2

Goal

I want to align some equations separated by enumerate items, with :s lined up. The picture below is an example.

output of my code

Since there are enumerate items between those equations, it might not be easy to adapt solutions using \intertext or breqn to solve my problem.

My attempt

I tried to define a command using \llap and \rlap, and it worked almost perfect:

\documentclass{article}
%\usepackage{lua-visual-debug}
\newcommand{\centersymbolalign}[2]{
  \llap{$\displaystyle{#1}$}\rlap{$\displaystyle{#2}$}
}

\begin{document}

The set $G$, endowed with the binary operation $\circ$ (briefly, $(G,\circ)$, or simply $G$ if the operation can be understood) is a \textbf{group} if

\begin{enumerate}
  \item the operation $\circ$ is \textbf{associative},
  \[
    \centersymbolalign{(\forall\,g,\,h,\,k \in G):}{\quad(g \circ h) \circ k = g \circ (h \circ k);}
  \]
  \item there exists an \textbf{identity element} $e_G$ for $\circ$, that is,
  \[
    \centersymbolalign{(\exists e_G \in G)(\forall g \in G):}{\quad g \circ e_G = g = e_G \circ g;}
  \]
  \item every element in $G$ has an \textbf{inverse} with respect to $\circ$, that is,
  \[
    \centersymbolalign{(\forall g \in G)(\exists h \in G):}{\quad g \circ h = e_G = h \circ g.}
  \]
\end{enumerate}

\end{document}

However, this caused a bug when the line above the equation is shorter than half of \textwidth: the extra space between texts and "displayed equations" disappeared.

the bug

\documentclass{article}
\usepackage{lua-visual-debug}
\newcommand{\centersymbolalign}[2]{
  \llap{$\displaystyle{#1}$}\rlap{$\displaystyle{#2}$}
}

\begin{document}

\begin{itemize}
\item \textbf{normal equations}
\begin{enumerate}
  \item short short short short short
  \[
    (\forall\,g,\,h,\,k \in G):\quad(\forall\,g,\,h,\,k \in G);
  \]
  \item long long long long long long long long
  \[
    (\forall\,g,\,h,\,k \in G):\quad(\forall\,g,\,h,\,k \in G);
  \]
\end{enumerate}

\item \textbf{equations using} \verb|\llap|s
\begin{enumerate}
  \item short short short short short
  \[
    \centersymbolalign{(\forall\,g,\,h,\,k \in G):}{\quad(\forall\,g,\,h,\,k \in G);}
  \]
  \item long long long long long long long long
  \[
    \centersymbolalign{(\forall\,g,\,h,\,k \in G):}{\quad(\forall\,g,\,h,\,k \in G);}
  \]
\end{enumerate}
\end{itemize}

\end{document}

I assume that it was caused by two reasons:

  1. LaTeX smartly manages that extra space. When the left end of the displayed equation box is on the right of the end of the line above, there is no need to have that extra space.
  2. As the definition of \llap suggests, the equations using \llaps are only 0pt wide.

Is there any way to fix this bug? Or is there another way to achieve my initial goal?

2 Answers 2

3

It depends if you want “absolute” centering or with respect to the enumerate line width.

In either case you can use two boxes of half the desired width and add special glue in order that TeX doesn't try to fit the equation.

For “absolute” centering you need to move left by the left margin and use \textwidth:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\centersymbolalign}[2]{%
  \hspace{-\leftmargin}%
  \makebox[0.5\textwidth][r]{$\displaystyle#1{:}$}%
  \makebox[0.5\textwidth][l]{\quad$\displaystyle#2$}%
  \hspace{1000pt minus 1fil}%
}

\begin{document}

The set $G$, endowed with the binary operation $\circ$ (briefly, $(G,\circ)$, 
or simply $G$ if the operation can be understood) is a \emph{group} if

\begin{enumerate}
  \item the operation $\circ$ is \emph{associative},
  \[
    \centersymbolalign
      {(\forall\,g,\,h,\,k \in G)}
      {(g \circ h) \circ k = g \circ (h \circ k);}
  \]
  \item there exists an \emph{identity element} $e_G$ for $\circ$, that is,
  \[
    \centersymbolalign
      {(\exists e_G \in G)(\forall g \in G)}
      {g \circ e_G = g = e_G \circ g;}
  \]
  \item every element in $G$ has an \emph{inverse} with respect to $\circ$, that is,
  \[
    \centersymbolalign
      {(\forall g \in G)(\exists h \in G)}
      {g \circ h = e_G = h \circ g.}
  \]
\end{enumerate}

\noindent\makebox[\linewidth]{\smash{\vrule height 7cm width 0.1pt}}

\end{document}

The final rule is at the middle of the text width.

enter image description here

If you want to center with respect to the line width in the enumerate or, in general, the current line width, change into

\documentclass{article}
\usepackage{amsmath}

\newcommand{\centersymbolalign}[2]{%
  \hspace{0pt}%
  \makebox[0.5\linewidth][r]{$\displaystyle#1{:}$}%
  \makebox[0.5\linewidth][l]{\quad$\displaystyle#2$}%
  \hspace{1000pt minus 1fil}%
}

\begin{document}

The set $G$, endowed with the binary operation $\circ$ (briefly, $(G,\circ)$, 
or simply $G$ if the operation can be understood) is a \emph{group} if

\begin{enumerate}
  \item the operation $\circ$ is \emph{associative},
  \[
    \centersymbolalign
      {(\forall\,g,\,h,\,k \in G)}
      {(g \circ h) \circ k = g \circ (h \circ k);}
  \]
  \item there exists an \emph{identity element} $e_G$ for $\circ$, that is,
  \[
    \centersymbolalign
      {(\exists e_G \in G)(\forall g \in G)}
      {g \circ e_G = g = e_G \circ g;}
  \]
  \item every element in $G$ has an \emph{inverse} with respect to $\circ$, that is,
  \[
    \centersymbolalign
      {(\forall g \in G)(\exists h \in G)}
      {g \circ h = e_G = h \circ g.}
  \]

\item \makebox[\linewidth]{\smash{\vrule height 7cm width 0.1pt}}

\end{enumerate}

\end{document}

The rule is in the middle of the line width.

enter image description here

Beware that the definition, as written, is wrong. In the second condition, the variable eG is bound, so it cannot be used unbound in the third condition. I know that it's done so in almost every book, but if you really want to be fussy with logical symbols such as \forall and \exists, you must also be careful.

1

The following uses eqparbox to extract the widest element's width and use it to box the three separate elements of an alignment correctly.

\centersymbolalign now takes 3 arguments. First is the left-hand side of the equation, then the symbol and finally the right-hand side of the equation. An optional argument (called a <tag>) can be used if you have different blocks that need differing alignment within the same document.

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

\NewDocumentCommand{\centersymbolalign}{ O{csa} m m m }{%
  \eqmathbox[#1-l][r]{#2}% Left-hand side (right-aligned)
  \eqmathbox[#1-c][c]{#3}% Symbol (center-aligned)
  \eqmathbox[#1-r][l]{#4}% Right-hand side (left-aligned)
}

\begin{document}

\begin{itemize}
\item \textbf{normal equations}
\begin{enumerate}
  \item short short short short short
  \[
    (\forall\,g,\,h,\,k \in G):\quad(\forall\,g,\,h,\,k \in G);
  \]
  \item long long long long long long long long
  \[
    (\forall\,g,\,h,\,k \in G):\quad(\forall\,g,\,h,\,k \in G);
  \]
\end{enumerate}

\item \textbf{equations using} \verb|\eqmathbox|
\begin{enumerate}
  \item short short short short short
  \[
    \centersymbolalign{(\forall\,g,\,h,\,k \in G)}{:}{\quad(\forall\,g,\,h,\,k \in G);}
  \]
  \item long long long long long long long long
  \[
    \centersymbolalign{(\forall\,g,\,h,\,k \in G)}{:}{\quad(\forall\,g,\,h,\,k \in G);}
  \]
\end{enumerate}
\end{itemize}

The set~$G$, endowed with the binary operation~$\circ$ (briefly, $(G, \circ)$, or simply~$G$ if the operation can be understood)
is a \textbf{group} if
\begin{enumerate}
  \item
  the operation~$\circ$ is \textbf{associative}, that is,
  \[
    \centersymbolalign[group]{(\forall g, h, k \in G)}{:}{\quad (g \circ h) \circ k = g \circ (h \circ k);}
  \]
  
  \item
  there exists an \textbf{identity element}~$e_G$ for~$\circ$, that is,
  \[
    \centersymbolalign[group]{(\exists e_G \in G) (\forall g \in G)}{:}{\quad g \circ e_G = g = e_g \circ g;}
  \]
  
  \item
  every element in~$G$ has an \textbf{inverse} with respect to~$\circ$, that is,
  \[
    \centersymbolalign[group]{(\forall g \in G) (\exists h \in G)}{:}{\quad g \circ h = e_G = h \circ g.}
  \]
\end{enumerate}

\end{document}

The document needs at least two compilations with every change in the widest element within a particular <tag>

You must log in to answer this question.

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