我正在尝试创建匹配类型问题的解决方案,这需要在框之间画线。我一直在尝试tikzpicture
这样做:
\tikzstyle{block} = [rectangle, draw, fill=blue!0,
text width=15em, text centered, rounded corners, minimum height=2em]
\tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}[node distance = 2cm, auto]
\node [block] (1) {1};
\node [block, below of=1, node distance=1cm] (2) {2};
\node [block, below of=2, node distance=1cm] (3) {3};
\node [block, below of=3, node distance=1cm] (4) {4};
\node [block, right of=1, node distance=11cm] (Four) {Four};
\node [block, right of=2, node distance=11cm] (Three) {Three};
\node [block, right of=3, node distance=11cm] (One) {One};
\node [block, right of=4, node distance=11cm] (Two) {Two};
\path [line] (1) -- (One);
\path [line] (2) -- (Two);
\path [line] (3) -- (Three);
\path [line] (4) -- (Four);
\end{tikzpicture}
然而,这会产生以下非常丑陋的结果:
我想制作类似这样的东西,其中箭头从框右边缘的中间开始并到达框左边缘的中间:
答案1
这是一种matrix
方法。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}
\tikzset{block/.style = {rectangle, draw, fill=blue!0,
text width=15em, text centered, rounded corners, minimum height=2em},
line/.style = {draw, -latex'}
}
\begin{document}
\begin{tikzpicture}
\matrix(m)[matrix of nodes,
row sep=1cm, column sep=2cm, nodes={block}, %% adjust row and column sep
]{
1 & Four\\
2 & Three \\
3 & One \\
4 & Two \\
};
\draw[line](m-1-1.east) -- (m-3-2.west);
\draw[line](m-2-1.east) -- (m-4-2.west);
\draw[line](m-3-1.east) -- (m-2-2.west);
\draw[line](m-4-1.east) -- (m-1-2.west);
\end{tikzpicture}
\end{document}