Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like the two nodes below to be roughly the same size, but one is much larger than the other. Is there a way to force tikz to reconsider its bounding box calculation?

\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}

enter image description here

share|improve this question
    
Measure the width of the plus subscript with \settowidth and add an empty box before and an empty box after the text in the right node. Each empty box should have a width that is half the size of the plus subscript. (I'm assuming you want the text centred:-) –  Marc van Dongen Apr 9 at 10:17
    
Choose a larger value as minimum size... –  Paul Gaborit Apr 9 at 10:22
    
@MarcvanDongen Thank you. Is there no way to make the left node smaller? –  Neil G Apr 9 at 10:25
    
It would look ugly IMO. changing inner sep as suggested by @PaulGaborit and suggested below is probably easier than the suggestion I suggested but you should be careful when the type size changes. –  Marc van Dongen Apr 9 at 11:26

3 Answers 3

up vote 7 down vote accepted

I enclose an example where text in the left hexagon is not affecting the width of node. The width can be set by other means.

%! *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}

mwe

share|improve this answer

For this shape at least, the inner sep can be negative without serious consequences (although I guess this is an unintended feature).

\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}

enter image description here

share|improve this answer

Another possibility would be to fix shape size with \phantom{$\gpi$} and add real text with label=center:$\gpep$ option.

\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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.