This question already has an answer here:

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





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

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?

marked as duplicate by Skillmon, TonioElGringo, Stefan Pinnow, Sebastiano, Steven B. Segletes Mar 2 '18 at 10:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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