# How to align equations with integrals and “subject to” equations

I have a long expression (maximization problem) which I force down to the next line using //.

I also have two functions ("subject to") which I want to place underneath. I use & to make the expressions fit vertically.

Problem:

• The third integral expression which I have to force down looks weird and isn't aligned with the two integral expression above. I don't know how to fix it.
• The alignment is off. Fx "Another equation here" should be aligned with Max(n_G, 0) \leq n_{min} \leq Min(n_B,1). Using & obviously doesn't solve the problem.
• Extra: The reason I use \def\mclimits_#1{\limits_{\mathclap{#1}}} is to make the long expression n_{min} fit in the limits of the integral.

Code:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{mathtools}

\def\mclimits_#1{\limits_{\mathclap{#1}}}

\begin{document}

\begin{aligned} \underset{n_{min}}{\text{argmax}} & & \Pi = \frac{1}{M}$\int\mclimits_{n_{min}}^M\! n_cP_c\, \mathrm{d}n_c$ + \frac{p}{M}$\int\mclimits_{n_B}^M\! \delta\bigg(z\beta P_r\big(h(1-n_B)+(1-h)x_B\big)-D\bigg)\, \mathrm{d}n_c$ \\ & & + \frac{1-p}{M}$\int\mclimits_{n_{min}}^M\! \delta\bigg(z\beta P_r\big(h(1-n_B)+(1-h)x_G\big)-D\bigg)\, \mathrm{d}n_c$ \\ \text{subject to} & & Max(n_G, 0) \leq n_{min} \leq Min(n_B,1)\\ & & \text{Another equation here}\\ \end{aligned}

\end{document}


Current output:

• Please make your example compilable. I get errors. – LaRiFaRi Jun 15 '16 at 9:39
• Hmm, I ran it. I get errors too. But it compiles. – Saud Jun 15 '16 at 9:40

Your MWE has errors: you nested equation ($...$) in equation ... I try to figured out what is your problem. After cleaning of your code I obtain the following results:

Is this what you looking for? In your code I also added a split environment for the long first equation:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\DeclareMathOperator*{\argmax}{argmax}

\begin{document}
\begin{align}
\begin{split}
\argmax_{n_{\min}}\Pi
& = \frac{1}{M}\int\limits_{n_{\min}}^M\! n_cP_c\, \mathrm{d}n_c \\
(1-h)x_B\big)-D\bigg)\, \mathrm{d}n_c \\
\delta\bigg(z\beta P_r\big(h(1-n_B) + (1-h)x_G\big)-D\bigg)\, \mathrm{d}n_c
\end{split}                                           \\
\text{subject to}
&\ \max(n_G, 0) \leq n_{min} \leq \min(n_B,1)      \notag  \\
&  \text{Another equation here}
\end{align}
\end{document}


Thanks to @egreg for the improvements he suggested in his comment.

• Yes :) Split works great! I just removed \\ &\qquad between the first and second integral expression to place them on the same line, like in the original code. Just one small thing: Why is "Another equation here" slightly more to the left than the expression just above? – Saud Jun 15 '16 at 10:10
• Because for expression above is shifted after ampersand to the right with \ . (otherwise it sticks with text before it). I assume that there ones wild be real equation, then this shift will looks slightly different. – Zarko Jun 15 '16 at 10:14
• Ah, I see. Yes, will be replaced with a real equation. Thx again! – Saud Jun 15 '16 at 10:16
• \DeclareMathOperator*{\argmax}{argmax} will allow typing \argmax_{n_{\min}\Pi instead of that awful concoction. – egreg Jun 15 '16 at 10:25
• @egreg, yes, this is correct approach. I will consider this in eddit of my answer. – Zarko Jun 15 '16 at 10:29

I am not sure, if I got your right. Like this?

% arara: pdflatex

\documentclass{article}
\usepackage{blindtext}
\usepackage{mathtools}
\DeclareMathOperator{\argmax}{argmax}
\def\mclimits_#1{\limits_{\mathclap{#1}}}

\begin{document}
\blindtext
\begin{align}
\begin{split}
\underset{n_{\min}}{\argmax}(\Pi) &= \frac{1}{M}\int\mclimits_{n_{\min}}^M n_c P_c\, \mathrm{d}n_c \\
&\quad+ \frac{p}{M}\int\mclimits_{n_B}^M \delta\Bigl(z\beta P_r\bigl(h(1-n_B)+(1-h)x_B\bigr)-D\Bigr)\, \mathrm{d}n_c \\
\int\mclimits_{n_{\min}}^M \delta\Bigl(z\beta P_r\bigl(h(1-n_B)+(1-h)x_G\bigr)-D\Bigr)\, \mathrm{d}n_c
\end{split}
\shortintertext{subject to}
&\max(n_G, 0) \leq n_{\min} \leq \min(n_B,1)\\
&\text{Another equation here}
\end{align}
\blindtext
\end{document}


• Yes, looks good :) – Saud Jun 15 '16 at 10:13
• +1 for using \intertext. – Henri Menke Jun 15 '16 at 12:12

With ConTeXT MKIV

\setupmathlabeltext[argmax=argmax]
\definemathcommand[argmax][limop]{\mfunctionlabeltext{argmax}}
\starttext
\placeformula
\startformula
\startmathalignment
\NC \argmax_{n_{\min}}\Pi
\NC = \frac{1}{M}\int\limits_{n_{\min}}^M\! n_cP_c\, \diff n_c \NR
\NC\NC\quad + \frac{p}{M}\int\limits_{n_B}^M\delta\bigg(z\beta P_r\big(h(1-n_B) + (1-h)x_B\big)-D\bigg)\, \diff n_c \NR
\NC\NC\qquad + \frac{1-p}{M}\int\limits_{n_{\min}}^M \delta\bigg(z\beta P_r\big(h(1-n_B) + (1-h)x_G\big)-D\bigg)\, \diff n_c \NR[+]
\startintertext
subject to
\stopintertext
\NC \max(n_G, 0) \NC \leq n_{\min} \leq \min(n_B,1) \NR
\NC              \NC \text{Another equation here} \NR[+]
\stopmathalignment
\stopformula
\stoptext


• What \quad in one line and \qquad in the other; won't \quad on both lines look better (aligned + signs) – Aditya Jun 16 '16 at 4:26
• @Aditya This is a matter of taste, I guess. One could also leave out the horizontal space altogether to have = and + aligned. I'll leave it there, because I like it that way, but your proposed layout would look good as well. May the user decide. – Henri Menke Jun 16 '16 at 7:12

Using the geometry package, you have more sensible margins and it looks nicer with alignat:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{mathtools}
\DeclareMathOperator{\argmax}{argmax}
\def\mclimits_#1{\limits_{\mathclap{#1}}}

\begin{document}

\begin{alignat}{2}
& \argmax_t{n_{\min}}(\Pi) &&=\!\begin{aligned}[t]\frac{1}{M}\int\mclimits_{n_{\min}}^M n_c P_c\, \mathrm{d}n_c + \frac{p}{M}\int\mclimits_{n_B}^M \delta\Bigl(z\beta P_r\bigl(h(1-n_B)+(1-h)x_B\bigr)-D\Bigr)\, \mathrm{d}n_c & \\
+ \frac{1-p}{M} \int\mclimits_{n_{\min}}^M \delta\Bigl(z\beta P_r\bigl(h(1-n_B)+(1-h)x_G\bigr)-D\Bigr)\, \mathrm{d}n_c &
\end{aligned}\\
& \text{subject to} \quad\mathrlap{\max(n_G, 0) \leq n_{\min} \leq \min(n_B,1)} \notag\\[1.5ex]
& \rlap{Another equation here}
\end{alignat}

\end{document}


• I think you mentioned before that this is due to your editor, but there are a lot of Unicode characters creeping into your answer, e.g. Π, β, and δ. Of course this would work if you used a Unicode engine in conjunction with unicode-math, but not with classic pdfTeX. – Henri Menke Jun 16 '16 at 7:15
• Oh! yes. When it's late, I may forget to check. Thanks for pointing it! Hope it's all fixed now. – Bernard Jun 16 '16 at 8:27
• BTW: Which editor are you using? – Henri Menke Jun 16 '16 at 8:30
• WinEdt. I wrote a small package for it that does some sort of pretty-printing in order to have a an easier-to-understand displayed code in formulae (Greek letters, numerical exponents, a number of symbols). – Bernard Jun 16 '16 at 8:34