![在案例環境中垂直對齊變數](https://rvso.com/image/281574/%E5%9C%A8%E6%A1%88%E4%BE%8B%E7%92%B0%E5%A2%83%E4%B8%AD%E5%9E%82%E7%9B%B4%E5%B0%8D%E9%BD%8A%E8%AE%8A%E6%95%B8.png)
我正在 LaTeX 中建立一個方程組,使用一個cases
環境,變數為 $x_1$、$x_2$、$x_3$ 和 $x_4$。這是我的 MWE:
\documentclass[a4paper,12pt,onecolumn]{article}
\usepackage{amsmath}
\begin{document}
\begin{math}
\begin{cases}
x_1 + x_2 + x_3 + x_4 = 3\\
- 3x_2 + x_3 - 2x_4 = -3\\
2x_3 + 5x_4 = -3\\
- 7x_4 = -7
\end{cases}
\end{math}
\end{document}
我想保持變數在輸出中垂直對齊,就像它們出現在上面的原始程式碼中一樣。我怎樣才能做到這一點?
答案1
該cases
環境可能不是實現您目的的最佳工具。您可能想考慮使用系統包和相關的巨集\systeme
。
以下範例說明了該巨集的用法。我應用的唯一手動調整是第一個方程中的 RHS 項,我在其中添加了一項\phantom{-}
來調整對齊方式。
\documentclass[a4paper,12pt,onecolumn]{article}
\usepackage{systeme}
\begin{document}
\begin{math}
\systeme{
x_1 + x_2 + x_3 + x_4 = \phantom{-}3,
- 3x_2 + x_3 - 2x_4 = -3,
2x_3 + 5x_4 = -3,
- 7x_4 = -7}
\end{math}
\end{document}
附錄: 前面的樣子可以實際上是透過一個cases
環境來實現的,如下:
\begin{math}
\begin{cases}
\hfill x_1 + \phantom{2}x_2 + \phantom{2}x_3 + \phantom{2}x_4 = \phantom{-}3\\
\hfill {}- 3x_2 + \phantom{2}x_3 - 2x_4 = -3\\
\hfill 2x_3 + 5x_4 = -3\\
\hfill {}- 7x_4 = -7
\end{cases}
\end{math}
然而,與使用套件時所需的工作相比systeme
,需要四個\hfill
指令、三個額外\phantom
指令和兩個{}
空組才能完成工作。我想每個人都會同意這systeme
是完成這項工作的更好的工具...