删除标签和节点之间的重复行

删除标签和节点之间的重复行

我想删除节点和节点标签之间的重复行,如下所示:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,fit,backgrounds}
\begin{document}
\begin{tikzpicture}[font=\footnotesize,node distance=0 and 0]

  \tikzset{
    box/.style={draw,minimum width=5em,text width=5em,minimum height=1.6em,inner sep=1pt},
  }
  \def\nodes{
AAA,
BBBB,
CCCCC,
DDDDDD
}
\begin{scope}[start chain=C1 going below]
\foreach \f/\t/\n/\s [count=\i] in \nodes {
  \node[box,on chain=C1] {\small \n};
  }
\end{scope}
\begin{pgfonlayer}{background}
    \node[fit=(C1-1)(C1-4),draw,inner sep=2pt,label={[anchor=south west,draw]north west:package}]{};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

下面的线package画了两遍,感觉比较粗一些。

输出:

在此处输入图片描述

答案1

您可以通过添加 将标签垂直移动线宽yshift=-\pgflinewidth。您还可以将node distance链中的 更改为-\pgflinewidth

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,fit,backgrounds}
\begin{document}
\begin{tikzpicture}[font=\footnotesize,node distance=0 and 0]

  \tikzset{
    box/.style={draw,minimum width=5em,text width=5em,minimum height=1.6em,inner sep=1pt},
  }
  \def\nodes{
AAA,
BBBB,
CCCCC,
DDDDDD
}
\begin{scope}[start chain=C1 going below, node distance=-\pgflinewidth]
\foreach \f/\t/\n/\s [count=\i] in \nodes {
  \node[box,on chain=C1] {\small \n};
  }
\end{scope}
\begin{pgfonlayer}{background}
    \node[fit=(C1-1)(C1-4),draw,inner sep=2pt,label={[anchor=south west,draw,yshift=-\pgflinewidth]north west:package}]{};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

相关内容