使用括号分组显示的方程式

使用括号分组显示的方程式

我想显示一个方程列表,并在左侧使用一些括号对方程进行分组。类似于下面的示例,每个括号左侧都有文本(垂直对齐),例如“无源”和“有源”,并且两个括号彼此对齐。此外,从语义上讲,最好使用单个环境而不是两个连续的环境来完成此操作。

我更倾向于使用尽可能标准的包/功能的解决方案,并且尽可能不临时,即使对齐并不完美。

(请不要对 div、rot 等的排版发表评论。我想到的应用程序与 Maxwell 无关!)

谢谢。

\documentclass{minimal}
\usepackage{empheq}
\begin{document}
Maxwell's equations:
\begin{empheq}[left=\empheqlbrace]{gather}
div B = 0 \tag{Thomson}\\
rot E + \frac{\partial B}{\partial t} = 0 \tag{Faraday}
\end{empheq}
\begin{empheq}[left=\empheqlbrace]{gather}
div E = \frac{\rho}{\epsilon_0} \tag{Gauss}\\
rot B - \frac1c^2 \frac{\partial E}{\partial t} = \mu_0 J \tag{Amp\`ere}
\end{empheq}
\end{document}

更新(2021-01-31):我接受了 Bernard 的回答,这很令人满意。我希望有一个环境可以写:

\begin{gather}
\begin{group}[\text{source-free }\left\{]
a = 0\\
b = 0  
\end{group}
\begin{group}[\text{with sources }\left\{]
c = 0\\
d = 0  
\end{group}
\end{gather}

(由于这两个组是相连的(两个左括号应该对齐),所以可能应该在“gather”环境级别传递一些选项)。

答案1

您可以使用eqparbox。要使用的标签对于要排版且宽度相同的框组应该是唯一的。

我更喜欢左对齐,\eqmath[c]{A}{...}如果您想要居中,请更改为。

\documentclass{article}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage{eqparbox}

\DeclareMathOperator{\Div}{div}
\DeclareMathOperator{\Rot}{rot}

\newcommand{\eqmath}[3][l]{%
  % #1 = alignment, default l, #2 = label, #2 = math material
  \eqmakebox[#2][#1]{$\displaystyle#3$}%
}

\begin{document}

Maxwell's equations:
\begin{empheq}[left=\empheqlbrace]{align}
&\eqmath{A}{\Div B = 0\vphantom{\Big|}} \tag{Thomson}\\
&\eqmath{A}{\Rot E + \frac{\partial B}{\partial t} = 0} \tag{Faraday}
\end{empheq}
\begin{empheq}[left=\empheqlbrace]{align}
&\eqmath{A}{\Div E = \frac{\rho}{\epsilon_0}} \tag{Gauss}\\
&\eqmath{A}{\Rot B - \frac{1}{c^2} \frac{\partial E}{\partial t} = \mu_0 J} \tag{Amp\`ere}
\end{empheq}
\end{document}

在此处输入图片描述

请注意,应该是

\frac{1}{c^2}

没错,确实\frac12有效,但是……

实际上,我宁愿不滥用\tag

\documentclass{article}
\usepackage{amsmath}
\usepackage{eqparbox}

\DeclareMathOperator{\Div}{div}
\DeclareMathOperator{\Rot}{rot}

\newcommand{\eqmath}[3][l]{%
  % #1 = alignment, default l, #2 = label, #2 = math material
  \eqmakebox[#2][#1]{$\displaystyle#3$}%
}
\newcommand{\eqtext}[3][l]{%
  % #1 = alignment, default l, #2 = label, #2 = text material
  \eqmakebox[#2][#1]{#3}%
}

\begin{document}

Maxwell's equations:
\begin{gather*}
\left\{\begin{alignedat}{2}
&\eqmath{B}{\Div B = 0\vphantom{\Big|}} &\quad&\eqtext{C}{(Thomson)}\\
&\eqmath{B}{\Rot E + \frac{\partial B}{\partial t} = 0} &&\eqtext{C}{(Faraday)}
\end{alignedat}\right.
\\[1ex]
\left\{\begin{alignedat}{2}
&\eqmath{B}{\Div E = \frac{\rho}{\epsilon_0}} &\quad&\eqtext{C}{(Gauss)}\\
&\eqmath{B}{\Rot B - \frac{1}{c^2} \frac{\partial E}{\partial t} = \mu_0 J} &&\eqtext{C}{(Amp\`ere)}
\end{alignedat}\right.
\end{gather*}

\end{document}

在此处输入图片描述

括号前带有标签,两种实现方式如下:

\documentclass{article}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage{eqparbox}

\DeclareMathOperator{\Div}{div}
\DeclareMathOperator{\Rot}{rot}

\newcommand{\eqmath}[3][l]{%
  % #1 = alignment, default l, #2 = label, #2 = math material
  \eqmakebox[#2][#1]{$\displaystyle#3$}%
}
\newcommand{\eqtext}[3][l]{%
  % #1 = alignment, default l, #2 = label, #2 = text material
  \eqmakebox[#2][#1]{#3}%
}

\begin{document}

\section{With empheq}

Maxwell's equations:
\begin{empheq}[left={\makebox[4em][r]{Source-free }\empheqlbrace}]{align}
&\eqmath{A}{\Div B = 0\vphantom{\Big|}} \tag{Thomson}\\
&\eqmath{A}{\Rot E + \frac{\partial B}{\partial t} = 0} \tag{Faraday}
\end{empheq}
\begin{empheq}[left={\makebox[4em][r]{With sources }\empheqlbrace}]{align}
&\eqmath{A}{\Div E = \frac{\rho}{\epsilon_0}} \tag{Gauss}\\
&\eqmath{A}{\Rot B - \frac{1}{c^2} \frac{\partial E}{\partial t} = \mu_0 J} \tag{Amp\`ere}
\end{empheq}

\section{No empheq}

Maxwell's equations:
\begin{gather*}
\eqtext[r]{1}{Source-free }
\left\{\begin{alignedat}{2}
&\eqmath{B}{\Div B = 0\vphantom{\Big|}} &\quad&\eqtext{C}{(Thomson)}\\
&\eqmath{B}{\Rot E + \frac{\partial B}{\partial t} = 0} &&\eqtext{C}{(Faraday)}
\end{alignedat}\right.
\\[1ex]
\eqtext[r]{1}{With sources }
\left\{\begin{alignedat}{2}
&\eqmath{B}{\Div E = \frac{\rho}{\epsilon_0}} &\quad&\eqtext{C}{(Gauss)}\\
&\eqmath{B}{\Rot B - \frac{1}{c^2} \frac{\partial E}{\partial t} = \mu_0 J} &&\eqtext{C}{(Amp\`ere)}
\end{alignedat}\right.
\end{gather*}

\end{document}

在此处输入图片描述

答案2

如果您不需要交叉引用方程式,您可以使用包bigdelim和来解决问题tabularx。我添加了esdiff包以便于输入偏导数,并cellspace为表格行添加一些垂直填充:

\documentclass{article}
\usepackage{esdiff, empheq}
\DeclareMathOperator{\Div}{div}
\DeclareMathOperator{\rot}{rot}
\usepackage{tabularx, bigdelim}
\usepackage[column=O]{cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}

\begin{document}

Maxwell's equations:

\noindent\begin{tabularx}{\textwidth}{@{}Xr @{}>{$\displaystyle}Ol<{$}>{\raggedleft\arraybackslash}X @{}}
 &\ldelim\{{3}{*}[Source-free~] & \Div B = 0 & \text{(Thomson)}\\
 & & \rot E + \diffp{B}{t} = 0 &\text{(Faraday)} \\ \strut \\
 &\ldelim\{{4}{*}[With sources~] & \Div E = \frac{\rho}{\epsilon} & \text{(Gauss)}\\
 & & \rot B - \frac1{c^2} \diffp{E}{t} = \mu_0 J &\text{(Ampère)}
\end{tabularx}

\end{document} 

在此处输入图片描述

答案3

这是我想出的解决方案,它并不完美:

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{cases}

\begin{document}
Maxwell's equations:


\begin{numcases}{source-free = }
    div B &= 0 \tag{Thompson} \\
    rot E + \frac{\partial B}{\partial t} &= 0 \tag{Faraday}
\end{numcases} 
\begin{numcases}{With sources  = }
    div E &= $\frac{\rho}{\epsilon}$ \tag{Gauss}\\
    rot B - \frac1c^2 \frac{\partial E}{\partial t} &= $\mu_0$ J \tag{Amp\`ere} 
\end{numcases}

\end{document}

答案4

使用最新版本nicematrix(2021-02-05 的 v. 5.10),您可以使用环境{NiceTabular*}并使用内置命令添加括号\SubMatrix。所有方程式都在同一环境中对齐。

\documentclass{article}
\usepackage{nicematrix}
\usepackage{esdiff}
\usepackage{lipsum}
\DeclareMathOperator{\Div}{div}
\DeclareMathOperator{\rot}{rot}

\NiceMatrixOptions{cell-space-limits=4pt}

\begin{document}

\lipsum[1]

Maxwell's equations:

\begingroup
\everymath{\displaystyle}
\noindent
\begin{NiceTabular*}{\textwidth}{r@{\qquad}l@{\extracolsep{\fill}}r@{}}
\Block{2-1}{\hspace{2cm}Source-free~}  
              & $\Div B = 0$                                  & (Thomson) \\
              & $\rot E + \diffp{B}{t} = 0$                   & (Faraday) \\ 
\strut \\
\Block{2-1}{With sources~} 
             & $\Div E = \frac{\rho}{\epsilon}$              & (Gauss) \\
             & $\rot B - \frac1{c^2} \diffp{E}{t} = \mu_0 J$ & (Ampère)
\CodeAfter
\SubMatrix\{{1-2}{2-2}.
\SubMatrix\{{4-2}{5-2}.
\end{NiceTabular*}
\endgroup

\end{document} 

您需要多次编译(因为nicematrix使用 PGF/Tikz 节点)。

上述代码的输出

相关内容