使用 tikz shapes.geometric 时,如何紧密贴合节点?

使用 tikz shapes.geometric 时,如何紧密贴合节点?

我希望下面的两个节点大小大致相同,但其中一个比另一个大得多。有没有办法强制 tikz 重新考虑其边界框计算?

\documentclass[tikz]{standalone}
\usetikzlibrary{
  positioning,
  shapes.geometric
}
\begin{document}
\newcommand{\gpi}{\mathrm{GPi}}
\newcommand{\gpep}{\mathrm{GPe_{+}}}
\begin{tikzpicture}
    \node[draw, inner sep=0pt, minimum size=9mm, shape=regular polygon, regular polygon sides=6] (gpi)  {$\gpi$};
    \node[draw, inner sep=0pt, minimum size=9mm, shape=regular polygon, regular polygon sides=6] (gpep) [left=40mm of gpi] {$\gpep$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

我附上了一个示例,其中左六边形中的文本不会影响节点的宽度。可以通过其他方式设置宽度。

%! *latex mal-shapes.tex
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,shapes.geometric}
\begin{document}
\newcommand{\gpi}{\mathrm{GPi}}
\newcommand{\gpep}{\makebox[0pt][c]{$\mathrm{GPe_{+}}$}}
\begin{tikzpicture}
    \node[draw, inner sep=0pt, minimum size=10mm, shape=regular polygon, regular polygon sides=6] (gpi)  {$\gpi$};
    \node[draw, inner sep=0pt, minimum size=10mm, shape=regular polygon, regular polygon sides=6] (gpep) [left=5mm of gpi] {\gpep};
\end{tikzpicture}
\end{document}

姆韦

答案2

另一种可能性是固定形状大小\phantom{$\gpi$}并使用选项添加真实文本label=center:$\gpep$

\documentclass[tikz]{standalone}
\usetikzlibrary{
  positioning,
  shapes.geometric
}
\begin{document}
\newcommand{\gpi}{\mathrm{GPi}}
\newcommand{\gpep}{\mathrm{GPe_{+}}}

\begin{tikzpicture}
    \node[draw, inner sep=0pt, minimum size=9mm, 
          shape=regular polygon, regular polygon sides=6] (gpi) {$\gpi$};
    \node[draw, inner sep=0pt, minimum size=9mm, 
         shape=regular polygon, regular polygon sides=6, 
         label=center:$\gpep$] (gpep) [left=10mm of gpi] {\phantom{$\gpi$}};
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案3

至少对于这种形状,其inner sep可以是负面的而不会产生严重的后果(尽管我猜这是一个非预期的特征)。

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[every node/.style={regular polygon, regular polygon sides=6}]
\node [inner sep=-10mm, minimum size=10mm, draw] at (-1,0) {GPe$_+$};
\node [inner sep=-10mm, minimum size=10mm, draw] at ( 1,0) {GPi};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容