请考虑以下示例:
\documentclass{article}
\usepackage{mathtools}
\usepackage[amsmath]{empheq}
\usepackage{xcolor}
\definecolor{shadecolor}{cmyk}{0,0,0.45,0}
\definecolor{light-blue}{cmyk}{0.25,0,0,0}
\newsavebox{\mysaveboxM}
\newsavebox{\mysaveboxT}
\newcommand*\Yellowbox[2][Formel]{%
\sbox{\mysaveboxM}{#2}
\sbox{\mysaveboxT}{\fcolorbox{black}{light-blue}{#1}}
\sbox{\mysaveboxM}{%
\parbox[b][\ht\mysaveboxM+0.4\ht\mysaveboxT+0.8\dp\mysaveboxT][b]{%
\wd\mysaveboxM}{#2}
}
\sbox{\mysaveboxM}{%
\fcolorbox{black}{shadecolor}{%
\makebox[\linewidth]{\usebox{\mysaveboxM}}%
}%
}%
\usebox{\mysaveboxM}%
\makebox[0pt][r]{%
\makebox[\wd\mysaveboxM][c]{%
\raisebox{\ht\mysaveboxM-0.5\ht\mysaveboxT
+0.5\dp\mysaveboxT-0.5\fboxrule}{\usebox{\mysaveboxT}}
}
}
}
\begin{document}
\begin{empheq}[box={\Yellowbox[Inverse $3 \times 3$ matrix]}]{equation*}
\textsf{A}^{-1}
= \frac{1}{a(ei-fh)+b(fg-di)+c(dh-eg)}
\begin{pmatrix}
ei-fh & ch-bi & bf-ce\\
fg-di & ai-cg & cd-af\\
dh-eg & bg-ah & ae-bd
\end{pmatrix}
\end{empheq}
\end{document}
为什么盒子里的内容没有水平居中?
PS 我从empheq
手动的并做了一些修改。
更新
我感觉有些事情已经改变,empheq
因为我以前使用过上述代码,没有任何问题。
答案1
您在 的定义中有几个不受保护的行尾\Yellowbox
;您还有一个过满的盒子,因为您没有考虑\fboxsep
和\fboxrule
。
\documentclass{article}
\usepackage{mathtools}
\usepackage[amsmath]{empheq}
\usepackage{calc}
\usepackage{xcolor}
\definecolor{shadecolor}{cmyk}{0,0,0.45,0}
\definecolor{light-blue}{cmyk}{0.25,0,0,0}
\newsavebox{\mysaveboxM}
\newsavebox{\mysaveboxT}
\newcommand*\Yellowbox[2][Formel]{%
\sbox{\mysaveboxM}{#2}%
\sbox{\mysaveboxT}{\fcolorbox{black}{light-blue}{#1}}%
\sbox{\mysaveboxM}{%
\parbox[b][\ht\mysaveboxM+0.4\ht\mysaveboxT+0.8\dp\mysaveboxT][b]{%
\wd\mysaveboxM}{#2}%
}
\sbox{\mysaveboxM}{%
\fcolorbox{black}{shadecolor}{%
\makebox[\displaywidth-2\fboxsep-2\fboxrule]{\usebox{\mysaveboxM}}%
}%
}%
\usebox{\mysaveboxM}%
\makebox[0pt][r]{%
\makebox[\wd\mysaveboxM][c]{%
\raisebox{\ht\mysaveboxM-0.5\ht\mysaveboxT
+0.5\dp\mysaveboxT-0.5\fboxrule}{\usebox{\mysaveboxT}}%
}%
}%
}
\begin{document}
\noindent X\hrulefill X\par
\begin{empheq}[box={\Yellowbox[Inverse $3 \times 3$ matrix]}]{equation*}
\textsf{A}^{-1}
= \frac{1}{a(ei-fh)+b(fg-di)+c(dh-eg)}
\begin{pmatrix}
ei-fh & ch-bi & bf-ce\\
fg-di & ai-cg & cd-af\\
dh-eg & bg-ah & ae-bd
\end{pmatrix}
\end{empheq}
\end{document}
右侧的空间显然比左侧的空间大,这是因为大括号(和pmatrix
)留出了更多空间。可能应该使用\displaywidth
,而不是。\linewidth