我正在尝试连接这些单元格,左侧的单元格完全符合我的要求,但右侧的单元格看起来很奇怪...我希望右侧的单元格与大单元格连接,方向与左侧的单元格相反......有人可以帮忙吗??
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{array,mathtools}
\usetikzlibrary{matrix, positioning,backgrounds}
\begin{document}
\begin{tikzpicture}
\matrix (m2) [matrix of nodes,
nodes={draw, minimum height=10mm, minimum width=8mm,
anchor=south},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth,
nodes in empty cells,]
{
$10$ & $5$ \\
};
\matrix[below left of=m2, xshift=-0.3cm, yshift=-0.8cm] (m3) [matrix of nodes,
nodes={draw, minimum height=10mm, minimum width=8mm,
anchor=south},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth,
nodes in empty cells,]
{
$10$ \\
};
\node[above of=m3,yshift=-2mm] (p2) {};
\draw (m2-1-1) |- (p2) -| (m3-1-1);
\matrix[below right of=m2, xshift=0.3cm, yshift=-0.8cm] (m4) [matrix of nodes,
nodes={draw, minimum height=10mm, minimum width=8mm,
anchor=south},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth,
nodes in empty cells,]
{
$5$ \\
};
\node[above of=m4,yshift=-2mm] (p3) {};
\node[above of=m4] (p4) {};
\draw (m2-1-2) |- (p3) -| (m4-1-1);
\end{tikzpicture}
\end{document}
答案1
由于您创建了节点,它们具有尺寸和 Ti钾默认情况下,Z 与边界相连。在这种情况下,您真正想要的是坐标而不是节点。而且您p4
根本不使用。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning,backgrounds}
\begin{document}
\begin{tikzpicture}
[my matrix/.style={matrix of nodes, nodes={draw, minimum height=10mm, minimum width=8mm, anchor=south}, column sep=-\pgflinewidth, row sep=-\pgflinewidth, nodes in empty cells}]
\matrix (m2) [my matrix]
{
$10$ & $5$ \\
};
\matrix[below left of=m2, xshift=-0.3cm, yshift=-0.8cm] (m3) [my matrix]
{
$10$ \\
};
\coordinate [above of=m3,yshift=-2mm] (p2);
\draw (m2-1-1) |- (p2) -| (m3-1-1);
\matrix[below right of=m2, xshift=0.3cm, yshift=-0.8cm] (m4) [my matrix]
{
$5$ \\
};
\coordinate [above of=m4,yshift=-2mm] (p3);
\draw (m2-1-2) |- (p3) -| (m4-1-1);
\end{tikzpicture}
\end{document}
请注意,该above of
语法已弃用。您正在加载positioning
,但不要使用其语法。above=<dim> of <wherever>
或above=of <wherever>
现在是推荐的语法。