2

I have three nodes of equal size which contain text of different lengths. This causes line breaks in two of the nodes.

I would like all of the text to be aligned with the last line of text in the third node. I have fiddled with text depth but because LaTeX reads the text in the third node as one line I don't think it's working the way I want it to.

Is there a simple solution to this problem? Any guidance is appreciated!

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

  \node [draw, text width=5em, minimum height = 5em, align = center] (node1) {One line};    
  \node [draw, right = 1cm of node1, text width=5em, minimum height = 5em, align = center] (node2) {One linebreak};
  \node [draw, right = 1cm of node2, text width=5em, minimum height = 5em, align = center] (node3) {This text has two linebreaks};

\end{tikzpicture}
\end{document}

enter image description here

0

You could place the text separately from the boxes:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

  \node [draw, text width=5em, minimum height = 5em] (node1) {};
  \node [draw, right = 1cm of node1, text width=5em, minimum height = 5em] (node2) {};
  \node [draw, right = 1cm of node2, text width=5em, minimum height = 5em] (node3) {};
  \node[text width=5em, align=center] (node3text) at (node3.center) {This text has two linebreaks};
  \node[anchor=south, text width=5em, align=center] at (node3text.south -| node2.center) {One linebreak};
  \node[anchor=south, text width=5em, align=center] at (node3text.south -| node1.center) {One line};

\end{tikzpicture}
\end{document}

enter image description here

  • This worked great (especially after I added \strut and \vphantom to my actual text to make sure all of the lines were even). Thank you! – M Post Nov 4 '16 at 18:18
1

It is ad hoc solution. If you can approximate the height of the highest text, you can use a proper \vbox:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}



  \node [draw, text width=5em, minimum height = 5em, align = center] (node1) {\vbox to 3em{\vfill  One line}};    
  \node [draw, right = 1cm of node1, text width=5em, minimum height = 5em, align = center] (node2) {\vbox to 3em{\vfill One linebreak}};
  \node [draw, right = 1cm of node2, text width=5em, minimum height = 5em, align = center] (node3) {\vbox to 3em{\vfill This text has two linebreaks}};

\end{tikzpicture}
\end{document}

enter image description here

0

You can also use an equal height group of tcolorboxes and define a bottom vertical alignment.

\documentclass{article}
\usepackage{tcolorbox}

\tcbset{colback=white, sharp corners, width=2.5cm, equal height group=AT, before=, after=\hfill, notitle, halign=center, valign=bottom}

\begin{document}

\begin{tcolorbox}
One line
\end{tcolorbox}
\begin{tcolorbox}
One\\ linebreak
\end{tcolorbox}
\begin{tcolorbox}
This text\\ has two\\ linebreaks\end{tcolorbox}

\end{document}

After two compilations the result is:

enter image description here

  • Thanks so much for your response! Unfortunately I have to do this within a TikZ image. – M Post Nov 4 '16 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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