![使用 tikz shapes.geometric 时,如何紧密贴合节点?](https://linux22.com/image/288005/%E4%BD%BF%E7%94%A8%20tikz%20shapes.geometric%20%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E7%B4%A7%E5%AF%86%E8%B4%B4%E5%90%88%E8%8A%82%E7%82%B9%EF%BC%9F.png)
我希望下面的两个节点大小大致相同,但其中一个比另一个大得多。有没有办法强制 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}