[Tex/LaTex] How to align text across two nodes in a Tikzpicture

tikz-pgf

Consider the following code:

\begin{tikzpicture}
\node[align=left,font={\small\bfseries}] at (-30 pt, 30pt) {99.99\%        $500 \mu s$};
\node[align=left,font={\small\bfseries}] at (-30 pt, 10pt) {Median Latency $5 \mu s$};
\end{tikzpicture}

How can I make the 500 us align with the 5 us in the rendered image?

More specifically, I want it to align almost exactly like I have it in the plain text in the code above, with the left edge of 99 aligning with the left edge of Median, as well as having the numbers line up.

I tried using & as I would when trying to align two equations, but it just causes an error.

Best Answer

First solution

Using your code sample, you can use right or anchor=west to align both nodes to the left together with a makebox to make sure ensure the left part of the text takes the same space in both nodes and are vertically aligned (see @egreg comment below):

\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \node[font={\small\bfseries},left] at (-30 pt, 30pt) {\parbox{3cm}{99.99\%}$500 \mu s$};
  \node[font={\small\bfseries},left] at (-30 pt, 10pt) {\parbox{3cm}{Median Latency}$5 \mu s$};
\end{tikzpicture}
\end{document}

Output

Second solution

Or you could use another node for the right part of the text (but both texts are not vertically aligned):

\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \draw (-30 pt, 30pt) node[font={\small\bfseries},left] {99.99\%} ++(3,0) node[left] {$500 \mu s$};
  \draw (-30 pt, 10pt) node[font={\small\bfseries},left] {Median Latency} ++(3,0) node[left] {$5 \mu s$};
\end{tikzpicture}
\end{document}

Second solution output

Related Question