![如何将“显示的方程式”中的符号对齐到中心?](https://linux22.com/image/456293/%E5%A6%82%E4%BD%95%E5%B0%86%E2%80%9C%E6%98%BE%E7%A4%BA%E7%9A%84%E6%96%B9%E7%A8%8B%E5%BC%8F%E2%80%9D%E4%B8%AD%E7%9A%84%E7%AC%A6%E5%8F%B7%E5%AF%B9%E9%BD%90%E5%88%B0%E4%B8%AD%E5%BF%83%EF%BC%9F.png)
目标
我想对齐一些方程式用枚举项分隔,其中:
s 对齐。下图就是一个例子。
由于这些方程之间存在枚举项,因此可能不容易适应使用\intertext
或的解决方案breqn
来解决我的问题。
我的尝试
\llap
我尝试使用和定义一个命令\rlap
,并且它几乎完美地运行:
\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}
然而,当等式上方的行短于一半时,这会导致一个错误\textwidth
:文本和“显示的等式”之间的额外空间消失了。
\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}
我认为有两个原因造成:
- LaTeX 可以巧妙地管理这些额外空间。当显示的公式框的左端位于上一行末尾的右侧时,就不需要这些额外空间了。
- 作为定义
\llap
表明,使用 s 的方程式\llap
仅很0pt
宽。
有什么方法可以修复此错误?或者还有其他方法可以实现我的初始目标吗?
答案1
这取决于您是否想要“绝对”居中或相对于enumerate
线宽。
无论哪种情况,您都可以使用两个所需宽度一半的盒子并添加特殊胶水,以便 TeX 不会尝试拟合方程。
对于“绝对”居中,您需要按左边距向左移动并使用\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}
最后一条规则位于文本宽度的中间。
如果要根据枚举中的线宽或当前线宽居中,请更改为
\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}
规则位于线宽的中间。
请注意,所写的定义是错误的。在第二种情况下,变量埃G是绑定的,所以在第三种情况下不能不绑定使用。我知道几乎每本书都是这样写的,但如果你真的想对诸如\forall
和 之类的逻辑符号吹毛求疵\exists
,你也必须小心。
答案2
以下用途eqparbox
提取最宽元素的宽度并用它来正确地框住对齐的三个独立元素。
\centersymbolalign
现在需要 3 个参数。第一个是等式的左边,然后是符号,最后是等式的右边。<tag>
如果同一文档中有不同的块需要不同的对齐方式,则可以使用可选参数(称为 a )。
\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}
文档至少需要两次编译,每次修改特定范围内最宽元素<tag>