- 在解释方程的各部分时,我将术语分组放在一个数组中,并对
\underbrace
各个部分添加解释 - 每个下括号内的第一个项是分数 (
\frac
),但与没有下括号部分的项相比,其字体太大(见图)
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[largesmallcaps]{kpfonts}
\usepackage[sf,scale=0.9]{merriweather}
\usepackage{mathtools}
\usepackage{bm}
\begin{document}
\begin{equation}
\begin{array}{lllll}
-\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{x} & +\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{\mu}_1 & +\frac{1}{2} \bm{\mu}_1^T \Sigma^{-1} \bm{x} & -\frac{1}{2} \bm{\mu}_1^T \Sigma^{-1} \bm{\mu}_1 & \\
\underbrace{+\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{x}}_{\mathclap{\text{cancel}}} & \underbrace{-\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{\mu}_2}_{\mathclap{\bm{x}^T \bm{w}\text{, but without} \frac{1}{2}}} & \underbrace{-\frac{1}{2} \bm{\mu}_2^T \Sigma^{-1} \bm{x}}_{\mathclap{\text{?}}} & \underbrace{+\frac{1}{2} \bm{\mu}_2^T \Sigma^{-1} \bm{\mu}_2 + \log \frac{p(C_1)}{p(C_2)}}_{\mathclap{\bm{w}_0}} \\
\end{array}
\end{equation}
\end{document}
答案1
\underbrace
无条件应用\displaystyle
。使用两个参数似乎更符合标准语法。所以我提供了一个命令\ubrace{<math material>}{<subscript>}
。它可以改变\underbrace
自身,但最好不要这样做。
这是代码。我还对设置进行了一些改进。特别是,我将列间距减小到 1pt,添加空原子以提供正确的间距,并粉碎一些东西以使括号和下标垂直对齐。
\documentclass{article}
%\usepackage[utf8]{inputenc} % no longer necessary
\usepackage[largesmallcaps]{kpfonts}
\usepackage[sf,scale=0.9]{merriweather}
\usepackage{mathtools}
\usepackage{bm}
\usepackage{array}
\makeatletter
\newcommand{\ubrace}[2]{\mathord{\mathpalette\ubrace@{{#1}{#2}}}}
\newcommand{\ubrace@}[2]{\ubrace@@#1#2}
\newcommand{\ubrace@@}[3]{% #1=style, #2=math to be underbraced, #3=subscript
\underbrace{#1#2}_{#3}%
}
\makeatother
\begin{document}
\begin{equation}
\setlength{\arraycolsep}{1pt}
\begin{array}{@{} *{4}{l} @{} }
-\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{x} &
{}+\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{\mu}_1 &
{}+\frac{1}{2} \bm{\mu}_1^T \Sigma^{-1} \bm{x} &
{}-\frac{1}{2} \bm{\mu}_1^T \Sigma^{-1} \bm{\mu}_1
\\[2ex]
\ubrace{+\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{x}}
{\text{\smash{cancel}}} &
\ubrace{{}-\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{\mu}_2}
{\smash[t]{\mathclap{\bm{x}^T \bm{w}\text{, but without} \frac{1}{2}}}} &
\ubrace{{}-\frac{1}{2} \bm{\mu}_2^T \Sigma^{-1} \bm{x}}
{\text{?}} &
\ubrace{{}+\frac{1}{2} \bm{\mu}_2^T \Sigma^{-1} \bm{\mu}_2 +
\log \smash[b]{\frac{p(C_1)}{p(C_2)}}}
{\bm{w}_0}
\end{array}
\end{equation}
\end{document}
答案2
这个怎么样?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[largesmallcaps]{kpfonts}
\usepackage[sf,scale=0.9]{merriweather}
\usepackage{mathtools}
\usepackage{bm}
\begin{document}
\begin{equation}
\begin{array}{lllll}
-\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{x} & +\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{\mu}_1 & +\frac{1}{2} \bm{\mu}_1^T \Sigma^{-1} \bm{x} & -\frac{1}{2} \bm{\mu}_1^T \Sigma^{-1} \bm{\mu}_1 & \\
\underbrace{+\textstyle\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{x}}_{\mathclap{\text{cancel}}} & \underbrace{\textstyle-\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{\mu}_2}_{\mathclap{\bm{x}^T \bm{w}\text{, but without} \frac{1}{2}}} & \underbrace{\textstyle-\frac{1}{2} \bm{\mu}_2^T \Sigma^{-1} \bm{x}}_{\mathclap{\text{?}}} & \underbrace{\textstyle+\frac{1}{2} \bm{\mu}_2^T \Sigma^{-1} \bm{\mu}_2 + \log \textstyle\frac{p(C_1)}{p(C_2)}}_{\mathclap{\bm{w}_0}}
\end{array}
\end{equation}
\end{document}
答案3
我将抓住机会,不仅在第二行生成显示样式的分数,而且在第一行也生成显示样式的分数,方法是将\frac
第一行中的四个指令切换为\dfrac
。(但是,如果所有 8 个\frac{1}{2}
项必须使用 textstyle 而不是 displaystyle,只需在第二行使用\tfrac
而不是 即可。\frac
我还会 (a) 确保下支撑彼此对齐,以及 (b) 在指令的帮助下增加行之间的垂直间距\addlinespace
。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[largesmallcaps]{kpfonts}
\usepackage[sf,scale=0.9]{merriweather}
\usepackage{booktabs} % for \addlinespace macro
\usepackage{mathtools,bm}
% define 2 typographic struts:
\newcommand\mystruta{\vphantom{\frac{p(C_1)}{p(C_2)}}}
\newcommand\mystrutb{\vphantom{\frac{1}{2}}}
\begin{document}
\begin{equation}
\begin{matrix*}[l]
-\dfrac{1}{2} \bm{x}^T \Sigma^{-1} \bm{x} &
+\dfrac{1}{2} \bm{x}^T \Sigma^{-1} \bm{\mu}_1 &
+\dfrac{1}{2} \bm{\mu}_1^T \Sigma^{-1} \bm{x} &
-\dfrac{1}{2} \bm{\mu}_1^T \Sigma^{-1} \bm{\mu}_1 \\
\addlinespace
\underbrace{+\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{x}\mystruta}%
_{\text{cancel}\mystrutb} &
\underbrace{-\frac{1}{2} \bm{x}^T \Sigma^{-1} \bm{\mu}_2\mystruta}%
_{\mathclap{\bm{x}^T\bm{w}\text{, but without} \frac{1}{2}}} &
\underbrace{-\frac{1}{2} \bm{\mu}_2^T \Sigma^{-1} \bm{x}\mystruta}%
_{\text{?}\mystrutb} &
\underbrace{+\frac{1}{2} \bm{\mu}_2^T \Sigma^{-1} \bm{\mu}_2 + \log \frac{p(C_1)}{p(C_2)}}%
_{\mathclap{\bm{w}_0}\mystrutb}
\end{matrix*}
\end{equation}
\end{document}