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}
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.
It's not clear to me why you have minipage
environments encasing tabular
environments. Here's a solution that dispenses with the minipages and top-aligns two tabular
environments within a tabularx
environment.
To avoid overlaps between the \hline
s drawn by the outer tabularx
and the inner tabular
environments, I've omitted some of your \hline
instructions from the inner environments. If you decide to get rid of the outer \hline
s, be sure to re-insert the \hline
s in the inner tabular
s.
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{@{}X@{}X@{}}
\hline
\begin{tabular}[t]{|l|l|}
1 & 2 \\ \hline
3 & 4 \\ \hline
5 & 6
\end{tabular}
&
\begin{tabular}[t]{|l|l|}
7 & 8 \\ \hline
\end{tabular}\\ \hline
\end{tabularx}
\end{document}
Next, here's a version with three vertical bars drawn by the outer tabularx
(far left, middle, and right). To avoid overlap of the vertical lines drawn by the inner and outer table-like environments, it may again be a good idea to omit the first vertical bar from each of the inner tabulars.
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|@{}X|@{}X@{}|}
\hline
\begin{tabular}[t]{l|l|}
1 & 2 \\ \hline
3 & 4 \\ \hline
5 & 6
\end{tabular}
&
\begin{tabular}[t]{l|l|}
7 & 8 \\ \hline
\end{tabular}\\ \hline
\end{tabularx}
\end{document}
Finally, for the sake of completeness, here's the code that's needed if you wish to use minipage
environments after all to typeset the preceding example. Note that it's necessary to use the [t]
position specifier for both minipages and both tabulars in order to get the vertical alignment just right. (Not showing a separate screenshot since the result is identical to the one above.)
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|@{}X|@{}X@{}|}
\hline
\begin{minipage}[t]{\linewidth}
\begin{tabular}[t]{l|l|}
1 & 2 \\ \hline
3 & 4 \\ \hline
5 & 6
\end{tabular}
\end{minipage}
&
\begin{minipage}[t]{\linewidth}
\begin{tabular}[t]{l|l|}
7 & 8 \\ \hline
\end{tabular}
\end{minipage}\\
\hline
\end{tabularx}
\end{document}
Best Answer
This probably achieves what you want (I made the code compilable by replacing
\f
by\frac
and changed the minipage alignment to[h]
):Just for the records: if I wanted to get the vertical line, I'd use
Note that I kicked out some of the unnecessary packages and also removed one of the conflicting options (letterpaper).