2

I am drawing over a figure, and I am surprised that the following does not look centered, visually:

\documentclass{article}
\usepackage{mwe}
\usepackage{tikz}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
    \draw (0, 0)
    node (image) { \includegraphics[width=1cm]{example-image} };
\draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5)
node (text) { \SI{100}{\micro\meter} };

\end{tikzpicture} \end{document}

Notice how the red text extends over the right edge of the image, while it does not on the left:

enter image description here

Replacing \SI{100}{\micro\meter} by --------- seems to indicate that the TikZ code is correct: enter image description here

Am I being too picky here, or is the alignment off with the siunitx content?

bers
  • 5,404
  • 1
    If you add draw=black,,inner sep=0pt to your text node options, You will see that all characters do not participate to the bounding box in the same fashion. Btw you obtain the same result with \node[text=red] (text) { \SI{100}{\micro\meter} }; – BambOo Nov 04 '20 at 18:50
  • 1
    In addition to my previous comment, what I meant by You will see that all characters do not participate to the bounding box in the same fashion was that though all number share the same bounding box width, the do not have the same character width. Hence the differences in appearance observed by Simon Dispa with 100 vs 500 or yourself with the ----. Compile \begin{tikzpicture} \foreach \number in {1,...,9}{\draw[common] (0.5, 0.5) node[inner sep=0pt,draw=black,xshift=\number*1.75 ex,rotate=90] (text) {\number};} with tikz loaded to see some illustration of this. \end{tikzpicture} – BambOo Nov 05 '20 at 22:58
  • 1
    The 1 character is particularly different from the other numbers – BambOo Nov 05 '20 at 22:58

1 Answers1

1

It seems to be an optical effect between the 1 and 10 point font size. Exchanging 100 for 500 everything seems normal (to the eye). The same by enlarging or decreasing the size of the font. I do not know if siunitx is modifying the space between the numbers and the units. Typesetting \SI{500}{} or \SI{500}{} the middle 0 appears perfectly centered. Compare also the result when omitting SI using {100 \textmu m}.

\documentclass{article}

\usepackage{mwe} \usepackage{tikz} \usepackage{siunitx}

\begin{document}

default size font

\begin{tikzpicture} \draw (0, 0) node (image) { \includegraphics[width=1cm]{example-image} };

\draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5)
node (text) {\SI{100}{\micro\meter}};

\end{tikzpicture}

\begin{tikzpicture} \draw (0, 0) node (image) { \includegraphics[width=1cm]{example-image} };

\draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5)
node (text) {\SI{500}{\micro\meter}};

\end{tikzpicture}

without SI

\begin{tikzpicture}

\draw (0, 0) node (image) { \includegraphics[width=1cm]{example-image} };

\draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5) node (text) {100 \textmu m }; \end{tikzpicture}

\begin{tikzpicture} \draw (0, 0) node (image) { \includegraphics[width=1cm]{example-image} };

\draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5) node (text) {500 \textmu m}; \end{tikzpicture}

{\large% larger font

\begin{tikzpicture} \draw (0, 0) node (image) { \includegraphics[width=1cm]{example-image} };

\draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5)
node (text) { \SI{100}{\micro\meter} };

\end{tikzpicture} }

{\small% smaller font

\begin{tikzpicture} \draw (0, 0) node (image) { \includegraphics[width=1cm]{example-image} };

\draw[red, x={(image.south east)}, y={(image.north west)}] (0.5, 0.5)
node (text) { \SI{100}{\micro\meter} };

\end{tikzpicture} }

\end{document}

output

UPDATE

In fact, the number 1 is very different from the others (and from the letter l!) In terms of sideberarings. This is the output using the program provided by Philipp Gesang.

Accessing side-bearings in LuaTeX

outSB

The bounding boxes of the numbers are similar between them. This is the output of Yiannis Lazarides answer to

Bounding box for each letter

outBB

So the number 1 really extends to the left of the image! It is just a coincidence that at 10pt the left border of the image it is right on the ink.

Simon Dispa
  • 39,141
  • I don't agree with the first part of your answer: this does not seem to depend on font size or the use of siunitx for me. Both with smaller and larger font sizes, the text is still non-centered visually (even though, of course, the specific characteristic of the txt extending over the right edge, but not the left edge, is gone - but the distances to the edge are still different). – bers Nov 07 '20 at 06:07
  • I do agree that the 1 is special, probably to enforce, as you note, identical bounding box widths between the numbers - most certainly to enforce alignment of numerical material in tables etc. – bers Nov 07 '20 at 06:08
  • I do wonder what to do about this. I could print a scale bar of length 99.99 µm, but I'm not sure this is what I want ;) – bers Nov 07 '20 at 06:09
  • 1
    @bers You have three options to make the output more visually pleasing fpr this particular case of font family and font size.

    {\small \SI{100}{\micro\meter} or

    {100 \textmu m } or

    {\kern-1.2pt \SI{100}

    The latter will allow you to manually adjust the label to your liking.

    – Simon Dispa Nov 07 '20 at 13:15
  • 1
    @bers For both fitting in and centering I suggest

    {\kern-1.15pt 100 \kern-1.35pt\textmu m }

    – Simon Dispa Nov 07 '20 at 13:46