我如何对齐如下所示的数组,以便它们从距纸张左边缘相同的距离开始?
\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{itemize}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\[\begin{array}{l}
a + b = c \\
a + c = b \\
a + b = c
\end{array}\]
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem \[ a + b + c + d + e + f = g \]
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\[\begin{array}{l}
a = x \\
a + b = y \\
a + b + c = z
\end{array}\]
\end{itemize}
\end{document}
答案1
您flalign
可以使用flalign*
amsmath 包要缩进方程式,只需在每个环境的第一行留出适当大小的空格即可。
\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\newcommand{\myindent}{\hspace*{2cm}}
\begin{document}
\begin{itemize}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\begin{flalign*}
\myindent & a + b = c & \\
& a + c = b & \\
& a + b = c &
\end{flalign*}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem
\begin{flalign*}
\myindent & a + b + c + d + e + f = g &
\end{flalign*}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\begin{flalign*}
\myindent & a = x & \\
& a + b = y & \\
& a + b + c = z &
\end{flalign*}
\end{itemize}
\end{document}
定义一个新环境,自动\myindent
在 中插入flalign
,这种做法amsmath
往往以失败告终(参见amsmath 技术说明了解详情)。
答案2
虽然 Ian Thompson 回答了关于在左侧对齐方程式的问题,但通常对齐方程式的方式是在等号上。下面我展示了两种不同的方法(使用array
最初设置的方法和使用包align
中的环境amsmath
):
- 使用
\hphantom{}
来添加适当量的水平空间。 - 使用
\makebox{<size>}{<text>}
在适当的空间中设置给定的文本。
笔记:
- 包裹
calc
提供\widthof
宏来计算所使用的长度,以便在适当的空间内\FitInBox
以正确的方式排列等式左边。r
全部产生类似的结果:
代码:
\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}% provides the align environment
\usepackage{calc}% for the \widthof macro
\begin{document}
Using \verb|array| along with \verb|\hphantom{}|:
\begin{itemize}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\[\begin{array}{r@{}l}
\hphantom{{}+c+d+e+f} a + c &{}= b \\
a + c &{}= b \\
a + b &{}= c
\end{array}\]
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem
\[ a + b + c + d + e + f = g \]
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\[\begin{array}{r@{}l}
a &{}= x \\
\hphantom{{}+c+d+e+f} a + b &{}= y \\
a + b + c &{}= z
\end{array}\]
\end{itemize}
\hrule\medskip
Using \verb|align| from the \verb|amsmath| package with \verb|\hphantom{}|:
\begin{itemize}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\begin{align*}
\hphantom{{}+c+d+e+f} a + b &= c \\
a + c &= b \\
a + b &= c
\end{align*}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem
\[ a + b + c + d + e + f = g \]
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\begin{align*}
a &= x \\
\hphantom{{}+c+d+e+f} a + b &= y \\
a + b + c &= z
\end{align*}
\end{itemize}
\newpage
\newcommand*{\WidestLeftHandSide}{$a + b + c + d + e + f$}
\newcommand*{\FitInBox}[1]{\makebox[\widthof{\WidestLeftHandSide}][r]{$#1$}}%
Using \verb|align| from the \verb|amsmath| package with \verb|\makebox{}|:
\begin{itemize}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\begin{align*}
\FitInBox{a + b} &= c \\
a + c &= b \\
a + b &= c
\end{align*}
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem
\[ a + b + c + d + e + f = g \]
\item Lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit lorem ipsum dolor sit l
\begin{align*}
\FitInBox{a} &= x \\
a + b &= y \\
a + b + c &= z
\end{align*}
\end{itemize}
\end{document}