答案1
是的,这是可能的:
\documentclass{article}
\usepackage{amsmath,array}
\begin{document}
\begin{equation*}
\renewcommand{\arraystretch}{1.2}
\setlength{\arraycolsep}{0pt}
\begin{array}{
>{\displaystyle}r % right aligned
>{\displaystyle{}}l % left aligned
@{\hspace{4em}} % spacing
| % vertical rule
@{\hspace{2em}} % spacing
>{\displaystyle}r % comments
}
2x+2 &= 7x+3 & -2 \\
2x &= 7x+1 & -7x \\
-5x &= 1 & \div(-5) \\
x &= \boxed{-\frac{1}{5}} & \\
\end{array}
\end{equation*}
\end{document}
如果您对间距感到满意,您可以将其变成环境:
\documentclass{article}
\usepackage{amsmath,array}
\newenvironment{solve}
{%
\renewcommand{\arraystretch}{1.2}%
\setlength{\arraycolsep}{0pt}%
\begin{array}{
>{\displaystyle}r % right aligned
>{\displaystyle{}}l % left aligned
@{\hspace{4em}} % spacing
| % vertical rule
@{\hspace{2em}} % spacing
>{\displaystyle}r % comments
}%
}%
{\end{array}}
\begin{document}
\begin{equation*}
\begin{solve}
2x+2 &= 7x+3 & -2 \\
2x &= 7x+1 & -7x \\
-5x &= 1 & \div(-5) \\
x &= \boxed{-\frac{1}{5}} & \\
\end{solve}
\end{equation*}
\end{document}
答案2
使用不同的格式似乎更好,这样您可以更轻松地控制序列内的编号元素(如果需要)。
\documentclass{article}
\usepackage{amsmath}
\newcommand{\eqcomment}[1]{& \triangleright~ & #1}
\begin{document}
\begin{align*}
2x + 2 &= 7x + 3 \eqcomment{-2} \\
2x &= 7x + 1 \eqcomment{-7x} \\
-5x &= 1 \eqcomment{\div(-5)} \\
x &= \boxed{-\frac{1}{5}}
\end{align*}
\end{document}
人们可以尝试各种对齐和符号。
答案3
另外两种可能性:
\documentclass{article}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}
\usepackage{eqparbox}
\usepackage{amsmath,array}
\begin{document}
\begin{flalign*}
\qquad & & 2x+2 &= 7x+3 &\smash{\rule[-4.5\baselineskip]{0.5pt}{5.5\baselineskip}} \quad\eqmakebox[B][r]{$ -2 $} & \\
& & 2x &= 7x+1 &\eqmakebox[B][r]{$ -7x $}& \\
& & -5x &= 1 & \eqmakebox[B][r]{$ \div(-5) $} & \\
& & x &= \boxed{-\frac{1}{5}} & &
\end{flalign*}
\begin{alignat*}{2}
\qquad2x+2 &= 7x+3 &\hspace{6em}\smash{\rule[-5\baselineskip]{0.5pt}{6\baselineskip}} \qquad-2 & \\
2x &= 7x+1 & -7 x & \\
-5x &= 1 &\div(-5) & \\
x &= \boxed{-\frac{1}{5}} & &
\end{alignat*}
\end{document}