当名称很长时,即使标记的名称不会与内容重叠,方程式的居中也会偏离。如何将名称较长的方程式居中?
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
1 &= 1\\
2 &= 2\tag{This is a long tag}\\
3 &= 3
\end{align*}
\end{document}
从下图中,我们可以看到有足够的空间让方程式与文档居中并且不会重叠。
答案1
一个选项是使用 ; 等来隐藏标签宽度\makebox
,在Dequation
环境中,标签宽度将不予考虑:
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newenvironment{Dequation}
{%
\def\tagform@##1{%
\maketag@@@{\makebox[0pt][r]{(\ignorespaces##1\unskip\@@italiccorr)}}}%
\ignorespaces
}
{%
\def\tagform@##1{\maketag@@@{(\ignorespaces##1\unskip\@@italiccorr)}}%
\ignorespacesafterend
}
\makeatother
\begin{document}
A regular \texttt{align*} with long tags:
\begin{align*}
1 &= 1\\
2 &= 2\tag{This is a long tag}\\
3 &= 3\tag{This is an even longer tag}
\end{align*}
A regular \texttt{align*} without tags, for comparison:
\begin{align*}
1 &= 1\\
2 &= 2\\
3 &= 3
\end{align*}
An \texttt{align*} with long tags inside \texttt{Dequation}:
\begin{Dequation}
\begin{align*}
1 &= 1\\
2 &= 2\tag{This is a long tag}\\
3 &= 3\tag{This is an even longer tag}
\end{align*}
\end{Dequation}
The initial regular \texttt{align*} with long tags, for comparison:
\begin{align*}
1 &= 1\\
2 &= 2\tag{This is a long tag}\\
3 &= 3\tag{This is an even longer tag}
\end{align*}
\end{document}
答案2
您可以在另一侧添加最长的标签,以\phantom
“恢复”水平偏移:
\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
1 &= 1 \\
2 &= 2 \\
3 &= 3
\end{align*}
\begin{align*}
1 &= 1 \\
2 &= 2 \tag{This is a long tag} \\
3 &= 3
\end{align*}
\begin{align*}
1 &= 1 \\
\phantom{\text{(This is a long tag)}}2 &= 2 \tag{This is a long tag} \\
3 &= 3
\end{align*}
\end{document}