3

For almost an hr I have been starring at this and can't figure where is my syntax error

\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}

\usepackage{forest}
\useforestlibrary{edges}
\begin{document}

\begin{forest}
[   
  {\begin{align*}
      x &= 1
  \end{align*}}
]
\end{forest}    
\end{document}

Compiling gives

! Missing \endgroup inserted.
<inserted text> 
\endgroup 
l.16 \end{forest}

I know one needs to add {....} around all math to protect it and that is what I did. If I use normal math, it works

\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}

\usepackage{forest}
\useforestlibrary{edges}
\begin{document}

\begin{forest}
[   
  {$x = 1$}
]
\end{forest}

\end{document}

No errors. I also found if I put the align environment in minipage the error goes away:

\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}

\usepackage{forest}
\useforestlibrary{edges}
\begin{document}

\begin{forest}
[   
  \begin{minipage}{2cm} 
  {\begin{align*}
      x &= 1
  \end{align*}}
  \end{minipage}
]
\end{forest}

\end{document}

No errors.

So why does the first example above give an error? I know I must be making some syntax error, but I just do not see what it is.

TL 2022

Update

OMG! I find workaround, but have no clue why this makes it work. Simply adding ,text width=3cm after it, now it works

\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}

\usepackage{forest}
\useforestlibrary{edges}
\begin{document}

\begin{forest}
[   
   {\begin{align*}
      x &= 1
    \end{align*}}
   ,text width=3cm% ADDING THIS MAKES IT WORK
]
\end{forest}    
\end{document}

enter image description here

But why??

Update

aligned does not really do what I want. Here is an example below

\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}

\begin{forest}
[   
Write the ode as 
{$\begin{aligned}
y'+p(x)y&=q(x)\\
        &=f(x,y)
\end{aligned}$}
This is only possible if ode is linear in {$y$}
]
\end{forest}

\end{document}

enter image description here

I wanted it to look like this

\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}

\begin{forest}
[   
Write the ode as 
{\begin{align*}
y'+p(x)y&=q(x)\\
        &=f(x,y)
\end{align*}
}
This is only possible if ode is linear in {$y$}
,text width=3cm
]
\end{forest}

\end{document}

enter image description here

But thanks to the answer, I know now that I needed to add specific value for the width for align* to work. So I am all OK now. I changed my code to make sure there is a specific text width given and the error now is gone.

2
  • 2
    you would get the same error if you put align in \mbox you can not have vertical displays. a tikz node is an mbox unless you give it a width when it is a minipage Mar 23 at 7:06
  • Replacing {\begin{align*} x &= 1 \end{align*}} with {$\begin{aligned} x &= 1 \end{aligned}$} (or, better still, with {$x = 1$}, as there's nothing to align in this simple example, right?) works too.
    – Mico
    Mar 23 at 7:14

1 Answer 1

4
  • Display style math in node always require defined node sizes. For example, it doesn't work in:
    • pure standalone
    • in table with c, l or r type of columns.
    • etc
  • I wonder, why you need display style in nodes? Isn't it simpler to use in-line math?
\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}

\usepackage{forest}
\useforestlibrary{edges}

\begin{document}

\begin{forest}
[root
    [{$\begin{aligned}
          x &= 1 \\[-1ex]
      x + y &= 2
    \end{aligned}$}]
]
\end{forest}
\end{document}

enter image description here

4
  • Thanks but aligned does not make the equations in display mode inside the node. So they look different now. I'll post an example. my nodes has lots of math in them. The one I showed in my question was just a MWE. I'll add another example now.
    – Nasser
    Mar 23 at 7:46
  • @Nasser, no. It looks the same. Make a comparison with your solution in another node. Frankly said, it is unclear, what you like to achieve.
    – Zarko
    Mar 23 at 8:28
  • How it looks the same? I posted an example? Did you not see my example? Did I do something wrong in my example? I need to have more text in the node than just the math. But anyway, I am all set now. Thanks for pointing out I needed to give specific value for the size for align* to work.
    – Nasser
    Mar 23 at 8:32
  • @Nasser, sorry, I have only information which you provide. For more context, please provide more realistic M(no)WE ... In it you show suggested comparison.
    – Zarko
    Mar 23 at 9:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .