以下输出看起来太密集了。你能让它在垂直和水平方向上都更松散一些吗?
平均能量损失
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{amsmath,xcolor}
\let\temp\underbrace
\def\underbrace#1_#2{{\color{red}\temp{{\color{black}#1}}_{#2}}}
\begin{document}
$\displaystyle
\begin{aligned}
x^2+6x+10
&= \underbrace{x^2}_{a^2} \underbrace{+2x (3)}_{+2ab} + 10\\
&= \underbrace{x^2}_{a^2} \underbrace{+2x (3)}_{+2ab} \underbrace{+(3)^2 -(3)^2}_{+b^2-b^2} +10\\
&= \underbrace{x^2+2x(3)+(3)^2}_{a^2+2ab+b^2} -(3)^2 +10\\
&= \underbrace{(x+3)^2}_{(a+b)^2} -9 +10\\
&= (x+3)^2+1
\end{aligned}
$
\end{document}
我们随时欢迎任何建设性的建议、意见、想法等!
答案1
我会用\mathstrut
它来涵盖最常见的避免幻影的情况;也比数学模式\textcolor
更好。\color
您需要{}
在前面添加+
以获得合适的间距。我还添加了几个细空格来分隔括号。
\documentclass[border=12pt,12pt]{standalone}
\usepackage{amsmath,xcolor}
\let\latexunderbrace\underbrace
\def\underbrace#1_#2{%
{\,\textcolor{red}{\latexunderbrace{\textcolor{black}{\mathstrut#1}}_{#2}}\,}%
}
\begin{document}
$\displaystyle
\begin{aligned}
x^2+6x+10
&= \underbrace{x^2}_{a^2} \underbrace{{}+2x (3)}_{+2ab} + 10\\
&= \underbrace{x^2}_{a^2} \underbrace{{}+2x (3)}_{+2ab} \underbrace{+(3)^2 -(3)^2}_{+b^2-b^2} +10\\
&= \underbrace{x^2+2x(3)+(3)^2}_{a^2+2ab+b^2} -(3)^2 +10\\
&= \underbrace{(x+3)^2}_{(a+b)^2} -9 +10\\
&= (x+3)^2+1
\end{aligned}
$
\end{document}
略微好一点的版本,删除了 + 前面的空格
\documentclass[border=12pt,12pt]{standalone}
\usepackage{amsmath,xcolor}
\let\latexunderbrace\underbrace
\def\underbrace#1_#2{%
{\,\textcolor{red}{\latexunderbrace{\textcolor{black}{\mathstrut#1}}_{#2}}\,}%
}
\newcommand{\hplus}{{\mspace{-\medmuskip}}+}
\begin{document}
$\displaystyle
\begin{aligned}
x^2+6x+10
&= \underbrace{x^2}_{a^2} \underbrace{\hplus 2x (3)}_{+2ab} + 10\\
&= \underbrace{x^2}_{a^2} \underbrace{\hplus2x (3)}_{+2ab} \underbrace{+(3)^2 -(3)^2}_{+b^2-b^2} +10\\
&= \underbrace{x^2+2x(3)+(3)^2}_{a^2+2ab+b^2} -(3)^2 +10\\
&= \underbrace{(x+3)^2}_{(a+b)^2} -9 +10\\
&= (x+3)^2+1
\end{aligned}
$
\end{document}
答案2
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{amsmath,xcolor}
\let\temp\underbrace
\def\underbrace#1_#2{{\color{red}\temp{{\color{black}{\strut}#1{}}}_{#2}}}
\begin{document}
$\displaystyle
\openup1\jot
\begin{aligned}
x^2+6x+10
&= \underbrace{x^2}_{a^2} \underbrace{+2x (3)}_{+2ab} + 10\\
&= \underbrace{x^2}_{a^2} \underbrace{+2x (3)}_{+2ab} \underbrace{+(3)^2 -(3)^2}_{+b^2-b^2} +10\\
&= \underbrace{x^2+2x(3)+(3)^2}_{a^2+2ab+b^2} -(3)^2 +10\\
&= \underbrace{(x+3)^2}_{(a+b)^2} -9 +10\\
&= (x+3)^2+1
\end{aligned}
$
\end{document}
{}
因此 + 获得中缀间距,添加后\strut
括号就都处于相同的深度,并且添加后\openup
行距会稍微增加。