0

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}

Result of the pdf

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
  • 1
    neither \multicolumn` nor \noindent should ever be used in align – David Carlisle Oct 13 '16 at 12:28
1

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}
&\mathrlap{\textbf{minimize:} \qquad\sum_{k=1}^{n} \Xa{A}} \\
&\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}

enter image description here

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}
&\mathrlap{\textbf{minimize:} \qquad\sum_{k=1}^{n} \Xa{A}} \\
&\rlap{\textbf{subject to:}} \nonumber\\
&\Xa{A}<\Xa{B} &\qquad& \forall k \\
&\Xa{A}>\Xa{C} &&       \forall k\\
&F(\Xa{A})=0   &&       \forall k
\end{alignat}
\end{subequations}

\end{document}

enter image description here

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}
&\mathrlap{\textbf{minimize:} \qquad\sum_{k=1}^{n} \Xa{A}} \\
&\rlap{\textbf{subject to:}} \nonumber\\
&\Xa{A}<\Xa{B} &\qquad& \forall k \\
&\Xa{A}>\Xa{C} &&       \forall k\\
&F(\Xa{A})=0   &&       \forall k
\end{alignat}
\end{subequations}

\end{document}
0

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.)

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.