[Tex/LaTex] What’s wrong with minipage(table(minipage(align))) arrangement

alignminipagetables

In an attempt to show the code and the output side by side, I have used a table inside a minipage. The table entries are two minipages and one contains an align environment. Having the align environment in the given setting causes problems.

I get a meaningless error message

Argument \flalign* has an extra }.

as a result.

If I put the minipage that contains the align environment inside an fbox the problem disappears. For some reason, I thought I saw the answer to this problem in SX sometime ago, but now I cannot find it. Why do I get this error message?

The following is the working example. I have commented out the \fbox so that you can see the effect.

\documentclass[11pt]{amsart}  
\begin{document}

\begin{minipage}{1\textwidth}
\begin{tabular}{l r}
\begin{minipage}[t]{.65\textwidth}
\begin{verbatim}
\begin{flalign*}
P &=x^2+y^+2xy &\\
&=(x+y)^2
\end{flalign*}
\end{verbatim}
\end{minipage}
&
%\fbox{
\begin{minipage}[t]{.35\textwidth} 
\begin{flalign*}
P &=x^2+y^2+2xy &\\
&=(x+y)^2
\end{flalign*}
\end{minipage}
%}
\end{tabular}
\end{minipage}

\end{document}

enter image description here

Best Answer

The tabular environment "gets confused" by the & characters of flalign* environment, so you need to hide them using, for example, a pair of braces (or a box, like you found out with \fbox):

\documentclass[11pt]{amsart}  
\begin{document}

\noindent\begin{minipage}{1\textwidth}
\begin{tabular}{@{}l@{}r@{}}
\begin{minipage}[t]{.65\textwidth}
\begin{verbatim}
\begin{flalign*}
P &=x^2+y^+2xy &\\
&=(x+y)^2
\end{flalign*}
\end{verbatim}
\end{minipage}%
&
{%
\begin{minipage}[t]{.35\textwidth} 
\begin{flalign*}
P &=x^2+y^2+2xy &\\
&=(x+y)^2
\end{flalign*}
\end{minipage}%
}
\end{tabular}
\end{minipage}

\end{document}

enter image description here

I did some modifications (removed spurious blank spaces, removed inter-column space) to your code to prevent overfull boxes. Do you really need that somehow complicated nesting structure? At least in this example you can get the same result just with

\documentclass[11pt]{amsart}  
\begin{document}

\noindent\begin{minipage}{\textwidth}
\begin{minipage}[t]{.65\textwidth}
\begin{verbatim}
\begin{flalign*}
P &=x^2+y^+2xy &\\
&=(x+y)^2
\end{flalign*}
\end{verbatim}
\end{minipage}%
\begin{minipage}[t]{.35\textwidth} 
\begin{flalign*}
P &=x^2+y^2+2xy &\\
&=(x+y)^2
\end{flalign*}
\end{minipage}
\end{minipage}

\end{document}

If you're interested in showing code and output side-by-side, perhaps the showexpl package could be of interest to you.