【问题标题】:LaTex/TikZ - Box alignmentLaTex/TikZ - 框对齐
【发布时间】:2018-01-27 23:53:41
【问题描述】:

我创建了以下 LaTeX/TikZ 脚本来绘制图形:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows, chains}
\usetikzlibrary{positioning,shapes.multipart}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \node[draw, fill=yellow!96!black, rectangle, 
      align=center, inner sep=3ex, font=\sffamily, label=below: Label1] (Box1) {
      \begin{tikzpicture}
        \node[draw, shape=rectangle split, rectangle split parts=2,
          inner sep=1ex, rounded corners=0pt,
          fill=white, font=\vphantom{Q}\sffamily] (Innerbox) {One \nodepart{two} Two};
    \end{tikzpicture}};
    \node[draw, inner sep=1ex, right=of Box1, label=below: Label2] (Box2) {
    \begin{tikzpicture}
\end{tikzpicture}

{\begin{tikzpicture}
    \node[draw, fill=yellow!96!black, rectangle, 
      align=center, inner sep=3ex, font=\sffamily, label=below: Label3] (Box3) {Four};
\end{tikzpicture}}};

    \draw (Box1) -- (Box2) -- (Box3);
    \draw[dashed] (Innerbox.one east) -- (Box2);
    \draw[dashed] (Innerbox.two east) -- (Box2);

\end{tikzpicture}
\end{document}

我想解决以下问题:

  1. 如何让盒子对齐,而不是下面的标签总是在同一水平面上?

  2. 如何在 Box2 的右侧添加框“四”(不是在里面,而是作为像 Box1 一样的框),最好是从 Box2 到 Box3 的虚线?

    所需结构:

    [盒子1] -- [盒子2] -- [盒子3]

【问题讨论】:

  • 嗨!如果它解决了问题,请记住将下面的答案标记为已接受! :)

标签: alignment latex draw tikz


【解决方案1】:

我对这张图片的基本处理:

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}
% left box
\filldraw [fill=yellow, draw=black, ultra thick] (0,0) rectangle (8,-10);
\filldraw [fill=white, draw=black, ultra thick] (2,-2) rectangle (6,-5);
\filldraw [fill=white, draw=black, ultra thick] (2,-5) rectangle (6,-8);
\node at (4,-3.5) [font=\sffamily] {\Huge One};
\node at (4,-6.5) [font=\sffamily] {\Huge Two};
% right box
\filldraw [fill=white, draw=black, ultra thick] (12,0) rectangle (20,-10);
\filldraw [fill=yellow, draw=black, ultra thick] (13,-1) rectangle (19,-6);
\node at (16,-3.5) [font=\sffamily] {\Huge Four};
% labels
\node at (4,-11) {\Huge 1};
\node at (16,-11) {\Huge 2};
\node at (16,-7) {\Huge 3};
% lines
\draw [ultra thick] (8,-5) -- (12,-5);
\draw [loosely dashed, ultra thick] (6,-3.5) -- (12,-4);
\draw [loosely dashed, ultra thick] (6,-6.5) -- (12,-6);
\end{tikzpicture}

\end{document}

及其输出:

在这里,您可以根据需要使用坐标来对齐框。

这试图回答您问题的第 1 部分,而第 2 部分对我来说不是很清楚。无论如何,如果你喜欢这个代码,你可以开发它并编辑框Four,只需使用上面的\filldraw\draw\node

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 2021-11-21
    相关资源
    最近更新 更多