[英]align latex equations
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}
I'm unsure if this is possible inside the enumerate
environment. 我不确定在
enumerate
环境中是否可以这样做。 An easy alternative is to use a tabular
environment instead. 一个简单的替代方法是使用
tabular
环境。 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}
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. 使用
\\eqmakebox[<tag>][<align>]
(来自eqparbox
),您可以将同一<tag>
下的所有元素放在最大宽度的框中,并根据需要与单个<align>
一起放置。 Below I has \\eqmakebox[LHS][r]
to ensure all elements tagged LHS
is r
ight-aligned. 下面我有
\\eqmakebox[LHS][r]
以确保所有元素标记LHS
是r
飞行对齐。 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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.