2

I have the following problem. I am currently trying to convert my paper into an Overleaf Journal template. This has two columns per page. But now my equations are getting a bit out of shape. See here:

This is my code: enter image description here

\begin{align}
    &c_{\tau}\ge d_{it}&\quad \forall i \in I, t\in T, \tau \in \{1,\ldots,t\}\\
    &c_{\tau}\ge d_{it}&\quad \forall i \in I, t\in T, \tau \in \{1,\ldots,t\}\\
    &(1-a_{it})\le \sum_{b=t-\alpha}^{t-1}o_{ib}&\quad\forall i\in I, t\in \{1+\alpha,\ldots,T\}\\
    &M\cdot (1-a_{it})\ge (1-\sum_{b=t-\alpha}^{t-1}o_{ib})&\quad\forall i\in I, t\in \{1+\alpha,\dots,T\}\\
    &a_{it}=0&\quad \forall i\in I, t\in \left\{ 1,\ldots,\alpha \right\}
\end{align}

I was wondering if there is a more elegant way to automatically align the equations to text width (with automatic line breaking).

I am using this template, which uses a elsarticle class.

EDIT:

\begin{alignat}{2}
    &\sum_{d=t}^{d+\bar{D}}w_{id}\le \bar{D}&&\forall i\in I,t\in \{1,\ldots,\mid T\mid - \bar{D}\}\\
    &v_{i(t-1)s}+v_{its}\le 1&& \forall i\in I, t\in \{2,\ldots,\mid T\mid\}, s\in S_r\\
    &1\ge l_{i(t-1)}+l_{iz}&\notag\\
    &\forall i\in I, z\in \left\{ t+1,\ldots,t+\bar{T}-1 \right\},t\in\left\{ 2,\ldots,\mid T\mid-\bar{T}+1 \right\}\\
    &M\cdot (1-a_{it})\ge (1-b_{it})+\sum_{j=t-\alpha}^{t-1}c_{ij}&&\forall i\in I, t\in \{1+\alpha,\dots,T\}
\end{alignat}
3
  • Welcome to TeX.SE. Please tell us which document class you employ.
    – Mico
    Apr 11 at 19:59
  • 1
    Sure. See the OP! Apr 11 at 20:04
  • 1
    Welcome. // Please upgrade you code: it should compile AND show your problem. To do so easily, you may want to follow these steps: tex.meta.stackexchange.com/questions/228/… .
    – MS-SPO
    Apr 11 at 21:09

2 Answers 2

3

(updated my answer to add a solution for the OP's second set of equations.)

I was wondering if there is a more elegant way to automatically align the equations to text width (with automatic line breaking).

I'm afraid the following isn't a solution with automatic line breaking.

I suggest using an alignat{2} environment to display the math material in two columns. Use \smashoperator directives, provided by the mathtools package (a superset of the amsmath package), to tighten the spacing around the \sum symbols.

enter image description here

\documentclass[final,5p,twocolumn,authoryear]{elsarticle}
\journal{Astronomy \& Computing}
\usepackage{mathtools,amssymb}
\usepackage{newtx}  % Times Roman text and math fonts
\usepackage{lipsum} % for filler text
\begin{document}

\lipsum[1][1-5] % filler text

\begin{subequations}
\begin{alignat}{2}
&c_{\tau}\ge d_{it}
    && \forall i \in I, t\in T, \tau \in \{1,\dots,t\}\\
&c_{\tau}\ge d_{it}
    && \forall i \in I, t\in T, \tau \in \{1,\dots,t\}\\
&(1-a_{it})\le \smash[t]{\smashoperator{\sum_{b=t-\alpha}^{t-1}}} o_{ib}
    && \forall i\in I, t\in \{1+\alpha,\dots,T\}\\
&M (1-a_{it})\ge 1-\smash{\smashoperator{\sum_{b=t-\alpha}^{t-1}}} o_{ib}
    &\quad& \forall i\in I, t\in \{1+\alpha,\dots,T\} \\
&a_{it}=0
    && \forall i\in I, t\in \{ 1,\dots,\alpha\}
\end{alignat}
\end{subequations}

\lipsum[2][1-5] % more filler text
\begin{subequations}
\begin{alignat}{2}
&\smashoperator{\sum_{d=t}^{d+\bar{D}}}w_{id}\le \bar{D}
  &&\forall i\in I,t\in \{1,\dots,|T| - \bar{D}\}\\
&v_{i(t-1)s}+v_{its}\le 1
  &\quad& \forall i\in I, t\in \{2,\dots,|T|\}, s\in S_r \\[\jot]
&1\ge l_{i(t-1)}+l_{iz} 
  &&\forall i\in I, z\in \{ t+1,\dots,t+\bar{T}-1 \}, \notag\\
  &&&\phantom{\forall} t\in\{ 2,\dots,|T|-\bar{T}+1 \} \\
&M(1-a_{it})\ge \mathrlap{(1-b_{it})
  +\smashoperator{\sum_{j=t-\alpha}^{t-1}} c_{ij}} \notag\\
  &&&\forall i\in I, t\in \{1+\alpha,\dots,T\}
\end{alignat}
\end{subequations}

\lipsum[3-9]

\end{document}
4
  • Thanks. I really like your answer, sadly it falls short for longer equations (like in the updated OP). Any idea how deal with those? Apr 12 at 14:13
  • @marvelfab12 - Please sse my updated answer.
    – Mico
    Apr 12 at 21:01
  • Thanks, you are a hero. One final question, which doent require a new post. How can i increase the vertical space between to equations? Sometimes, the upper part of the sum is pretty close to the equation above. Apr 13 at 15:11
  • @marvelfab12 - I'm blushing. :-) I've used several \smash directives in the first answer; do check for yourself if you prefer the "look" that's generated without those instructions. Otherwise, the "canonical" [!] way to increase the vertical separation between rows in an align, gather, array, or similar environment is to change the row terminator ["double backslash"] to either \\[1\jot] or even \\[2\jot]. By default, \jot inserts 3pt of additional vertical whitespace between rows.
    – Mico
    Apr 13 at 15:22
2

An alternative solution (for exercise and joy😉) with use of table tblr of tabularray package in math environment. IN MWE below for starting point is used nice @Mico answer (+1). Foe easier placing equation in one colum, for it is used \small font size:

\documentclass[final,5p,twocolumn,authoryear]{elsarticle}
\usepackage{tabularray}
\usepackage{mathtools, amssymb}
\usepackage{newtx}  % Times Roman text and math fonts
\usepackage{lipsum} % for filler text

\begin{document}

\lipsum[1] % filler text

\noindent%
$   \refstepcounter{equation}
\begin{tblr}{colsep = 1pt,
             colspec = {@{} r l X[l, leftsep=2em] Q[r, mode=text, 
                                                    cmd={(\theequation\alph{rownum})}]},
               cells = {font=\small},
              rowsep = 7pt, 
            }
c_{\tau} 
    & \ge d_{it}
        &   \forall i \in I, t\in T, \tau \in \{1,\dots,t\}
            &   \\
c_{\tau}
    & \ge d_{it}
        &   \forall i \in I, t\in T, \tau \in \{1,\dots,t\}
            &   \\
(1-a_{it})
    & \le \smash[t]{\smashoperator{\sum_{b=t-\alpha}^{t-1}}} o_{ib}
        &   \forall i\in I, t\in \{1+\alpha,\ldots,T\} 
            &   \\
M (1-a_{it})
    &   \ge 1-\smash{\smashoperator{\sum_{b=t-\alpha}^{t-1}}} o_{ib}
        &   \forall i\in I, t\in \{1+\alpha,\dots,T\} 
            &   \\
a_{it}
    & =0
        &   \forall i\in I, t\in \{ 1,\dots,\alpha\}
            &   \\
\end{tblr}
$

\lipsum[2-9] % more filler text

\end{document}

enter image description here

2
  • +1. :-) Just out of idle: How would one create a cross-reference to, say, equation "1d"?
    – Mico
    Apr 12 at 5:11
  • @Mico, thank you very much!. hm, so far I forgot on this issues. During day I will check how to do this.
    – Zarko
    Apr 13 at 2:07

You must log in to answer this question.

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