[Tex/LaTex] How to “align” the LyX aligned math environment

environmentsequationslyx

I frequently use the aligned math environment in LyX to typeset my equations. However, if I want to save space on the page and set two equations simultaneously in the same aligned math environment, the second equation fails to "stay" straight (see image below).

enter image description here

What do I need to do in order to set the equalities in the right equation in a straight line, like the ones in the left equation?

I've tried the following: using other math environments, inserting blank spaces, adding more columns.

Best Answer

This is precisely what the alignat and alignat* environments are designed for: they allow you to vertically align multiple columns. (Just as with align and align*, alignat numbers each equation and alignat* doesn't number them.)

To align n columns, place them in \begin{alignat*}{n}...\end{alignat*}, and align each column with an & as usual. However, you also need an & to separate each column (as in an array or table), and in the first row, you should insert any extra space you need before this separator.

Here's the LaTeX code I have:

\documentclass{article}
\usepackage{amsmath}
% \dr{F}{x} produces δF/δx
% \hdr{2}{F}{x} produces δ²F/δ²x
\newcommand{\dr}[2]{\frac{\delta #1}{\delta #2}} 
\newcommand{\hdr}[3]{\frac{\delta^{#1} #2}{\delta^{#1} #3}}
\begin{document}
\begin{alignat*}{2}
% set spacing between columns in the first row
\dr{F}{x} &= ye^{x+y} + y^3 + 2xy - 1 \qquad\qquad & \dr{F}{y} &= ye^{x+y} + e^{x+y} + 3xy^2+ x^2\\
\hdr{2}{F}{x} &= ye^{x+y} + 2y                     & \hdr{2}{F}{y} &= ye^{x+y} + 2e^{x+y} + 6xy\\
\hdr{3}{F}{x} &= ye^{x+y}                          & \hdr{3}{F}{y} &= ye^{x+y} + 3e^{x+y}+ 6x\\
\hdr{4}{F}{x} &= ye^{x+y}                          & \hdr{4}{F}{y} &= ye^{x+y}+ 4e^{x+y}\\
&\vdots                                            & \vdots\\
\hdr{r}{F}{x} &= ye^{x+y}                          & \hdr{r}{F}{y} &= ye^{x+y} + re^{x+y}
\end{alignat*}
\end{document}

And here's the result.

enter image description here