我有以下 MNWE:
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{process} = [rectangle, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node (start) [process] {1};
\node (node2r) [process, below right=of start] {2r};
\node (node3r) [process, below=of node2r] {3r};
\node (node4r) [process, below=of node3r] {4r};
\node (node2l) [process, below left=of start] {2l};
\node (node4l) [process, below=of node2l, left=of node4r] {4l};
\node (end) [process, below left=of node4r] {4};
\draw [arrow] (start) -| (node2r);
\draw [arrow] (start) -| (node2l);
\draw [arrow] (node2l) -- (node4l);
\draw [arrow] (node2r) -- (node3r);
\draw [arrow] (node3r) -- (node4r);
\draw [arrow] (node4r) |- (end);
\draw [arrow] (node4l) |- (end);
\end{tikzpicture}
\end{document}
这将生成以下输出。
我如何调整代码以便与(水平)和(垂直)4l
对齐?2l
4r
附加问题:我如何确保垂直1
对齐5
?(如果矩形的宽度不同就会发生)
答案1
例如,您可以使用语法at (coordinate|-coordinate)
。顺便说一句,我改用了,\tikzset
因为\tikzstyle
已被弃用(即使它可能仍受支持)。
输出
代码
\documentclass[tikz, margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc, shapes.geometric, arrows}
\tikzset{
process/.style={rectangle, minimum height=1cm, text centered, draw=black, fill=orange!30},
arrow/.style={thick,->,>=stealth},
}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node (start) [process] {1};
\node (node2r) [process, below right=of start] {2r};
\node (node3r) [process, below=of node2r] {3r};
\node (node4r) [process, below=of node3r] {4r};
\node (node2l) [process, below left=of start] {2l};
\node (node4l) [process, ] at (node2l|-node4r) {4l};
\node (end) [process] at ($(node4l)!.5!(node4r)+(0,-2cm)$) {5moretext};
\draw [arrow] (start) -| (node2r);
\draw [arrow] (start) -| (node2l);
\draw [arrow] (node2l) -- (node4l);
\draw [arrow] (node2r) -- (node3r);
\draw [arrow] (node3r) -- (node4r);
\draw [arrow] (node4r) |- (end);
\draw [arrow] (node4l) |- (end);
\end{tikzpicture}
\end{document}