How can I create a tree node with an aligned math equations inside?

\begin{align}
\end{align}

doesn't work

\begin{minipage}{100}
  \begin{align}
    ...
  \end{align}
\end{minipage}

Gives a lot of margin and I don't want to manually tune 100.

\nodepart from shapes tikz library seems to be overkill and doesnt do the alignment.

Any ideas?

up vote 46 down vote accepted

You could use an aligned environment with inline math inside nodes, their size is automatically calculated. Here's a small example with such a node in a tree:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[every node/.style={rectangle,draw}]
\node {Example:}
  child {node {%
  $\begin{aligned}
     a &= bx + c\\
     a+b &= d +1
  \end{aligned}$}};
\end{tikzpicture}
\end{document}

Output:

alt text

  • Great! it works. But why align doesn't? – Łukasz Lew Aug 8 '10 at 14:26
  • 3
    align is displayed, set off normal text and centered. Here it requires a minipage environment or \parbox, so it needs specifying a width. At least for the centering. – Stefan Kottwitz Aug 8 '10 at 14:40

EDIT

As pointed out by Zarko in the comments, the text width option to the node already defines a minipage. Thus, the minipage environment is superfluous unless you want the minipage width different than the node width.


I know this is old, but, for future reference, if you want to number your equations or really want to use an align environment, you may place it inside a minipage and specify both the node text width and minipage width properties to whatever works for you.

\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}
    % These are needed to remove the vertical space around above and below
    % the align and flalign environments
    \setlength{\abovedisplayskip}{0pt}
    \setlength{\belowdisplayskip}{0pt}

    \node [rectangle, draw] (example) {Examples:};
    \node [rectangle, draw, right=1cm, text width=4cm] (eq1) at (example.east) {
        \begin{minipage}{\textwidth}
            \begin{align}
                x + y &= 1 \\
                x - 2y &= 1
            \end{align}
        \end{minipage}
    };
    \node [rectangle, draw, below=0.5cm, text width=4cm] (eq2) at (eq1.south) {
        \begin{minipage}{\textwidth}
            \begin{flalign}
                x + y &= 2& \\
                x - 2y &= 2&
            \end{flalign}
        \end{minipage}
    };
    \draw [->, line width=1pt] (example) -- (eq1);
    \draw [->, line width=1pt] (example) |- (eq2);
\end{tikzpicture}
\end{document}

This example also includes flalign, since I believe it looks better than align when the node has borders.

enter image description here

  • 1
    when you define text width of node, the node behavior as minipage, consequently use of minipage in your example` is superfluous. the same result you will obtain without it. – Zarko Sep 14 at 13:29

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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