如何用 Tikz 给别人画块?
How to draw a block on others with Tikz?
这是我尝试使用 tikz 制作的图表。块 A、B 和 C 在一个块内(这里是红色背景的块),块 E 和 F 在另一个块内。两个巨大的块(红色背景)顶部有标签(LabA 和 LabB)。此外,我希望方块 E 位于方块 A 和 B 的中间。并且指向方块 E 的箭头应该有一定的弯曲角度;所以,不像我试过的那样。
这是我的代码。
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=black, thick, text width=2cm, minimum height=1cm, align=center]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\node[block] (a) {a};
\node[block, below=of a, yshift=0.7cm] (b) {b};
\node[block, below=of b, yshift=0.7cm] (c) {c};
\node[block, right=of c, xshift=0.7cm] (d) {d};
\node[block, right=of a, xshift=0.7cm, yshift=-0.4cm] (e) {e};
\draw [arrow] (a) -- (e);
\draw [arrow] (b) -- (e);
\draw [arrow] (c) -- (d);
\end{tikzpicture}
\end{document}
如何在一些节点上添加一个矩形并在其上写一个标签。
如何使此处的箭头具有一定的倾斜角度(不是直线),以及如何使 E 块位于 A 块和 B 块的中间和右侧。我虽然可以用 \draw [arrow] (a) -|- (e);
得到箭头,但它不起作用。
提前谢谢你
我试了一下,希望能满足要求:
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=none, thick, text width=.4cm, minimum height=.5cm, align=center, fill=blue!50]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\Large
%red rectangles
\node (r1) [draw=none, fill=red, minimum width=1.2cm,minimum height=3.5cm]{};
\node (r2) [right=2cm of r1.center, anchor=center, draw=none, fill=red, minimum width=1.2cm,minimum height=3.5cm]{};
\node (r1Label)[above=0cm of r1] {\textbf{LabA}};
\node (r2Label)[above=0cm of r2]{\textbf{LabB}};
%nodes
\node[block, below=3mm of r1.north, anchor=north] (a) {\color{white}A};
\node[block, below=4mm of a] (b) {\color{white}B};
\node[block, below=4mm of b] (c) {\color{white}C};
\node[block, right=2cm of c.center, anchor=center] (d) {\color{white}D};
\node at ($(a.south)+(2,-.2)$) [block] (e) {\color{white}E};
%arrows
\draw [arrow, rounded corners=2] (a) -- ($(a)+(1,0)$) |- ($(e.west)+(0,.1)$);
\draw [arrow, rounded corners=2] (b) -- ($(b)+(1,0)$) |- ($(e.west)+(0,-.1)$);
\draw [arrow] (c) -- (d);
\end{tikzpicture}
\end{document}
结果如下:
一些解释:
- 您可以通过在其他节点之前定义它们来在后面绘制矩形。使用层有更复杂的方法,但我认为在这个例子中它就足够了。
- 我主要使用给定示例代码中的绝对距离。您可能需要调整...但是,使用这些您可以轻松找到 A 和 B 之间的中间(距离 4mm)以找到 E 的 y 位置(a.south+ 2mm)。使用 ($(node1)+(node2)$) 您可以计算节点位置。
- 您提到的
-|-
选项分两步工作。首先绘制 --
到某个锚点(否则这是不明确的),然后 |-
到目标节点。
- 绘图的圆角选项以圆角半径作为参数。
这是我尝试使用 tikz 制作的图表。块 A、B 和 C 在一个块内(这里是红色背景的块),块 E 和 F 在另一个块内。两个巨大的块(红色背景)顶部有标签(LabA 和 LabB)。此外,我希望方块 E 位于方块 A 和 B 的中间。并且指向方块 E 的箭头应该有一定的弯曲角度;所以,不像我试过的那样。
这是我的代码。
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=black, thick, text width=2cm, minimum height=1cm, align=center]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\node[block] (a) {a};
\node[block, below=of a, yshift=0.7cm] (b) {b};
\node[block, below=of b, yshift=0.7cm] (c) {c};
\node[block, right=of c, xshift=0.7cm] (d) {d};
\node[block, right=of a, xshift=0.7cm, yshift=-0.4cm] (e) {e};
\draw [arrow] (a) -- (e);
\draw [arrow] (b) -- (e);
\draw [arrow] (c) -- (d);
\end{tikzpicture}
\end{document}
如何在一些节点上添加一个矩形并在其上写一个标签。
如何使此处的箭头具有一定的倾斜角度(不是直线),以及如何使 E 块位于 A 块和 B 块的中间和右侧。我虽然可以用 \draw [arrow] (a) -|- (e);
得到箭头,但它不起作用。
提前谢谢你
我试了一下,希望能满足要求:
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=none, thick, text width=.4cm, minimum height=.5cm, align=center, fill=blue!50]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}
\Large
%red rectangles
\node (r1) [draw=none, fill=red, minimum width=1.2cm,minimum height=3.5cm]{};
\node (r2) [right=2cm of r1.center, anchor=center, draw=none, fill=red, minimum width=1.2cm,minimum height=3.5cm]{};
\node (r1Label)[above=0cm of r1] {\textbf{LabA}};
\node (r2Label)[above=0cm of r2]{\textbf{LabB}};
%nodes
\node[block, below=3mm of r1.north, anchor=north] (a) {\color{white}A};
\node[block, below=4mm of a] (b) {\color{white}B};
\node[block, below=4mm of b] (c) {\color{white}C};
\node[block, right=2cm of c.center, anchor=center] (d) {\color{white}D};
\node at ($(a.south)+(2,-.2)$) [block] (e) {\color{white}E};
%arrows
\draw [arrow, rounded corners=2] (a) -- ($(a)+(1,0)$) |- ($(e.west)+(0,.1)$);
\draw [arrow, rounded corners=2] (b) -- ($(b)+(1,0)$) |- ($(e.west)+(0,-.1)$);
\draw [arrow] (c) -- (d);
\end{tikzpicture}
\end{document}
结果如下:
一些解释:
- 您可以通过在其他节点之前定义它们来在后面绘制矩形。使用层有更复杂的方法,但我认为在这个例子中它就足够了。
- 我主要使用给定示例代码中的绝对距离。您可能需要调整...但是,使用这些您可以轻松找到 A 和 B 之间的中间(距离 4mm)以找到 E 的 y 位置(a.south+ 2mm)。使用 ($(node1)+(node2)$) 您可以计算节点位置。
- 您提到的
-|-
选项分两步工作。首先绘制--
到某个锚点(否则这是不明确的),然后|-
到目标节点。 - 绘图的圆角选项以圆角半径作为参数。