Question

Can I automatically reference the lowest baseline of a node in TikZ?

Situation

I would like to draw a line under the lowest baseline of the node in red (not just moonfact.south west -- moonfact.south east).

Example Code

\documentclass{article}
\usepackage{fontspec}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[remember picture,baseline,every node/.style={draw,red,inner sep=0pt,outer sep=0pt}]%
\node [align=left,text width=5em] (moonfact) {The moon is 384,400 kilometers away from earth.};
\end{tikzpicture}%
\begin{tikzpicture}[overlay,remember picture,baseline]%
\draw ([yshift=-1ex]moonfact.base west) -- ([yshift=-1ex]moonfact.base east);
\end{tikzpicture}%

\end{document}


Output as standalone with a border of 10px

Compare the two examples both with anchor=north and using south west and south east instead of base west and base east. The g affects the line distance. It would be nice to avoid this with the use of a "last-line baseline":

• You want to draw the line under earth then? I think a three-part node would be much more efficient – percusse Feb 9 '15 at 10:08
• In your last two cases listed, add ing a \strut to the end of the input will cause the two black lines to align. – Steven B. Segletes Feb 9 '15 at 10:56

Not sure if this helps but, introducing a \strut after every node text will adjust bottom node's limit.

\documentclass{article}
\usepackage{fontspec}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[remember picture,baseline,every node/.style={draw,red,inner sep=0pt,outer sep=0pt}]%
\node [align=left,text width=5em] (moonfact) {The moon is 384,400 kilometers away from earth.\strut};
\node [align=left,text width=5em,anchor=north west,at=(moonfact.north east)] (car) {My car is forty meters away from my garage.\strut};
\end{tikzpicture}%
\begin{tikzpicture}[overlay,remember picture,baseline]%
\draw ([yshift=-1ex]moonfact.south west) -- ([yshift=-1ex]moonfact.south east);
\draw[blue] ([yshift=-1ex]car.south west) -- ([yshift=-1ex]car.south east);
\end{tikzpicture}%
\end{document}


• Awesome Ignasi! That will definitely help. I am going to leave the question open a while longer, but you provided an effective workaround. – Jonathan Komar Feb 9 '15 at 11:48