Multicolumn changes equation numbering indentation

I want to display a mathematical problem definition in LaTeX. I know there are several ways to do this, but I would still like to get this method working. Here is a minimal example. The real equations are quite a bit longer:

\documentclass{article}
\begin{subequations}\label{lp}
\begin{align}
\multicolumn{2}{l}{\textbf{min:} \qquad $\displaystyle\sum\limits_{k=1}^{n} A_k$} \\
\multicolumn{2}{l}{\textbf{subject to:}}\nonumber\\
2 + 2 A_k &<  B_k & \forall k \\
A_k &>  C_k & \forall k\\
\multicolumn{2}{$F(A_k = B_k + C_k)$} & \forall k \noindent
\end{align}
\end{subequations}
\end{document}


The problem is the equation numbering. The equation number of the last line is not vertically aligned with the rest (even though the 'for all' symbols are). This seems to be due to the multicolumn statement. (The first line does not show this problem because it doesn't have an extra & symbol). I use the multicolumn statement because I want the "<" and ">" to vertically aligned. Does somebody know more about the reason for the incorrect alignment and how to correct it? Thank you in advance!

• Welcome to TeX SX! Your code is not compilable: it does not start with \documentclass nor end with \end{document}. Also the command \Xa is not defined. Are we supposed to guess what it does? – Bernard Oct 13 '16 at 9:47
• neither \multicolumn nor \noindent should ever be used in align – David Carlisle Oct 13 '16 at 12:28

Tricky. You have to check whether the last line doesn't overlap the "for all k" part.

\documentclass{article}
\usepackage{amsmath,mathtools}

\newcommand{\Xa}[1]{#1_k}

\begin{document}

\begin{subequations}\label{problem}
\begin{alignat}{3}
&\rlap{\textbf{subject to:}} \nonumber\\
&&\Xa{A} &<  \Xa{B} &\qquad& \forall k \\ % <- change \qquad if overlap happens
&&\Xa{A} &>  \Xa{C} && \forall k\\
&\mathrlap{F(\Xa{A})=0} &&&& \forall k
\end{alignat}
\end{subequations}

\end{document}


Explanation. The initial & establishes a left alignment point; the object we want not to be counted in the computation of the column widths are in \mathrlap.

With alignat we are in charge of the spacing; change \qquad to something else if the last term overlaps "for all k".

Less tricky: give up the alignment in the relation signs.

\documentclass{article}
\usepackage{amsmath,mathtools}

\newcommand{\Xa}[1]{#1_k}

\begin{document}

\begin{subequations}\label{problem}
\begin{alignat}{2}
&\rlap{\textbf{subject to:}} \nonumber\\
&\Xa{A}>\Xa{C} &&       \forall k\\
&F(\Xa{A})=0   &&       \forall k
\end{alignat}
\end{subequations}

\end{document}


The first line will not be considered for the size; if you want, just add some backup (computed by eye):

\documentclass{article}
\usepackage{amsmath,mathtools}

\newcommand{\Xa}[1]{#1_k}

\begin{document}

\begin{subequations}\label{problem}
\begin{alignat}{2}
\hspace{-2em}
&\rlap{\textbf{subject to:}} \nonumber\\
&\Xa{A}>\Xa{C} &&       \forall k\\
&F(\Xa{A})=0   &&       \forall k
\end{alignat}
\end{subequations}

\end{document}


Maybe I'm missing something, but I don't see the need (or a chance for success) for \multicolumn directives outside of array and tabular-like environments. The following may be what you're looking for: Note the use of an equation environment for the first equation and an align environment for the remaining three equations. I wouldn't use boldface, by the way; good layout and organization of the material should be more than enough to convey the message. (I also had to provide a guess as to how the macro \Xa is defined.)

\documentclass{article}
\usepackage{amsmath}     % for 'align' and 'subequations' environments
\newcommand\Xa[1]{#1_k}  % is this right?
\begin{document}
\begin{subequations}
$$\label{problem} \text{minimize} \quad \sum_{k=1}^{n} \Xa{A}$$
subject to
\begin{align}
\Xa{A} <  \Xa{B} &\qquad\forall k \\
\Xa{A} >  \Xa{C} &\qquad\forall k \\
`