3

I want to know how to align these equations neatly and make them one after the other. I have tried all combinations of aligned, align etc but nothing seems to be working for me. Can you please tell me how to align these equations. I will be really grateful. Thank you!

\begin{equation}
Minimise \ \  \sum_{i \in M} q_i^{pub} p_i^{pub} + (1 - \mu) z 
\end{equation}
\vspace{-1cm}

\begin{equation}
\begin{aligned}
Subject \ \ to \ \ \ \ \ z \geq p_i^{pub} - p_j^{pub}  \ \ \ \ i,j\in M,  \ i \neq j 
\end{aligned}
\end{equation}


\vspace{-1cm}

\begin{equation}
\begin{algined}
\sum_{i \in M} q_i^{pub} \geq 0.57 D
\end{algined}
\end{equation}


\vspace{-1cm}

\begin{equation}
 q_i^{pub} + bp_i^{pub} - cp_j^{pub} = a^{pub} \ \  \ \ i,j\in M,  \ i \neq j 

\end{equation}

\vspace{-1cm}

\begin{equation}
\sum_{s \in S} q_i^{s} p_i^{s} \geq P_i \ \ \ \ i \in M 
\end{equation}

\vspace{-1cm}

\begin{equation}
\sum_{s \in S} q_i^{s} \leq K_i  \ \ \ \ i \in M 
\end{equation}

\vspace{-1cm}

\begin{equation}
K_i - q_i^{pub} \geq U  \ \ \ \ i \in M 
\end{equation}

\vspace{-1cm}

\begin{equation}
p_i^{pub} \leq \rho_i  \ \ \ \ i \in M 
\end{equation}

\vspace{-1cm}

\begin{equation}
q_i^{pub}, p_i^{pub}, z \geq 0  \ \ \ \ i \in M 
\end{equation}

1
  • Welcome to TeX SX! Do you really want to align these equations at left, or just align them neatly?
    – Bernard
    Mar 20, 2021 at 17:18

3 Answers 3

7

Something like this?

enter image description here

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
&\textup{Minimise}\quad \sum_{i \in M} q_i^{\mathrm{pub}} p_i^{\mathrm{pub}} + (1 - \mu) z
\\
&\begin{alignedat}{3}
&\textup{Subject to}\quad && z \geq p_i^{\mathrm{pub}} - p_j^{\mathrm{pub}}
  &\quad& i,j\in M,\ i \neq j 
\\
&&& \sum_{i \in M} q_i^{\mathrm{pub}} \geq 0.57 D
\\
&&& q_i^{\mathrm{pub}} + bp_i^{\mathrm{pub}} - cp_j^{\mathrm{pub}} = a^{\mathrm{pub}}
  &\quad& i,j\in M,\ i \neq j 
\\
&&& \sum_{s \in S} q_i^{s} p_i^{s} \geq P_i
  &\quad& i \in M 
\\
&&& \sum_{s \in S} q_i^{s} \leq K_i  &\quad& i \in M 
\\
&&& K_i - q_i^{\mathrm{pub}} \geq U  &\quad& i \in M 
\\
&&& p_i^{\mathrm{pub}} \leq \rho_i  &\quad& i \in M 
\\
&&& q_i^{\mathrm{pub}}, p_i^{\mathrm{pub}}, z \geq 0  &\quad& i \in M 
\end{alignedat}
\end{align*}

\end{document}
3
  • +1: Maybe a stupid question. (1) I am looking at the amsmath manual at the moment to find out what the argument {3} means for the \begin{alignedat}{3} environment. In Chapter 3.7 Alignment building blocks for example, I do not see the second argument. (joke: plus they use the evil \left and \right commands). Where can I read about the second argument? FRom the context, I assume that it means that the 3rd column is the reference/anchor. (2) Do I understand correctly, that the first "column" has no content? Meaning that there is no content left of the first &. Mar 21, 2021 at 0:37
  • 1
    @Dr.ManuelKuehner The argument to alignedat (or alignat) is the number of column pairs (right aligned and left aligned) you want. So for 3, you have at most 5 alignment points to specify.
    – egreg
    Mar 21, 2021 at 9:34
  • Thanks for the follow-up! Mar 21, 2021 at 15:51
4

Or like this?

enter image description here

\documentclass{article}
\usepackage{amsmath} % for 'alignat' environment
\newcommand\pub{\mathrm{pub}}
\begin{document}

\begin{equation}
\text{Minimise} \quad \sum_{i \in M} q_i^{\pub} p_i^{\pub} + (1 - \mu) z 
\end{equation}
subject to
\begin{alignat}{2}
z &\geq p_i^{\pub} - p_j^{\pub} &\quad&i,j\in M,  \ i \neq j \\
\sum\nolimits_{i \in M} q_i^{\pub} &\geq 0.57 D \\
 q_i^{\pub} + bp_i^{\pub} - cp_j^{\pub} &= a^{\pub} && i,j\in M,  \ i \neq j \\
\sum\nolimits_{s \in S} q_i^{s} p_i^{s} &\geq P_i && i \in M  \\
\sum\nolimits_{s \in S} q_i^{s} &\leq K_i && i \in M \\
K_i - q_i^{\pub} &\geq U     && i \in M \\
p_i^{\pub} &\leq \rho_i      && i \in M \\
q_i^{\pub}, p_i^{\pub}, z &\geq 0 && i \in M 
\end{alignat}
\end{document}
1
  • 1
    Just wanted to say thanks Mico! Mar 21, 2021 at 8:10
4

I suggest to use the optidef package, dedicated to the layout of optimisation problems. The code below proposes two of the possibilities:

\documentclass{article}
\usepackage{optidef}

\begin{document}

\begin{mini!}[2]{}{\sum_{i \in M} q_i^\text{pub} p_i^\text{pub} + (1 - \mu) z\label{eq; objective}}%
{\label{eq:minimisation}}{}
  \addConstraint{z}{\geq p_i^\text{pub} - p_j^\text{pub}}{\qquad i,j\in M,\enspace i \neq j}
\addConstraint{\sum_{i \in M} q_i^\text{pub}} {\geq 0.57 D}
\addConstraint{q_i^\text{pub} + bp_i^\text{pub} - cp_j^\text{pub}}{= a^\text{pub}}{\qquad i,j\in M, \enspace i
\neq j}
\addConstraint{\sum_{s \in S} q_i^{s} p_i^{s}}{\geq P_i } {\qquad i \in M}
\addConstraint{\sum_{s \in S} q_i^{s}}{\leq K_i}{\qquad i \in M}
\addConstraint{K_i - q_i^\text{pub}}{\geq U }{\qquad i \in M}
\addConstraint{p_i^\text{pub}}{\leq \rho_i}{\qquad i \in M}
\addConstraint{q_i^\text{pub}, p_i^\text{pub}, z}{\geq 0}{\qquad i \in M}
\end{mini!}

\begin{mini!}{}{\sum_{i \in M} q_i^\text{pub} p_i^\text{pub} + (1 - \mu) z\label{eq; objective}}%
{\label{eq:minimisation}}{}
  \addConstraint{z}{\geq p_i^\text{pub} - p_j^\text{pub}}{\quad i,j\in M,\enspace i \neq j}
\addConstraint{\sum_{i \in M} q_i^\text{pub}} {\geq 0.57 D}
\addConstraint{q_i^\text{pub} + bp_i^\text{pub} - cp_j^\text{pub}}{= a^\text{pub}}{\quad i,j\in M, \enspace i
\neq j}
\addConstraint{\sum_{s \in S} q_i^{s} p_i^{s}}{\geq P_i } {\quad i \in M}
\addConstraint{\sum_{s \in S} q_i^{s}}{\leq K_i}{\quad i \in M}
\addConstraint{K_i - q_i^\text{pub}}{\geq U }{\quad i \in M}
\addConstraint{p_i^\text{pub}}{\leq \rho_i}{\quad i \in M}
\addConstraint{q_i^\text{pub}, p_i^\text{pub}, z}{\geq 0}{\quad i \in M}
\end{mini!}

\end{document} 

enter image description here

3
  • Instead of 1a, .. 1i, is it not possible to label 1, 2 ,3 4, and so on ? Mar 21, 2021 at 8:10
  • Also, thanks a ton Bernard! Mar 21, 2021 at 8:10
  • @IshaanSingh: I suppose it might be possible patching the code in the package. With the default numbering it means iy's using the subequations environment (which is meaningful, semantically).
    – Bernard
    Mar 21, 2021 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .