1

I have a tree working written in tikz, however, it's not fully what I wanted it to look like enter image description here

\begin{tikzpicture}[level/.style={sibling distance=60mm/#1}]
\node [circle,draw] (equal){$=$}
  child {node [circle,draw] (m1) {$meters$}
    child {node [circle,draw] (x1) {$X_1$ \\ meters/hour}}
    child {node [circle,draw] (x2) {$X_2$ \\ {\it hour}}}
    }
  child {node [circle,draw] (m2) {$meters$}
    child {node [circle,draw] (y1) {$Y_1$ \\ {\it meters/lap}}}
    child {node [circle,draw] (y2) {$Y_2$ \\ {\it lap}}}
};    

\end{tikzpicture}

My question is first how do I break the text into two lines (\\does not work for some reason), also how do I fix the size of each circle to be the same (meaning shrinking the text for some of the nodes if necessary)

2
1

Using Paul's comment and this question on node size, you can set the minimum size of each node (so you have to adjust the font size of each node separately to make sure it fits inside, with the font= option). Here's the code:

\begin{tikzpicture}[level/.style={sibling distance=60mm/#1},
                    every node/.style={align=center,inner sep=0pt,minimum size=1.5cm}]
\node [circle,draw] (equal){$=$}
  child {node [circle,draw] (m1) {$meters$}
    child {node [circle,draw,font=\tiny] (x1) { $X_1$ \\ meters/hour}}
    child {node [circle,draw] (x2) {$X_2$ \\ {\it hour}}}
    }
  child {node [circle,draw] (m2) {$meters$}
    child {node [circle,draw,font=\footnotesize] (y1) {$Y_1$ \\ {\it meters/lap}}}
    child {node [circle,draw] (y2) {$Y_2$ \\ {\it lap}}}
};    

\end{tikzpicture}

And here's the result:

enter image description here

The node size is set to 1.5cm, which you can change, and I've only adjusted some of the node font sizes.

A personal opinion - I think long text like "meters/hour" is better to split over two lines or abbreviate, rather than trying to shrink the font. Uniform text size in a figure looks better.

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.