我正在创建一个具有不同multirow
高度的表格。我希望箭头延伸到文本上方/下方以显示适用范围multirow
。下面是一个简单的示例,其中所需的箭头为红色。
对于三行(参见黑色箭头),可能有一个比较 hack 的解决方案,但如果有一种方法可以自动创建箭头,而不管行数是多少,那就太理想了。
MWE 中的表格很简单,可以用 完全绘制tikz
,但预期的应用使完整tikz
实现变得不切实际。
平均能量损失
\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{table}[t]
\centering
\begin{tabular}{llll}
\toprule
1 & \multirow{2}{*}{A} & \multirow{4}{*}{+} & $\uparrow$ \\\cline{1-1}
2 & & & Z \\\cline{1-2}
3 & \multirow{2}{*}{B} & & $\downarrow$ \\\cline{1-1}\cline{4-4}
4 & & & $\uparrow$ \\\cline{1-3}
5 & \multirow{2}{*}{C} & \multirow{2}{*}{+} & Z \\\cline{1-1}
6 & & & $\downarrow$ \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
为什么 TikZ 解决方案不切实际?
这是一个使用 TikZ 矩阵的解决方案,可以轻松扩展为任意数量的行。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{table}\centering
\begin{tikzpicture}
\matrix[matrix of nodes, nodes in empty cells, nodes={text height=3ex, text depth=1ex, text width=2em, text centered}] (mymatr)
{
1&&&\\
2&&&\\
3&&&\\
4&&&\\
5&&&\\
6&&&\\
};
% Horizontal lines
\draw[thick] (mymatr-1-1.north west) -- (mymatr-1-4.north east);
\foreach \ind in {1,3,5}
{\draw[thick] (mymatr-\ind-1.south west) -- (mymatr-\ind-1.south east);}
\draw[thick] (mymatr-2-1.south west) -- (mymatr-2-2.south east);
\draw[thick] (mymatr-3-4.south west) -- (mymatr-3-4.south east);
\draw[thick] (mymatr-4-1.south west) -- (mymatr-4-3.south east);
\draw[thick] (mymatr-6-1.south west) -- (mymatr-6-4.south east);
% Vertical lines
\draw[red, {Latex}-{Latex}] (mymatr-1-2.north) -- node[fill=white, text=black]{A} (mymatr-2-2.south);
\draw[red, {Latex}-{Latex}] (mymatr-3-2.north) -- node[fill=white, text=black]{B} (mymatr-4-2.south);
\draw[red, {Latex}-{Latex}] (mymatr-5-2.north) -- node[fill=white, text=black]{C} (mymatr-6-2.south);
\draw[red, {Latex}-{Latex}] (mymatr-1-3.north) -- node[fill=white, text=black]{+} (mymatr-4-3.south);
\draw[red, {Latex}-{Latex}] (mymatr-5-3.north) -- node[fill=white, text=black]{+} (mymatr-6-3.south);
\draw[{Latex}-{Latex}] (mymatr-1-4.north) -- node[fill=white, text=black]{Z} (mymatr-3-4.south);
\draw[{Latex}-{Latex}] (mymatr-4-4.north) -- node[fill=white, text=black]{Z} (mymatr-6-4.south);
\end{tikzpicture}
\end{table}
\end{document}