用 tikz 的 matrix 模块给一种方法(在这种情况下它并非是最优解)
\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{equation}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\matrix [matrix of math nodes, nodes={anchor=east},]{
\frac{1}{\sqrt{2}}y_1 & - & \frac{1}{\sqrt{2}}y_2 & & = & f_1\\
\frac{1}{\sqrt{2}}y_1 & + & \frac{1}{\sqrt{2}}y_2 & & = & f_2\\
& \textcolor{red}{+} & \frac{1}{\sqrt{2}}y_2 & + \,y_3 & = & f_3\\
& \textcolor{red}{+} & -\frac{1}{\sqrt{2}}y_2 & & = & f_4\\
\frac{1}{\sqrt{2}}y_1 & & & - \,y_3 & = & f_5\\
-\frac{1}{\sqrt{2}}y_1 & & & & = & f_6\\
};
\end{tikzpicture}
\end{equation}
\begin{equation}
a + b =c
\end{equation}
\end{document}
结果如下
其中 [baseline=(current bounding box.center)]
是为了使 matrix 的公式编号垂直居中。
以上使用的是 equation 环境的自动编号,如果想使用手动编号,只需在 tikzpicture 环境后添加\tag{...}
.
该方法对于公式中不同行列等间距输出的情况不是最优解,而对于行列不等间距的情况是比较方便的(因为 matrix 模块可以轻松指定 row sep, column sep
或者在 &
和 \\
后添加增量距离来实现改变行列间距)。
问 排版「多个对齐位点」带标号公式的最佳实践?