In a plot, I have several vertically distributed nodes containing numbers with different numbers of digits before and after the decimal separator, and a trailing percent sign.
I would like to align these nodes horizontally along the decimal separator, similar to what can be done using the S
column type in tables using the siunitx
package. However, I do not want to use a table for the alignment, since the nodes are unevenly spaced vertically.
How can I align these nodes properly? I thought about somehow adding space before the numbers depending on the number of digits, but couldn't think of an elegant way of doing that without lots of manual work.
Here's a MWE:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
What I have:
\begin{tikzpicture}
\begin{axis}[
ymode=log,
height=4cm, width=8cm,
domain=1:10,
axis lines=left,
clip=false
]
\pgfplotsinvokeforeach{0.01, 0.1, 1, 10, 100}{
\addplot [black] {#1*x} node [anchor=west] {#1\,\%};
}
\end{axis}
\end{tikzpicture}
What I want:
\begin{tikzpicture}
\begin{axis}[
ymode=log,
domain=1:10,
height=4cm, width=8cm,
axis lines=left,
clip=false
]
\addplot [black] {x*0.01} node [anchor=west] {\hphantom{10}0.01\,\%};
\addplot [black] {x*0.1} node [anchor=west] {\hphantom{10}0.1\,\%};
\addplot [black] {x*1} node [anchor=west] {\hphantom{00}1\,\%};
\addplot [black] {x*10} node [anchor=west] {\hphantom{0}10\,\%};
\addplot [black] {x*100} node [anchor=west] {100\,\%};
\end{axis}
\end{tikzpicture}
\end{document}
siunitx
package provides a macro for table-like output of numbers:\tablenum[table-format=3.2]{#1}\,\%
However, this also aligns the%
sign.