在案例環境中垂直對齊變數

在案例環境中垂直對齊變數

我正在 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是完成這項工作的更好的工具...

相關內容