[Tex/LaTex] Problem inserting a complicated equation into a (tikz) node

equationsnodestikz-pgf

I have a problem inserting an equation into a tikz node. I'm used to insert successive equations that are separated with 'align', but with my equation (succesive lines, put together with two braces), I does not work, I cannot seem to find the answer to this. I'm using: tikz, tikzlibrary, amsmath, amssymb and amsmath.
I think the problem is with the two braces, and the encapsulated equation…

\begin{equation}

if \;  

  \left\{  
      \begin{aligned}
        x_{ref}=x_1+1\\
        x_{ref}=x_2+1\\
        x_{ref}=x_3+1\\
      \end{aligned}
    \right\rbrace 
\end{equation}

Best Answer

There are several possible problems. The only obvious problem in your snippet is that you have empty lines inside the equation environment, which is not permitted.

That said, egreg is correct in saying that you cannot have an equation environment inside a node, unless you set the text width of the node. That makes the node a minipage like box, and makes it possible to use equation. You could of course also add a minipage inside the node, but that is more messy, I think.

In the code below I also added egreg's suggestion of inline math.

enter image description here

\documentclass[tikz,border=3mm]{standalone}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}
\node [text width=5cm]  {\begin{equation*}
\text{if }  
  \left\lbrace
      \begin{aligned}
        x_{\mathrm{ref}}=x_1+1\\
        x_{\mathrm{ref}}=x_2+1\\
        x_{\mathrm{ref}}=x_3+1\\
      \end{aligned}
    \right\rbrace 
\end{equation*}};

\node at (6,0) {if $ \left\lbrace
      \begin{aligned}
        x_{\mathrm{ref}}=x_1+1\\
        x_{\mathrm{ref}}=x_2+1\\
        x_{\mathrm{ref}}=x_3+1\\
      \end{aligned}
    \right\rbrace$};
\end{tikzpicture}
\end{document}