1

I want to write something like:

\begin{enumerate}
  \item $f(x)=0\quad,\quad\forall{x}\in{S_1}$
  \item $g(x)=0\quad,\quad\forall{x}\in{S_2}}$
\end{enumerate}

and I want each line to be aligned at the comma (between the \quads). Is there any simple way to do this?


Because the above example was too simple, I present a part of the actual code:

\begin{enumerate}
\item 
$X\left(V\left(\varphi\right)\right)=\left\langle {{\operatorname{grad}}_{V}}\left(\varphi\right),X\left(\varphi\right)\right\rangle\quad,\quad\forall{X}\in{TM},\varphi\in{{C}^{\infty}}\left(M,W\right)$
\item ${{\operatorname{grad}}_{V}}\left(\rho\left(g\right)u\right)=\rho\left(g\right){{\operatorname{grad}}_{V}}\left(u\right)\quad,\quad\forall{u}\in{W},g\in{G}$
\item $\left\langle{\operatorname{grad}}_{V}\left(u\right),\rho_{*}\left(X\right)u\right\rangle=0\quad\quad\quad\quad\,,\quad\forall{u}\in{W},X\in{\mathfrak{g}}$
\end{enumerate}

As you can see I have "manually" aligned the commata, by inserting spaces with the appropriate length. Is there a simple way to align them automatically?

3

Here are two ways of achieving this:

enter image description here

\documentclass{article}

\usepackage{mathtools,eqparbox}

\begin{document}

\begin{enumerate}
  \item $f(x) = 0, \quad \forall x \in S_1$
  \item $g(x) = 0, \quad \forall x \in S_2$

  \bigskip

  \item $f(x) = 0, \quad \forall x \in S_1$
  \item $\phantom{f(x)}\mathllap{g(x)} = 0, \quad \forall x \in S_2$

  \bigskip

  \item $\eqmakebox[lhs]{$f(x)$} = 0, \quad \forall x \in S_1$
  \item $\eqmakebox[lhs][r]{$g(x)$} = 0, \quad \forall x \in S_2$
\end{enumerate}

\end{document}

(1) and (2) above is your original setup. We notice that f(x) is wider than g(x). As such, our focus will be only on moving g(x) to the right a smidge.

In (4) we insert a \phantom{f(x)} which puts us in the correct horizontal position, then insert g(x) in a math box with a left overlap (or \mathllap).

In (6) we insert both f(x) and g(x) inside an \eqmakebox with the same label (lhs). This ensures that they will take up the same space horizontally. Furthermore, we align g(x) to the r within the box.


Here is a more complex example using the same setup:

enter image description here

\documentclass{article}

\usepackage{mathtools,amsfonts,eqparbox}

\DeclareMathOperator{\grad}{grad}

\begin{document}

% Original setup
\begin{enumerate}
  \item 
  $X\left(V\left(\varphi\right)\right)=\left\langle {{\operatorname{grad}}_{V}}\left(\varphi\right),X\left(\varphi\right)\right\rangle\quad,\quad\forall{X}\in{TM},\varphi\in{{C}^{\infty}}\left(M,W\right)$
  \item ${{\operatorname{grad}}_{V}}\left(\rho\left(g\right)u\right)=\rho\left(g\right){{\operatorname{grad}}_{V}}\left(u\right)\quad,\quad\forall{u}\in{W},g\in{G}$
  \item $\left\langle{\operatorname{grad}}_{V}\left(u\right),\rho_{*}\left(X\right)u\right\rangle=0\quad\quad\quad\quad\,,\quad\forall{u}\in{W},X\in{\mathfrak{g}}$
\end{enumerate}

\bigskip

\begin{enumerate}
  \item
  $\phantom{\grad_V(\rho(g) u) = \rho(g) \grad_V(u)}
   \mathllap{X(V(\varphi)) = \langle \grad_V(\varphi), X(\varphi) \rangle}, \quad \forall X \in TM , \varphi \in C^\infty(M,W)$

  \item
  $\grad_V(\rho(g) u) = \rho(g) \grad_V(u), \quad \forall u \in W ,g \in G $

  \item
  $\phantom{\grad_V(\rho(g) u) = \rho(g) \grad_V(u)}
   \mathllap{\langle \grad_V(u), \rho_*(X) u \rangle = 0}, \quad \forall u \in W , X \in \mathfrak{g}$
\end{enumerate}

\bigskip

\begin{enumerate}
  \item
  \eqmakebox[lhs][r]{$X(V(\varphi)) = \langle \grad_V(\varphi), X(\varphi) \rangle$}%
  $, \quad \forall X \in TM , \varphi \in C^\infty(M,W)$

  \item
  \eqmakebox[lhs]{$\grad_V(\rho(g) u) = \rho(g) \grad_V(u)$}%
  $, \quad \forall u \in W ,g \in G $

  \item
  \eqmakebox[lhs][r]{$\langle \grad_V(u), \rho_*(X) u \rangle = 0$}%
  $, \quad \forall u \in W , X \in \mathfrak{g}$
\end{enumerate}

\end{document}
  • It works pretty well with my simple example but when I put in the real expressions (I also used [rhs]) the result didn't look that good. Is there any way to align at the commas, without using equation boxes? – user3257624 Dec 3 '16 at 14:47
  • @user3257624: There are many ways. Perhaps providing something that is a bit more relevant to your use-case would also help in guiding you. Please provide the community with a minimal working example (MWE) that shows us what you're talking about. – Werner Dec 3 '16 at 16:45
  • I have added to my original post part of the code I want to align – user3257624 Dec 3 '16 at 18:15
  • 1
    @user3257624: I've added your code to show how to achieve the alignment. Note how I've simplified the code, dropping most of your \left...\right combinations. – Werner Dec 4 '16 at 2:32
  • 1
    @user3257624: True; that's how you like things. I was somewhat suggestive in the way I would like things by not using \quad , \quad. You understand the approach though, which is essentially what I tried to convey. – Werner Dec 4 '16 at 17:15
2

Use the align environment from the amsmath package.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
   f(x)&=0\qquad\text{for all $x\in S_1$} \label{eq:f}\\
   g(x)&=0\qquad\text{for all $x\in S_2$} \label{eq:g}
\end{align}
See equations \ref{eq:f} and~\ref{eq:g}.
\end{document}

enter image description here

To have the numbers at the left margin, use the leqno option as a class option

\documentclass[leqno]{article}

or as a package option

\usepackage[leqno]{amsmath}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.