1

It appears that the siblings of a tree I made in Tikz don't align properly. The text line for each sibling level doesn't seem right.

I'm not sure how to fix this; thanks for any help.

\begin{figure*}
\centering
\begin{tikzpicture}[level 1/.style={sibling distance=8cm},level 2/.style={sibling distance=4cm},level 3/.style={sibling distance=2cm}]
\node {Buying a car}
 child {node {Red}
  child {node {Cloth}
   child {node {Standard}}
   child {node {Upgraded}}}
  child {node {Leather}
   child {node {Standard}}
   child {node {Upgraded}}}}
 child {node {Blue}
  child {node {Cloth}
   child {node {Standard}}
   child {node {Upgraded}}}
  child {node {Leather}
   child {node {Standard}}
   child {node {Upgraded}}}}
;
\end{tikzpicture}
\caption{Options when buying a car.}
\end{figure*}
  • 2
    Please don't post code fragments. Instead put your fragment into a complete compilable document that people can play with. – Alan Munn Jan 15 '18 at 17:29
3

You could use something like

every node/.append style={anchor=mid}

added to the options you pass tikzpicture.

aligned nodes

Or Forest aligns them by default:

\documentclass[border=9pt]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
  [Buying a car
    [Red
      [Cloth
        [Standard]
        [Upgraded]
      ]
      [Velvet
        [Standard]
        [Upgraded]
      ]
  ]
  [Blue
      [Cloth
        [Standard]
        [Upgraded]
      ]
      [Velvet
        [Standard]
        [Upgraded]
      ]
    ]
  ]
\end{forest}
\end{document}

cruelty-free alignment

2

The descenders of the letters p and g in Upgraded force the node to be higher than Standard, whose letters do not have descenders. You can fix this by adding the option anchor=north to the nodes, which will align the siblings as they have the same cap height.

Another solution is to put \vphantom{p} after Standard in every such node, which provides a vertical space the height of the letter p with no horizontal width.

  • Thank you for pointing out the descenders of the letters like p and g. Another solution is to use text depth option in TikZ. – InSung Cho Jan 21 '18 at 11:32
2

This is just an example to use the istgame package:

enter image description here

Revised: To correct the alignment of the last texts, I inserted [text depth=.25ex]and exchanged the picture accordingly.

\documentclass{standalone}

\usepackage{istgame}

\begin{document}

\begin{istgame}
\tikzset{oval node/.style={ellipse node,draw=none}}
% start
\xtdistance{15mm}{80mm}
\istrooto(0){Buying a car} \istb \istb \endist
% Red or Blue
\xtdistance{15mm}{40mm}
\istrooto(1)(0-1){Red} \istb \istb \endist
\istrooto(2)(0-2){Blue} \istb \istb \endist
% Cloth or Leather
\xtdistance{15mm}{20mm}
\istrooto(a)(1-1){Cloth} \istb \istb \endist
\istrooto(b)(1-2){Leather} \istb \istb \endist
\istrooto(c)(2-1){Cloth} \istb \istb \endist
\istrooto(d)(2-2){Leather} \istb \istb \endist
% Standard or Upgrade
\foreach \x in {a,b,c,d}
{
\istrooto(A)(\x-1)[text depth=.25ex]{Standard} \endist % revised
\istrooto(B)(\x-2)[text depth=.25ex]{Upgrade} \endist  % revised
}
\end{istgame}

\end{document}

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.