# Vertically align multiple labels

I have a sketch with two aligned lines. These lines have a label each. When you look on my example, you will see, that the labels "Top" and "Inlet" do not share the same baseline. Both labels are placed individually.

How can I define a baseline for both of them?

\begin{tikzpicture}[scale=20]
% Specify the coordinates
\coordinate (P1) at (-0.125,0.15);
\coordinate (P2) at (-0.0635, 0.15);
\coordinate (P3) at (-0.0605, 0.15);
\coordinate (P4) at (0.0, 0.15);

\coordinate (P5) at (-0.125,0);
\coordinate (P6) at (-0.0635,0);
\coordinate (P7) at (-0.0605,0);
\coordinate (P8) at (0.0,0);

\coordinate (P9) at (-0.102588, -0.03);
\coordinate (P10) at (-0.0605, -0.03);
\coordinate (P11) at (0.0, -0.03);

\draw[line width=0.5pt] (P1) -- (P2) -- (P6) -- (P10) -- (P7) -- (P3) -- (P4);
\draw[line width=0.5pt] (P1) -- (P5) -- (P9);
\draw[line width=0.5pt] (P4) -- (P11);
\draw[line width=0.5pt] (P1) -- (P2)  node [midway, above] {Inlet};
\draw[line width=0.5pt] (P3) -- (P4)  node [midway, above] {Top};

\end{tikzpicture}


-
{\strut Inlet} and {\strut Top}? –  egreg Jan 11 '13 at 15:25
This works, thank you. –  Dohn Joe Jan 11 '13 at 15:33

If you want an "automatic" solution that doesn't depend on the labels, then

\draw[line width=0.5pt] (P1) -- (P2)  node [midway, above] {\strut Inlet};
\draw[line width=0.5pt] (P3) -- (P4)  node [midway, above] {\strut Top};


can do.

-
An even more automatic solution would be to issue every node/.style={font=\strut} (globally, to the tikzpicture or to another scope) –  Qrrbrbirlbel Jan 11 '13 at 16:07

They are not aligned due to the depth of p in Top. You can use vphantom{p} to align them:

\draw[line width=0.5pt] (P1) -- (P2)  node [midway, above] {Inlet\vphantom{p}};


-
The “opposite” solution would be to add text depth=0ex to the Top node. –  Qrrbrbirlbel Jan 11 '13 at 15:29
Does the code "\vphantom{p}" make TikZ align the text "Inlet" in a way, as if the text contained a letter 'p'? And therefore, adjust the spacing between text and line? –  Dohn Joe Jan 11 '13 at 15:35
@DohnJoe: It adds a depth of p but no width. –  Harish Kumar Jan 11 '13 at 15:38
@Qrrbrbirlbel That is a valid (and reasonable) solution, consider posting it as an answer! –  yo' Jan 11 '13 at 16:03

(This answer aims at a alignment that uses the original placement of “Inlet” without adding further (vertical) padding to the nodes.)

There is a special anchor .base that would place the at part of the node at the baseline of the text. But this does not help here, as we want to place the node above (equivalent to anchor=south) of the lines. With anchor=base we would get

Though, anchor=south can be mimiced by up-shifting the base-line aligned nodes by the amount of inner ysep; key: base above:

A very similar solution can be obtained, by setting the text depth to zero (and thus ignoring the depth of p); key: Base above:

The actual difference can be seen by drawing the rectangular shape of the node:

If the missing depth of p is too tight for you, you can use (as already proposed in the other answers) \vphantom or \strut (which is just a very big \vphantom). But I would rather use a key for this and would not manual insert those macros in the node. We can use the font key for that:

• ssstrut, Ag:

• sstrut, ():

• strut, \strut:

## Code

\documentclass[tikz]{standalone}
\tikzset{
%   nodes={draw,draw opacity=.5},% debug
base above/.style={%                                     shape does not loose its original measurements
anchor=base, yshift=\pgfkeysvalueof{/pgf/inner ysep}},
Base above/.style={%                                     “smashing” the bottom part
above, text depth=0ex},
ssstrut/.style={%                                        very small strut
font=\vphantom{Ag}},
sstrut/.style={%                                         small strut
font=\vphantom{()}},
strut/.style={%                                          big strut
font=\strut}}
\newcommand*{\coordinates}{\coordinate (P1) at (-0.125,0.15) coordinate (P2) at (-0.0635,0.15)
coordinate (P3) at (-0.0605,0.15) coordinate (P4) at (0.0,0.15);}
\begin{document}
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, base above] {Inlet};
\draw (P3) -- (P4) node [midway, base above] {Top};
\end{tikzpicture}
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, Base above] {Inlet};
\draw (P3) -- (P4) node [midway, Base above] {Top};
\end{tikzpicture}
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, above, ssstrut] {Inlet};
\draw (P3) -- (P4) node [midway, above, ssstrut] {Top};
\end{tikzpicture}
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, above, sstrut] {Inlet};
\draw (P3) -- (P4) node [midway, above, sstrut] {Top};
\end{tikzpicture}
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, above, strut] {Inlet};
\draw (P3) -- (P4) node [midway, above, strut] {Top};
\end{tikzpicture}
\end{document}

-