我正在尝试为文档创建说明表格的图表。(下面是我希望它看起来的样子的示例。)我应该使用什么工具来复制它?
答案1
使用 TikZ 的一种可能性:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning}
\begin{document}
\begin{tikzpicture}[my shape/.style={
rectangle split, rectangle split parts=#1,draw,
rectangle split empty part height= 1.5ex,align=center}]
% the rectangular nodes
\node[my shape=7] (rec1) {\phantom{10}};
\node[right = 15pt of rec1,my shape=2] (rec2) at (rec1.three split east) {16\nodepart{two}17};
\node[right = 15pt of rec1,my shape=2] (rec3) at (rec1.six split east) {12\nodepart{two}13};
\node[right = 4cm of rec1,my shape=7] (rec4) {\nodepart{two}17\nodepart{three}26\nodepart{four}16\nodepart{five}\nodepart{six}12\nodepart{seven}13};
\node[right = 15pt of rec3,my shape=1] (rec5) at (rec3.text east) {26};
% the numbers to the left of the rectangles
\foreach \part [count=\i from 0] in {text ,two ,three ,four ,five ,six ,seven }
{
\foreach \rect in {rec1,rec4}
\node[label=left:$\i$] at (\rect.\part west) {};
}
% the arrows
\draw[->] (rec1.three east) -- (rec2.text west);
\draw[->] (rec1.four east) -- (rec2.two west);
\draw[->] (rec1.six east) -- (rec3.text west);
\draw[->] (rec1.seven east) -- (rec3.two west);
\draw[->] (rec3.text east) -- (rec5.text west);
\end{tikzpicture}
\end{document}
答案2
没有 Tikz ...
\documentclass{article}
\begin{document}
\begin{minipage}{0.4\linewidth}
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{c|c| *2{@{}c@{}|c|} }
\cline{2-2}
0 & \phantom{0} & \multicolumn{4}{c}{} \\ \cline{2-2}
1 & & \multicolumn{4}{c}{} \\ \cline{2-2} \cline{4-4}
2 & & $\rightarrow$ & 16 \\ \cline{2-2} \cline{4-4}
3 & & $\rightarrow$ & 17 \\ \cline{2-2} \cline{4-4}
4 & & \multicolumn{4}{c}{} \\ \cline{2-2} \cline{4-4} \cline{6-6}
5 & & $\rightarrow$ & 12 & $\rightarrow$ & 26 \\ \cline{2-2} \cline{4-4} \cline{6-6}
6 & & $\rightarrow$ & 13 \\ \cline{2-2} \cline{4-4}
\end{tabular}
\end{minipage}%
\begin{minipage}{0.4\linewidth}
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{c|c|}
\cline{2-2}
0 & \\ \cline{2-2}
1 & 17 \\ \cline{2-2}
2 & 26 \\ \cline{2-2}
3 & 16 \\ \cline{2-2}
4 & \\ \cline{2-2}
5 & 12 \\ \cline{2-2}
6 & 13 \\ \cline{2-2}
\end{tabular}
\end{minipage}
\end{document}
这使,
我尝试简化第一个表格,但失败了 :(
\begingroup
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{c|c|@{$\rightarrow$}|c|@{$\rightarrow$}|c|}
\cline{2-2}
0 & \phantom{0} \\ \cline{2-2}
1 & \\ \cline{2-3}
2 & & 16 \\ \cline{2-3}
3 & & 17 \\ \cline{2-3}
4 & \\ \cline{2-4}
5 & & 12 & 26 \\ \cline{2-4}
6 & & 13 \\ \cline{2-3}
\end{tabular}
\endgroup
这就产生了,
我不知道是否有办法去掉horizontal rules
上方和下方的那些rightarrow
。我考虑过使用hhline
包,但这不是我想要的。如果有人知道如何做,我将非常感谢您的回复。