5

I would like all "columns" in my 'aling' to begin text from left to right (left flush).

I have included my code below, which gives the following result:

enter image description here

As seen in picture:

  • The text in the first column is from right to left
  • The text in the second column is from left to right
  • The text in the third column is from right to left

TEX file:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\begin{document}

\begin{align}
    \text{min} \qquad & \sum_{e\in \mathcal{E}} \sum_{r\in  \mathcal{R}_e} c^r_e x^r_e + \sum_{d \in \mathcal{D}} c^-_d s_d^- + \sum_{d \in \mathcal{D}} c^+_d s^+_d \label{MP1} \\ 
    \text{s.t.} \qquad & \sum_{e\in \mathcal{E}} \sum_{r\in  \mathcal{R}_e} a^r_{ed} x^r_e + s_d^- -s_d^+ = b_d & \forall d \in \mathcal{D} \label{MP2} \\
    & \sum_{r\in  \mathcal{R}_e} x^r_e = 1 & \forall e \in \mathcal{E} \label{MP3} \\
    & x^r_e\in \{ 0,1\} & \forall e \in \mathcal{E}, \forall r \in \mathcal{R}_e \label{MP4} \\
    & 0 \leq s_d^- \leq u_d^- & \forall d \in \mathcal{D} \label{MP5} \\
    & 0 \leq s_d^+ \leq u_d^+ & \forall d \in \mathcal{D} \label{MP6}
\end{align}


\end{document}

Any suggestions?

2 Answers 2

10

As you observed, align alternates between r (right aligned) and l (left alinged) columns. To just get left aligned columns, you cann add & so "skip" the r columns:

enter image description here

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\begin{document}

\begin{align}
    &\text{min} \qquad && \sum_{e\in \mathcal{E}} \sum_{r\in  \mathcal{R}_e} c^r_e x^r_e + \sum_{d \in \mathcal{D}} c^-_d s_d^- + \sum_{d \in \mathcal{D}} c^+_d s^+_d \label{MP1} \\ 
   & \text{s.t.} \qquad && \sum_{e\in \mathcal{E}} \sum_{r\in  \mathcal{R}_e} a^r_{ed} x^r_e + s_d^- -s_d^+ = b_d && \forall d \in \mathcal{D} \label{MP2} \\
    &&& \sum_{r\in  \mathcal{R}_e} x^r_e = 1 && \forall e \in \mathcal{E} \label{MP3} \\
    &&& x^r_e\in \{ 0,1\} && \forall e \in \mathcal{E}, \forall r \in \mathcal{R}_e \label{MP4} \\
    &&& 0 \leq s_d^- \leq u_d^- && \forall d \in \mathcal{D} \label{MP5} \\
    &&& 0 \leq s_d^+ \leq u_d^+ && \forall d \in \mathcal{D} \label{MP6}
\end{align}


\end{document}
2
  • Thank you, for the excellent explanation. It was exactly what I wanted. Commented Mar 21, 2020 at 11:03
  • 1
    It is only my sensation....:-) I often read the thoughts of my students and many have told me that I can predict.
    – Sebastiano
    Commented Apr 3, 2020 at 11:57
8

You also can have this layout with the dedicated optidef package. I changed the numbering so that the constraints are subequations of the first line:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage[short]{optidef}

\begin{document}

\begin{mini!}
  {\qquad}{ \sum_{e\in \mathcal{E}} \sum_{r\in \mathcal{R}_e} c^r_e x^r_e + \sum_{d \in \mathcal{D}} c^-_d s_d^- + \sum_{d \in \mathcal{D}} c^+_d s^+_d \tag{1}}{\label{MP1}}{}
%
\addConstraint{}{\sum_{e\in \mathcal{E}} \sum_{r\in \mathcal{R}_e} a^r_{ed} x^r_e + s_d^- -s_d^+ = b_d\qquad }{\forall d \in \mathcal{D} \label{MP2}}
\addConstraint{}{\sum_{r\in \mathcal{R}_e} x^r_e = 1}{\forall e \in \mathcal{E} \label{MP3}}
\addConstraint{}{x^r_e\in \{ 0,1\}}{\forall e \in \mathcal{E}, \forall r \in \mathcal{R}_e \label{MP4}}
\addConstraint{}{0 \leq s_d^- \leq u_d^- }{\forall d \in \mathcal{D} \label{MP5}}
\addConstraint{}{0 \leq s_d^+ \leq u_d^+}{\forall d \in \mathcal{D} \label{MP6}}
\end{mini!}

\end{document} 

enter image description here

0

You must log in to answer this question.

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