The output from the following script
\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\node(title)[text width = 0.25\textwidth, text height = 3 cm, draw]{title};
\end{tikzpicture}
\end{document}
is
How can I vertically align the text in the node?
Specifying the text depth
as in
\node(title)[text width = 0.25\textwidth, text height = 1cm, text depth = 1 cm, draw]{
title line 1\\
title line 2\\
title line 3};
Does not result in the text being vertically centred.
Best Answer
text height
andtext depth
specify the vertical dimensions of the text you give explicitly. As a result TikZ thinks the node's text has exactly that height and draws its box like that.You can use
minimum height
to set a minimum vertical size of the node, andminimum width
for the width (whiletext width
inserts line wrapping at the specified widthminimum width
does not). The result will be a box in which your text is centred, but the box must have at least those dimensions. Note thatminimum height
is both height and depth around your text (evenly). If you want line wrapping text which is horizontally centred you can usetext width
andtext centered
.Compare the following: