5

I'm trying to produce a tree diagram with tikz with vertically and horizontally centered text in my nodes. The second is working but the text is not vertically aligned although I'm using "text centered". Here is my code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
grow = right,
level 1/.style={sibling distance=1.5cm,level distance=4.5cm},
edge from parent/.style={thick,draw=blue!40!black!60},
every node/.style = {shape=rectangle, rounded corners, thick,
    draw=blue!40!black!60, align=center,
    top color=white, bottom color=black!20!white,
    text centered, text width=2.75cm, text height = 0.5cm}]]
\node {Question}
child { node {\small Question}}
;
\end{tikzpicture}
\end{document}

This produces the following:

enter image description here

Any idea of what I'm doing wrong here?

| improve this question | | | | |
  • 3
    Do not use text height replace it with minimum height=1cm. – Salim Bou May 16 '16 at 8:44
  • 2
    The text height is the distance from the baseline of the text to the top of the box with the text. Similarly there is a text depth, see also their descriptions in the manual. text centered is not described in the manual, but I would guess that only relates to the justification of the text in the node. Anyway, as @salimbou says, I think minimum height is what you want to use here. – Torbjørn T. May 16 '16 at 8:52
6

use minimum height and font=\small instead of \small in the text.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
  grow = right,
  level 1/.style=
  {
    sibling distance=1.5cm,
    level distance=4.5cm
  },
  edge from parent/.style=
  {
    thick,
    draw=blue!40!black!60
  },
  every node/.style = 
  {
    shape=rectangle,
    rounded corners,
    thick,
    draw=blue!40!black!60,
    align=center, 
    font=\small,
    top color=white,
    bottom color=black!20!white,
    text centered,
    text width=2.75cm,
    minimum height = 1cm,
  }
  ]
\node {Question}
child { node {Question}}
;
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | | | | |
  • text centered = align=center ? it is sufficient to use only one from both :-) – Zarko May 16 '16 at 10:14

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.