![有人能帮助我如何在乳胶中构建这样的表格吗?](https://linux22.com/image/338422/%E6%9C%89%E4%BA%BA%E8%83%BD%E5%B8%AE%E5%8A%A9%E6%88%91%E5%A6%82%E4%BD%95%E5%9C%A8%E4%B9%B3%E8%83%B6%E4%B8%AD%E6%9E%84%E5%BB%BA%E8%BF%99%E6%A0%B7%E7%9A%84%E8%A1%A8%E6%A0%BC%E5%90%97%EF%BC%9F.png)
我使用上面的代码在乳胶中重现了表格,但我不知道如何将线转换为箭头
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
$\begin{pgfpicture}{0.0cm}{0.0cm}{8.0cm}{8.0cm}
\pgfsetlinewidth{0.5pt}
% Row 1
\pgfnoderect{A1}[stroke]{\pgfxy(1,4)}{\pgfxy(2,2)}
\pgfputat{\pgfxy(0.5,4.5)}{\pgfbox[center,center]{$$}}
\pgfputat{\pgfxy(1.5,4.5)}{\pgfbox[center,center]{$6$}}
\pgfputat{\pgfxy(0.5,3.5)}{\pgfbox[center,center]{$$}}
\pgfputat{\pgfxy(1.5,3.5)}{\pgfbox[center,center]{$$}}
\pgfnoderect{A2}[stroke]{\pgfxy(3,4)}{\pgfxy(2,2)}
\pgfputat{\pgfxy(2.5,4.5)}{\pgfbox[center,center]{$$}}
\pgfputat{\pgfxy(3.5,4.5)}{\pgfbox[center,center]{$10$}}
\pgfputat{\pgfxy(2.5,3.5)}{\pgfbox[center,center]{$$}}
\pgfputat{\pgfxy(3.5,3.5)}{\pgfbox[center,center]{$$}}
\pgfnoderect{B1}[stroke]{\pgfxy(1.5,4.5)}{\pgfxy(1,1)}
\pgfnoderect{B2}[stroke]{\pgfxy(3.5,4.5)}{\pgfxy(1,1)}
% Row 2
\pgfnoderect{A3}[stroke]{\pgfxy(1,6)}{\pgfxy(2,2)}
\pgfputat{\pgfxy(0.5,6.5)}{\pgfbox[center,center]{$$}}
\pgfputat{\pgfxy(1.5,6.5)}{\pgfbox[center,center]{$5$}}
\pgfputat{\pgfxy(0.5,5.5)}{\pgfbox[center,center]{$$}}
\pgfputat{\pgfxy(1.5,5.5)}{\pgfbox[center,center]{$$}}
\pgfnoderect{A4}[stroke]{\pgfxy(3,6)}{\pgfxy(2,2)}
\pgfputat{\pgfxy(2.5,6.5)}{\pgfbox[center,center]{$$}}
\pgfputat{\pgfxy(3.5,6.5)}{\pgfbox[center,center]{$9$}}
\pgfputat{\pgfxy(2.5,5.5)}{\pgfbox[center,center]{$$}}
\pgfputat{\pgfxy(3.5,5.5)}{\pgfbox[center,center]{$$}}
\pgfnoderect{B3}[stroke]{\pgfxy(1.5,6.5)}{\pgfxy(1,1)}
\pgfnoderect{B4}[stroke]{\pgfxy(3.5,6.5)}{\pgfxy(1,1)}
%%%%%%%%%%%%%%%%%%%%%%%%
\pgfputat{\pgfxy(4.5,3.5)}{\pgfbox[center,center]{$32$}}
\pgfputat{\pgfxy(4.5,5.5)}{\pgfbox[center,center]{$28$}}
\pgfputat{\pgfxy(3.0,7.5)}{\pgfbox[center,center]{$v_{2}=2$}}
\pgfputat{\pgfxy(1.0,7.5)}{\pgfbox[center,center]{$v_{1}=4$}}
\pgfputat{\pgfxy(-1.0,3.5)}{\pgfbox[center,center]{$u_{2}=-2$}}
\pgfputat{\pgfxy(-1.0,5.5)}{\pgfbox[center,center]{$u_{1}=-3$}}
\pgfputat{\pgfxy(0.5,2.5)}{\pgfbox[center,center]{$48$}}
\pgfputat{\pgfxy(2.5,2.5)}{\pgfbox[center,center]{$29$}}
%%%%%%%%%%%%%%%%%%%%%%%%
\pgfsetendarrow{\pgfarrowsingle}
\pgfxycurve(4.75,4.25)(4.75,4.25)(3.75,3.5)(3.75,3.5)
\end{pgfpicture}$
\end{document}
答案1
正如图像很简单:
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[node distance = 0mm,
box/.style = {rectangle, draw, minimum size=#1, outer sep = 0pt}
]
\node (n11) [box=20mm,label=above:{$v_1=4$},label=left:{$u_1=-3$}] {};
\node (n12) [box=20mm,label=above:{$v_2=2$},label=right:28,right=of n11] {};
\node (n21) [box=20mm,label=left:{$u_2=-2$},label=below:48,below=of n11] {};
\node (n22) [box=20mm,label=right:32,label=below:29,right=of n21] {};
%
\node (n11a) [box=10mm,below left=of n11.north east] {5};
\node (n12a) [box=10mm,below left=of n12.north east] {9};
\node (n21a) [box=10mm,below left=of n21.north east] {6};
\node (n2a2) [box=10mm,below left=of n22.north east] {10};
\end{tikzpicture}
\end{document}
附录: 假设 32 号处的斜线必须是箭头:
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[node distance = 0mm,
box/.style = {rectangle, draw, minimum size=#1, outer sep = 0pt}
]
\node (n11) [box=20mm,
label=195:{$u_1=-3$},% on the left side
label=above:{$v_1=4$}] {};
\node (n12) [box=20mm,
label=above:{$v_2=2$},
label=-15:28,% on the right side
right=of n11] {};
\node (n21) [box=20mm,
label=195:{$u_2=-2$},% on the left side
label=below:48,
below=of n11] {};
\node (n22) [box=20mm,
label=-15:32,% on the right side
label=below:29,
right=of n21] {};
%
\node (n11a) [box=10mm,below left=of n11.north east] {5};
\node (n12a) [box=10mm,below left=of n12.north east] {9};
\node (n21a) [box=10mm,below left=of n21.north east] {6};
\node (n2a2) [box=10mm,below left=of n22.north east] {10};
% added arrows
\draw[->] ([xshift=-3mm,yshift=5mm] n22.south east) -- + (45:9mm);
\end{tikzpicture}
\end{document}
在上面的代码中,标签也被移动到了如图所示的位置。结果是:
答案2
作为数学环境中的数组,您可以使用它\multicolumn
来跨越多列。有一个包multirow
可以像 Zarko 的答案中那样用于在多行上居中,但问题图中没有指定它。
\documentclass{article}
\begin{document}
\begin{displaymath}
\begin{array}{r|p{1.3em}|p{1.3em}|p{1.3em}|p{1.3em}|l}
\multicolumn{1}{c}{} & \multicolumn{2}{c}{v_1=4} & \multicolumn{2}{c}{v_2=2}\\\cline{2-5}
& & 5 & & 9 & \\\cline{3-3}\cline{5-5}
u_1=-3 & \multicolumn{2}{c|}{} & \multicolumn{2}{c|}{} & 28 \\\cline{2-5}
& & 6 & & 10 & \\\cline{3-3}\cline{5-5}
u_2=-2 & \multicolumn{2}{c|}{} & \multicolumn{2}{c|}{} & 32 \\\cline{2-5}
\multicolumn{1}{c}{} & \multicolumn{2}{c}{48} & \multicolumn{2}{c}{29}
\end{array}
\end{displaymath}
\end{document}