4
  1. I would like a list of equations (ideally using enumitem's enumerate environment) aligned (e.g.) by the equal sign. Is there a way to achieve that?

    The following produces a list of equations that are not aligned:

    \begin{enumerate}
      \item $a=b$
      \item $c+d=e$
    \end{enumerate}
    

    I want them aligned as in

    \begin{align*}
        a &= b \\
      c+d &= e
    \end{align*}
    

    but numbered with the same spacing of labels that would be produced by enumerate.

  2. If possible, I would also like to know how to have them as much to the left as possible (as opposed to centering produced by align* environment). In the examples above this would mean that the second equation (i.e. "c+d=e") would typeset exactly as it does using enumerate and the first one would be aligned to it.

  3. And finally, at the risk of being unmodest, I wish to be able to choose between inline and display style.

Werner
  • 603,163
MrMRm
  • 75

2 Answers2

6

I would recommend using the functionality provided by eqparbox. Specifically, \eqparbox[<tag>][<align>]{<stuff>} will set <stuff> in a box that has maximum width across the same <tag>, with an additional <align>ment specification (left, center/default or right). With a slight modification that accommodates for math mode, \eqmathbox defined below does the same:

enter image description here

\documentclass{article}

\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{enumerate} \item $\eqmathbox[LHS][r]{a} = b$

\item $\eqmathbox[LHS]{c + d} = e$ \end{enumerate}

\end{document}

The principle behind eqparbox is to store the width of the largest element in the .aux file, after processing the entire document. This .aux is then read during a subsequent compilation, setting elements within the appropriately-sized (maximal) boxes. Since it uses the .aux for processing, it requires at least two compilations with every change in the widest element for a <tag>.

Werner
  • 603,163
2

This solution (which is inspired by code from appendix D of The TeXbook) first typesets the formulas using \halign and then unpacks the \hboxes thus produced, placing each \hbox content after an \item:

\def\itemize{\unskip\setbox0=\lastbox
  \ifhbox0{\itemize}\item\unhbox0 \fi}
\begin{enumerate}
\vbox{\halign{\hfil$#$&${}#$\hfil\cr
  a&=b\cr
  c+d&=e\cr
}\itemize}
\end{enumerate}

enter image description here

The \vbox is necessary because \lastbox cannot be used on the main vertical list.

To achieve displaystyle, replace the \halign template in the fourth row with \hfil$\displaystyle#$&$\displaystyle{}#$\hfil