# Aligning the equations and equation numbers correctly

I have the following code

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{minipage}{16cm}
Maximization:\\
\begin{minipage}{7.6cm}
\begin{align}
&\sup_{{g_0}\in\mathcal{G}_0} P_F(\delta,g_0)\nonumber\\
\end{align}
\end{minipage}
\begin{minipage}{7.6cm}
\begin{align}\label{equation311}
&\sup_{{g_1}\in\mathcal{G}_1} P_M(\delta,g_1)\nonumber\\
\end{align}
\end{minipage}
\end{minipage}
\begin{minipage}{16cm}
Minimization:\\
$$\min_{\delta\in\Delta} P_E(\delta,\hat{g}_0,\hat{g}_1)$$
\end{minipage}
\end{document}


and I use

\documentclass[12pt,twoside,a4paper]


Here is the output

Problems are as follows:

The equation number is outside the text and the formulas are also almost overlapping with the text, including 'Maximization:'. I want a normal vertical space of say equation environment in all cases. I don't want to arrange the vspaces and hspaces by hand because it won't be accurate, especially for the equation number which must be aligned with all other equation numbers in the text.

One more thing: Although I use align environment $\sup$ and "s.t." are als not well aligned, as it can be seen in the figure.

What is the best way of solving this problem?

• Well, 16cm is about 455pt, but \documentclass[12pt,twoside,a4paper] sets \textwidth to 390pt, so it's no wonder things overrun the margin. It's usually better to use fractions of \textwidth for minipages. Beyond that, it's hard to see exactly what you want; perhaps you could upload a picture to illustrate this. – Ian Thompson Mar 26 '15 at 14:09
• @IanThompson \begin{minipage}{390pt} couldnt align. What I want is as follows: If I am able to used just one align environment or just one equation environment, then everything is fine. Because there is enough vspace and equations are perfectly alligned. BUT; I am not able to do it with a single align or even with a few align. Therefore I use minipage and it creates me unwanted problems as shown with the image. – Seyhmus Güngören Mar 26 '15 at 14:44
• @SeyhmusGüngören Ian Thompson suggested you use \begin{minipage}{\textwidth}. And it works quite fine if then you make the two sub-level minipages \begin{minipage}{0.45\textwidth}. – Manuel Weinkauf Mar 26 '15 at 15:13
• @ManuelWeinkauf Ok. I had understood it wrong. Now I did it and it works fine. Still vspaces are problem. – Seyhmus Güngören Mar 26 '15 at 15:18

Rather than fight with minipage environments, you could try turning it round like this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{aligned} \text{Maximization:}\quad & \begin{aligned} &\sup_{g_0\in\mathcal{G}_0} P_F(\delta,g_0) \quad \text{s.t. g_0>0, \Upsilon(g_0)=\int_{\mathbb{R}}g_0\,\mathrm{d}\mu=1}\\ &\sup_{g_1\in\mathcal{G}_1} P_M(\delta,g_1) \quad \text{s.t. g_1>0, \Upsilon(g_1)=\int_{\mathbb{R}}g_1\,\mathrm{d}\mu=1} \end{aligned} \\[12pt] \text{Minimization:}\quad &\min_{\delta\in\Delta} P_E(\delta,\hat{g}_0,\hat{g}_1) \end{aligned}

\end{document}

• I must confess that is seems really nice. Btw, why min is not perfectly aligned with sups? I also think that maximization could better be aligned with the first sup rather than being in the middle. I am trying now. – Seyhmus Güngören Mar 26 '15 at 16:16
• because the subscripts stick out a bit... – Thruston Mar 26 '15 at 16:16
• One more thing. Is it possible to take the equation number to bottom. Namely to the same line with "minimization"? – Seyhmus Güngören Mar 26 '15 at 16:19
• @SeyhmusGüngören Just use \begin{aligned}[b]. – Manuel Mar 26 '15 at 16:44
• @Manuel I used it and in all cases I solved my problem with the equation number but in neither cases (using [b] for the inner, outer and both aligneds) I was able to get Maximization aligned with the first "sup" – Seyhmus Güngören Mar 26 '15 at 17:01

this should give exactly the result requested, grouping lines with a combination of the multi-line display environments provided by amsmath. mathtools is loaded instead of amsmath to be able to use \shortintertext; mathtools loads amsmath, so it's not necessary to explicitly load both.

there is an added \, before the \text{s.t.} to account for the fact that a thin space is automatically added before an operator (\sup), and it was requested that these line up. \text is generally preferable to \mbox, as it will choose the correct size.

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}

\numberwithin{equation}{section}

\begin{document}
\setcounter{section}{3}
\setcounter{equation}{22}
\noindent
XXXXX
\begin{gather}
\shortintertext{Maximization:}
\begin{alignedat}{5}
&\sup_{{g_0}\in\mathcal{G}_0} && P_F(\delta,g_0)
&&\sup_{{g_1}\in\mathcal{G}_1} && P_M(\delta,g_1) \\
&& \,\text{s.t.} && g_1>0, \Upsilon(g_1)=\int_{\mathbb{R}}g_1\mbox{d}\mu=1.
\nonumber
\end{alignedat}\\
\shortintertext{Minimization:}
\min_{\delta\in\Delta} P_E(\delta,\hat{g}_0,\hat{g}_1)
\label{equation311}
\end{gather}
XXXXX
\end{document}


• \, seems unnecessary. TeX adds a thin space in front of \sup only in certain cases, if it's the “first item in the list” the space is not added (I hope I'm not using words that have certain important meaning here). – Manuel Mar 26 '15 at 17:11
• @Manuel -- thanks for the observation. i added the \. because when i tested this, the "s.t." was visibly aligned to the left of the "sup" expression. i hesitate to remove it for that reason. – barbara beeton Mar 26 '15 at 17:13
• In fact, here it's added since you have & before it (which adds an invisible \mathord{} I think). So I got it wrong. In any case, part of the space is because of the subscript, so \mathclap{..} would be handy. – Manuel Mar 26 '15 at 17:15
• @Manuel -- i began each row with & expressly because the op requested alignment. your conjecture is correct. in this particular case, \clap would probably work, but if the lower limit on "sup" were wider, or whatever follows it had a descender, it might not. if one is really fussy, then more experimentation along those lines would be in order. – barbara beeton Mar 26 '15 at 17:20
• thx for the answer. – Seyhmus Güngören Mar 26 '15 at 17:26

This does not solve the problem, but at least it provides a real minimal example for others to try, including all necessary packages. Next time, this is your job (this is not your first question, so more effort could be expected). Additionally, if you want to solve the problem with misaligned equation numbers, you hardly should deactivate them in your code, should you?

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{minipage}{16cm}
Maximization:\\
\begin{minipage}{7.6cm}
\begin{align}
&\sup_{{g_0}\in\mathcal{G}_0} P_F(\delta,g_0)\\
\end{align}
\end{minipage}
\begin{minipage}{7.6cm}
\begin{align}\label{equation311}
&\sup_{{g_1}\in\mathcal{G}_1} P_M(\delta,g_1)\\
$$\min_{\delta\in\Delta} P_E(\delta,\hat{g}_0,\hat{g}_1)$$