0

I'm trying to right-align pieces of text in separate TikZ nodes. One piece of text is alphabetical and the other is numerical. The numerical text is much larger than the alphabetical text, and I'm finding there is extraneous space to the right of it. As a result, the right alignment is not accurate enough.

Here is a MWE:

% !TEX program = xelatex

\documentclass{book}

\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{positioning}
\usepackage{fontspec}
\setmainfont{Cambria}

\newcommand\hugefont{
    \fontsize{200}{220}\selectfont%
}

\newcommand\smallfont{
    \fontsize{20}{22}\selectfont%
}

\begin{document}
    \begin{tikzpicture}[remember picture,overlay]%
        \node(small) [anchor=north east,fill=green,inner sep=0pt]             at (current page text area.north east) {\smallfont abc};%
        \node(big)   [anchor=north east,fill=red,inner sep=0pt,yshift=-10pt]  at (small.south east)                  {\hugefont 123};%
        \node(big2)  [anchor=north east,fill=blue,inner sep=0pt,yshift=-10pt] at (big.south east)                    {\hugefont abc};%
    \end{tikzpicture}
\end{document}

And here is the result:

enter image description here

As you can see, the "123" has a large gap to the right of the "3", so it doesn't align well. The large "abc" is better, though still imperfect.

I'm aware that my font choice of Cambria exacerbates the issue, but even without it the problem persists to a lesser extent.

Is there any way I can accurately right-align this text without resorting to manual xshift values?

Kent Boogaart
  • 664
  • 4
  • 15
  • 1
    This is possible only manually, as TeX doesn't know the contour of your glyphs, just the boxes around them. – Skillmon Mar 02 '18 at 09:56
  • note your \hugefont and \smallfont commands have % in the wrong place so they will add spurious white space you need {% – David Carlisle Mar 02 '18 at 10:23

0 Answers0