I want to write multiple lines of text within a TikZ rectangle. This is how I did it.
\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node at (0, 0) [rectangle,draw,minimum size=2cm] { \begin{tabular}{c} \( a^2 \) \\ \( b^2 \) \end{tabular} }; \end{tikzpicture} \end{document} This works fine. But I want to understand why using another environment, such as, align* environment or displayed math does not work well like the tabular environment does.
For example, the following code
\documentclass{article} \usepackage{tikz} \usepackage{amsmath} \begin{document} \begin{tikzpicture} \node at (0, 0) [rectangle,draw,minimum size=2cm] { \begin{align*} a^2 \\ b^2 \end{align*} }; \end{tikzpicture} \end{document} leads to the following error.
! Missing \endgroup inserted. <inserted text> \endgroup l.8 \begin{align*} a^2 \\ b^2 \end{align*} The following code
\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node at (0, 0) [rectangle,draw,minimum size=2cm] { \[ a^2 \] }; \end{tikzpicture} \end{document} leads to the following error.
! Missing $ inserted. <inserted text> $ l.8 \[ a^ 2 \] Here are my questions:
- Why is special about
tabularenvironment (compared toalign*or displayed math) that makes it possible to use it as text within a node? - What do the
Missing \endgroup insertedorMissing $ insertederrors mean?



text width=5cm.$\begin{array}{c} a^2 \\ b^2 \end{array}$text widtha node has nothing to fill. Note that usingtext widthis equivalent to putting the contents into a\parbox.\[ a^2 \], try changing it by$a^2$and the error dissapears. Somehow, math delimiters\[ ... \]are not allowed insideTikZ.