TikZ 节点的内部分离和最小高度问题

TikZ 节点的内部分离和最小高度问题

考虑一下这个代码,它是这个答案

\documentclass[tikz,margin=3mm]{standalone}
\def\innersep{.3333em}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,text centered}]
\node[minimum height=6*\baselineskip+2*\innersep] (c1-r1) {Output index 1}; % The origin
\draw (c1-r1.south) node[below,minimum height=6*\baselineskip+2*\innersep] (c1-r2) {Output index 2};
%%%%%%%%%%%%%%%%%%%%%%%%
% TAKE NOTE OF THIS LINE
\draw (c1-r2.south) node[below,minimum height=18*\baselineskip+6*\innersep] (c1-r3) {Output index 3};
%%%%%%%%%%%%%%%%%%%%%%%%
\foreach \i in {1,2} {
    \draw (c1-r\i.north east) node[below right,minimum height=3*\baselineskip+\innersep] (c2-r\i-1) {Inner index \i.1};
    \draw (c1-r\i.south east) node[above right,minimum height=3*\baselineskip+\innersep] (c2-r\i-2) {Inner index \i.2};
}
\draw (c1-r3.north east) node[below right,minimum height=3*\baselineskip+\innersep] (c2-r3-1) {Inner index 3.1};
\foreach \i/\j in {2/1,3/2,4/3,5/4,6/5} {
    \draw (c2-r3-\j.south) node[below,minimum height=3*\baselineskip+\innersep] (c2-r3-\i) {Inner index 3.\i};
}
\end{tikzpicture}
\end{document}

部分输出:

在此处输入图片描述

可以看到node的高度{Output index 3}比实际的稍微小了一点,不过我们可以证明上面的代码是正确的:

考虑节点{Output index 1}{Output index 2}。它们的高度均为6*\baselineskip+2*\innersep。它们每个的高度都是节点的两倍{Inner index x.y}

现在,节点的{Output index 3}高度应该是节点的六倍,或者,相当于或{Inner index x.y}的三倍。{Output index 1}{Output index 2}

因此,节点的高度{Output index 3}

3 * (6*\baselineskip + 2*\innersep) = 18*\baselineskip + 6*\innersep

或者上述代码是正确的。

怎么了?


在链接的答案中,我使用了18*\baselineskip+6.6*\innersep,但我知道这只是一个近似值。我想要一个准确的数字!

提前致谢。

答案1

您忘记了这些线条。在本例中为 5*\pgflinewidth:

\documentclass[tikz,margin=3mm]{standalone}
\def\innersep{.3333em}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,text centered}]
\node[minimum height=6*\baselineskip+2*\innersep] (c1-r1) {Output index 1}; % The origin
\draw (c1-r1.south) node[below,minimum height=6*\baselineskip+2*\innersep] (c1-r2) {Output index 2};
%%%%%%%%%%%%%%%%%%%%%%%%
% TAKE NOTE OF THIS LINE
\draw (c1-r2.south) node[below,minimum height=18*\baselineskip+6*\innersep+5*\pgflinewidth] (c1-r3) {Output index 3};
%%%%%%%%%%%%%%%%%%%%%%%%
\foreach \i in {1,2} {
    \draw (c1-r\i.north east) node[below right,minimum height=3*\baselineskip+\innersep] (c2-r\i-1) {Inner index \i.1};
    \draw (c1-r\i.south east) node[above right,minimum height=3*\baselineskip+\innersep] (c2-r\i-2) {Inner index \i.2};
}
\draw (c1-r3.north east) node[below right,minimum height=3*\baselineskip+\innersep] (c2-r3-1) {Inner index 3.1};
\foreach \i/\j in {2/1,3/2,4/3,5/4,6/5} {
    \draw (c2-r3-\j.south) node[draw=red,below,minimum height=3*\baselineskip+\innersep] (c2-r3-\i) {Inner index 3.\i};
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容