maybe this is a well-known problem, but I haven't been able to find a solution for it yet. The TikZ option inner sep=0pt at a node leads to a wrong bounding box (at least for characters or numbers as an argument). This means e.g. that nodes cannot be positioned correctly. In my minimal example I have tried to illustrate that. Here is the code

\documentclass[tikz, border=2pt]{standalone}
% If the bounding boxes were correct, the two ones would have to touch each other.
\node[fill=yellow, inner sep=0pt] (one) {1};
\node[fill=red, inner sep=0pt, anchor=west] at (one.east) {1}; 

The Output looks like this

enter image description here

As you can see, the bounding boxes for the two ones are too big at the left and the right part, but too small at the upper part. The lower part fits as I would expect it. What is the reason for the bounding boxes behaving like that? I have seen here https://stackoverflow.com/questions/47048850/what-is-the-difference-between-font-bounding-box-and-glyph-bounding-box that there is a difference between font bounding box and glyph bounding box. But in neither of the two definitions it would make sense for a bounding box to cut its own content as here in the example.

  • 2
    Because that's the bounding box of the character as defined in the font file. There's not much you can do on that side. You could try to use negative spacing to compensate that. – Phelype Oleinik Jun 19 at 11:56
  • Do you mean something like "inner xsep=-5pt"? Well for one character or number that would make sense, but actually I want to use the bouding box mechanism as described to position "\thechapter" in the heading of my document. As the margins on the left and right are different for different numbers (e.g. for 7 it is quite tight), I would have to change the negative spacing depending on the actual chapter number. – Nico Jun 19 at 12:07
  • Yes, you would need to do it in a per-number basis. Or use another font in which the actual glyphs match their bounding boxes. – Phelype Oleinik Jun 19 at 12:11
  • Can you tell me a font where that's the case? – Nico Jun 19 at 12:16
  • Off the top of my head I don't know any. I tried a few I can remember and it seems that none fits perfectly. CormorantGaramond, though, seems to have a consistent amount of space to the sides, so the amount of inner xsep would be the same for all numbers: \documentclass{article} \usepackage{CormorantGaramond} \begin{document} \fboxsep0pt \fboxrule1sp \makeatletter \count@=0 \loop \fbox{\the\count@} \advance\count@ by 1 \ifnum\count@<10 \repeat \end{document} – Phelype Oleinik Jun 19 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.