TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

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


Image generated by the code.

share|improve this question
{\strut Inlet} and {\strut Top}? – egreg Jan 11 '13 at 15:25
This works, thank you. – Dohn Joe Jan 11 '13 at 15:33
up vote 5 down vote accepted

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.

share|improve this answer
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}};

enter image description here

share|improve this answer
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
enter image description here

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

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

enter image description here

The actual difference can be seen by drawing the rectangular shape of the node: enter image description hereenter image description here

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:

    enter image description here

  • sstrut, ():

    enter image description here

  • strut, \strut:

    enter image description here


%   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
    sstrut/.style={%                                         small strut
    strut/.style={%                                          big 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{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, base above] {Inlet};
\draw (P3) -- (P4) node [midway, base above] {Top};
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, Base above] {Inlet};
\draw (P3) -- (P4) node [midway, Base above] {Top};
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, above, ssstrut] {Inlet};
\draw (P3) -- (P4) node [midway, above, ssstrut] {Top};
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, above, sstrut] {Inlet};
\draw (P3) -- (P4) node [midway, above, sstrut] {Top};
\begin{tikzpicture}[scale=20] \coordinates
\draw (P1) -- (P2) node [midway, above, strut] {Inlet};
\draw (P3) -- (P4) node [midway, above, strut] {Top};
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.