Reputation: 863
I am a beginner in latex.I have the following piece of latex code. The code is working fine but I want that all the equality operators of each equation should be aligned. How can it be done?
\begin{enumerate}
\item[Commutative] $a+b = b+a$
\item[Associative] $a+(b+c)=(a+b)+c$
\item[Distributive] $a(b+c)=ab+ac$
\end{enumerate}
Upvotes: 1
Views: 1633
Reputation: 15065
Using \eqmakebox[<tag>][<align>]
(from eqparbox
) you can have all elements under the same <tag>
be placed in a box of maximum width, together with individual <align>
ment as needed. Below I has \eqmakebox[LHS][r]
to ensure all elements tagged LHS
is r
ight-aligned. The result is alignment around the =
.
\documentclass{article}
\usepackage{eqparbox}
\begin{document}
\begin{enumerate}
\item[Commutative] $ a + b = b + a $
\item[Associative] $a + (b + c) = (a + b) + c$
\item[Distributive] $ a(b + c) = ab + ac $
\end{enumerate}
\begin{enumerate}
\item[Commutative] $ \eqmakebox[LHS][r]{$a + b$} = b + a $
\item[Associative] $\eqmakebox[LHS][r]{$a + (b + c)$} = (a + b) + c$
\item[Distributive] $ \eqmakebox[LHS][r]{$a(b + c)$} = ab + ac $
\end{enumerate}
\end{document}
Alternatively you can measure the widest element yourself:
\newlength{\widestelement}
\settowidth{\widestelement}{$a + (b + c)$}
and then use
\begin{enumerate}
\item[Commutative] $ \makebox[\widestelement][r]{$a + b$} = b + a $
\item[Associative] $\makebox[\widestelement][r]{$a + (b + c)$} = (a + b) + c$
\item[Distributive] $ \makebox[\widestelement][r]{$a(b + c)$} = ab + ac $
\end{enumerate}
Upvotes: 1
Reputation: 1362
I'm unsure if this is possible inside the enumerate
environment. An easy alternative is to use a tabular
environment instead. In the example below the left and right sides of the equation are contained in two separate columns, with an =
appearing between them.
\documentclass[12pt]{article}
\begin{document}
\begin{tabular}{l r@{$=$}l}
Commutative & $a+b$ & $b+a$ \\
Associative & $a+(b+c)$ & $(a+b)+c$ \\
Distributive & $a(b+c)$ & $ab+ac$ \\
\end{tabular}
\end{document}
Upvotes: 2