對齊環境中的多行右側

對齊環境中的多行右側

考慮工作範例:

\documentclass{article}
\usepackage{amsmath}


\begin{document}
    \begin{align*}
        (a+b)^2 &= a^2 + 2ab + b^2\\
        (a-b)^2 &= a^2 - 2ab + b^2
    \end{align*}
\end{document}

}我需要的是在右側繪製,覆蓋兩條線,然後是一些文字。該圖像代表了我想要的(以紅色顯示)。

我不知道如何開始(所以,沒有我嘗試過的程式碼)。

答案1

您有兩個主要選項:(a)array環境,以及 (b)rcases環境;後者由數學工具包裹。如下圖所示,它們產生相同的結果水平的佈局。如果你仔細觀察,rcases會發現選項的行距比選項的行間距要寬一些array。垂直間距的增加可能符合您的喜好,也可能不符合您的喜好。

事實上,由於使用aligned環境來封裝方程,第三種選擇也可用: (c) 不要使用arrayrcases--\left. \blurb \right\}就足夠了。非常感謝唐納德·阿瑟諾在評論中指出這一點。

在此輸入影像描述

對於目前的情況(雙關語),使用rcases環境可能有點矯枉過正,因為測試程式碼沒有利用環境的許多功能。

如果您需要將「sum」一詞排版為紅色,請務必 (i)xcolor在序言中載入套件並 (ii) 變更\text{sum}\text{\color{red}sum}。如果右側花括號也需要呈現為紅色,則不能使用rcases解決方案(“選項 B”),並且需要鍵入\color{red}\right\}\text{\color{red}sum}​​。

\documentclass{article}
\usepackage{mathtools} % for 'rcases' environment
\newcommand\blurb{% 
% material that's common to all three options:
    \begin{aligned}
        (a+b)^2 &= a^2 + 2ab + b^2\\
        (a-b)^2 &= a^2 - 2ab + b^2
    \end{aligned}
}
    
\begin{document}
\begin{align*}
%% Option A: 'array' environment
    \left. \begin{array}{@{}c@{}}
       \blurb
    \end{array} \right\}
    &\text{sum} 
    \\[1ex]
%% Option B: 'rcases' environment
    \begin{rcases}
       \blurb
    \end{rcases}
    &\text{sum}
    \\[1ex]
%% Option C: no encasing environment
    \left. 
       \blurb
    \right\}
    &\text{sum} 
\end{align*}
\end{document}

答案2

還有另一種簡短的方式,使用empheq(載入mathtools):

\documentclass{article}
\usepackage{empheq}
\usepackage[svgnames]{xcolor} 

\begin{document}

    \begin{empheq}[right=\color{Coral}\empheqrbrace \textsf{sum}]{align*}
        (a+b)^2 &= a^2 + 2ab + b^2\\
        (a-b)^2 &= a^2 - 2ab + b^2
    \end{empheq}

\end{document} 

在此輸入影像描述

相關內容