2

In the following excerpt, I would like to align the set of equations as indicated by the & or && symbols, except that I need the left-hand side of each equation to be attached to the = or \geq signs. In other words, I would like to have the horizontal white spaces just after the equation numbers.

Thank you in advance for any suggestions.

\documentclass{extbook}
\usepackage{amsmath}

\begin{document}
\begin{equation*}
    \begin{aligned}
        &\textnormal{(i)} \enspace f'(x^*) &&= \sum\limits_{i=1}^m \lambda_i h'_i(x^*) +\sum\limits_{i=1}^p \mu_i^* g'_i(x^*) \\
        &\textnormal{(ii)} \enspace h_i(x^*) &&= 0, \; i=1,\ldots, \, m, \\
        &\textnormal{(iii)} \enspace g_i(x^*) &&\ge 0, \; i=1, \ldots, \, p, \\
        &\textnormal{(iv)} \enspace \mu_i^* g_i(x^*) &&=0, \; i=1,\ldots, \, p, \\
        &\textnormal{(v)} \enspace \mu_i^* &&\ge 0, \; i=1,\ldots, \, p.
    \end{aligned}
\end{equation*}
\end{document}

enter image description here

2 Answers 2

3

You just need to insert an additional & instead of \enspace in your aligned environment. However, it seems like you're interested in an enumeration of a list of elements, coupled with an alignment around the relations. For that, set each equation as an \item with some box measurement/manipulation to aid with the lefthand side alignment.

Both options are shown below:

enter image description here

\documentclass{article}

%\usepackage{showframe}
\usepackage{enumitem}
\usepackage{amsmath,eqparbox}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
  \IfValueTF{#1}
    {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
    {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
  \mathpalette\eqmathbox@{#3}
}
\makeatother


\begin{document}

\[
  \begin{aligned}
    &\textnormal{(i)}   &          f'(x^*) &= \sum\limits_{i = 1}^m \lambda_i h'_i(x^*) + \sum\limits_{i = 1}^p \mu_i^* g'_i(x^*) \\
    &\textnormal{(ii)}  &         h_i(x^*) &= 0, ~ i = 1,\dots, m, \\
    &\textnormal{(iii)} &         g_i(x^*) &\geq 0, ~ i = 1, \dots, p, \\
    &\textnormal{(iv)}  & \mu_i^* g_i(x^*) &= 0, ~ i = 1, \dots, p, \\
    &\textnormal{(v)}   &          \mu_i^* &\geq 0, ~ i = 1, \dots, p.
  \end{aligned}
\]

\begin{enumerate}[label={(\roman*)},align=left]
  \item
  $\displaystyle\eqmathbox[LHS][r]{f'(x^*)} = \sum\limits_{i = 1}^m \lambda_i h'_i(x^*) + \sum\limits_{i = 1}^p \mu_i^* g'_i(x^*)$

  \item
  $\eqmathbox[LHS][r]{h_i(x^*)} = 0, ~ i = 1,\dots, m$,
  
  \item
  $\eqmathbox[LHS][r]{g_i(x^*)} \geq 0, ~ i = 1, \dots, p$,

  \item
  $\eqmathbox[LHS][r]{\mu_i^* g_i(x^*)} = 0, ~ i = 1, \dots, p$,

  \item
  $\eqmathbox[LHS][r]{\mu_i^*} \geq 0, ~ i = 1, \dots, p$.
\end{enumerate}

\end{document}

\eqmathbox[<tag>][<align>]{<stuff>} sets <stuff> in the widest box possible across all similar <tag>s, with additional <align>ment options (default is centred, but you can also align to the left or right).

Since eqparbox (used by \eqmathbox internally) measures its contents using a mechanism similar to what \label-\ref does (via the .aux), you'll have to compile at least twice with every change of the maximum width in some <tag> (necessarily also on the first compilation).

showframe was used to indicate the text block boundary (seen in the image as the black bars along the side).

6
  • Thank you, @Werner. I was also wondering how to align the set of equations to the left of the page. (Sorry, I should have probably asked that in the question.)
    – AEW
    Commented Jul 14, 2023 at 1:13
  • @AEW: Do you still want a math display? Or do you really just want an enumerated list with elements in it, but the elements still aligned around the relations?
    – Werner
    Commented Jul 14, 2023 at 1:24
  • I think I need the math environment to keep the equation alignment that you proposed.
    – AEW
    Commented Jul 14, 2023 at 1:36
  • @AEW: It's not about what you think you need... what is it that you want? Here are the options, visually: image
    – Werner
    Commented Jul 14, 2023 at 1:51
  • What I want is the second option. Thanks.
    – AEW
    Commented Jul 14, 2023 at 1:54
3

Use alignedat:

\documentclass{extbook}
\usepackage{amsmath}

\begin{document}
\begin{equation*}
    \begin{alignedat}{2}
        &\textnormal{(i)} & f'(x^*) &= \sum\limits_{i=1}^m \lambda_i h'_i(x^*) +\sum\limits_{i=1}^p \mu_i^* g'_i(x^*) \\
        &\textnormal{(ii)} & h_i(x^*) &= 0, \; i=1,\ldots, \, m, \\
        &\textnormal{(iii)} & g_i(x^*) &\ge 0, \; i=1, \ldots, \, p, \\
        &\textnormal{(iv)} & \enspace \mu_i^* g_i(x^*) &=0, \; i=1,\ldots, \, p, \\
        &\textnormal{(v)} & \mu_i^* &\ge 0, \; i=1,\ldots, \, p.
    \end{alignedat}
\end{equation*}
\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 .