
我有許多簡短的方程,我想將它們分成兩列顯示。本質上:
A = B (1) || C = D (2)
E = F (3) || G = H (4)
我首先嘗試了flalign
環境(我更喜歡這個align
,但沒有必要),但我無法按照我想要的方式對方程式進行編號。環境align
將每一行視為一個方程式。
例子:
\documentclass{article}
\usepackage{mathtools}
\usepackage{amsmath}
\begin{document}
\begin{flalign}
A = & B & C = & D \\
E = & F & G = & H
\end{flalign}
\end{document}
另一種方法是一個簡單的multicolumn
環境,有強制的分欄:
\documentclass{article}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{multicol}
\begin{document}
\begin{multicols}{2}
\begin{align}
A = & B \\
E = & F
\end{align}
\columnbreak
\begin{align}
C = & D \\
G = & H
\end{align}
\end{multicols}
\end{document}
但存在多個問題:
- 方程式似乎在垂直方向上錯位
- 編號是垂直的而不是水平的(這對我來說是可以接受的)
我將不勝感激任何幫助。
答案1
我認為,如果您打算稍後引用方程,則應該只對它們進行編號,因此,根據這一理念,為什麼不定義一個既插入方程編號又製作標籤的宏:
\newcommand\Label[1]{&\refstepcounter{equation}(\theequation)\ltx@label{#1}&}
首先增加equation
計數器,列印它,然後使用一些技巧來製作標籤(當多個標籤出現在一行上時,amsmath 環境會列印錯誤訊息,我們需要迴避這一點)。因為@
這需要被包裹在裡面\makeatletter...\makeatother
。
&
可能不明智的是,我在巨集中包含了's ,因此隱含地假設它\Label
總是在align*
環境之類的東西中使用——請注意 ,*
因為您不希望環境給出額外的標籤。另一方面,需要付出一些額外的努力才能避免align*
錯誤(因為align*
抑制了方程式編號),因此該巨集在 ams 對齊環境之外無法運作。
使用這個巨集可以得到:
這是完整的程式碼:
\documentclass{article}
\usepackage{mathtools}
\usepackage{amsmath}
\makeatletter
\newcommand\Label[1]{&\refstepcounter{equation}(\theequation)\ltx@label{#1}&}
\makeatother
\begin{document}
\begin{align*}
A &= B \Label{one}& C &= D \Label{two}\\
E &= F \Label{three}& G &= H \Label{four}
\end{align*}
See equations \ref{one}, \ref{two}, \ref{three} and \ref{four}.
\end{document}
&
正如我上面所說,將兩者放在巨集中可能是不明智的,\Label
因為它隱藏了環境中的一些結構align*
,這最終可能會讓某人感到困惑。
flalign*
順便說一句,這對環境同樣有效。
答案2
我無法在答案中添加評論,因此我將其添加為對\Label
僅使用第一個字母有類似問題的其他任何人的答案。
\tmpLabel
我使用原語添加了一個虛擬變量\def
,以便它可以在\ltx@label
.
\makeatletter
\newcommand{\allignLabel}[1]{&\refstepcounter{equation}(\theequation)\def\tmplab{#1}\ltx@label\tmplab&}
\makeatother
我確信對此有一個更優雅的解決方案,因此請使用正確的解決方案評論或編輯此答案。