自定义数学命令的字体不会在下标和上标中调整大小

自定义数学命令的字体不会在下标和上标中调整大小

我的文档中有一种特定类型的符号,我想用不同的字体排版。因此,我定义了一个宏\tn来缩短它。经过几次尝试,我最终得到了 MWE 中显示的定义,这在大多数情况下都很好。但是当我\tn在下标或上标中使用时,符号的大小没有正确调整,方程式看起来不一致。

我需要改变的定义,\tn以便在下标和/或上标中使用时符号的大小一致。

谢谢,

平均能量损失

\documentclass{article}

\newcommand{\tn}[1]{\ensuremath\mbox{\boldmath$\mathsf{#1}$}}
\begin{document}
Good sizes \[h=\tn{A}+\tn{B}^2 + \hat{\tn{C}}\]

But the sizes are bad when superscripts or subscripts are involved
\[k=\underbrace{\hat{\tn{C}}}_{\hat{\tn{C}}}+\overbrace{\mathbf{u}}^{\mathbf{u}}+\tn{D}^{\tn{D}}
+\mathbf{v}^{\mathbf{v}}\]

Look how size of $\mathbf{u}$ and $\mathbf{v}$ is smaller in the superscripts, but $\tn{C}$ and $\tn{D}$ are the same. Even worse, the hat accent over $\hat{\tn{C}}$ is resized in the subscript, so it's not consistent
\end{document}

答案1

对于下标和上标位置的材料自动调整大小,请勿使用基本命令\mbox。(此处,“基本”表示“在 LaTeX 内核中定义”。)相反,请务必加载包amsmath并使用该\text命令。因此,宏的设置\tn应如下:

\newcommand{\tn}[1]{\text{\boldmath$\mathsf{#1}$}}

因为\tn似乎只在数学模式材料中使用,所以我也会省去\ensuremath包装器。

答案2

我认为这bm可能会有所帮助:

\documentclass{article}
\usepackage{amsmath}
\usepackage{bm}

\newcommand{\tn}[1]{\bm{\mathsf{#1}}}

\begin{document}

Good sizes (and $\mathsf{A}$ for comparison)
\[
h=\tn{A}+\tn{B}^2 + \hat{\tn{C}}
\]

But the sizes are bad when superscripts or subscripts are involved
\[k=\underbrace{\hat{\tn{C}}}_{\hat{\tn{C}}}+\overbrace{\mathbf{u}}^{\mathbf{u}}+\tn{D}^{\tn{D}}
+\mathbf{v}^{\mathbf{v}}\]

Look how size of $\mathbf{u}$ and $\mathbf{v}$ is smaller in the superscripts, but $\tn{C}$ and
$\tn{D}$ are the same. Even worse, the hat accent over $\hat{\tn{C}}$ is resized in the subscript, so
it's not consistent

\end{document}

在此处输入图片描述

如果您不缺少数学组,那么还有一个更清晰的解决方案:

\documentclass{article}
\usepackage{amsmath}

\DeclareMathAlphabet{\mathsfbf}{OT1}{\sfdefault}{bx}{n}

\newcommand{\tn}[1]{\mathsfbf{#1}}

\begin{document}

Good sizes (and $\mathsf{A}$ for comparison)
\[
h=\tn{A}+\tn{B}^2 + \hat{\tn{C}}
\]

But the sizes are bad when superscripts or subscripts are involved
\[k=\underbrace{\hat{\tn{C}}}_{\hat{\tn{C}}}+\overbrace{\mathbf{u}}^{\mathbf{u}}+\tn{D}^{\tn{D}}
+\mathbf{v}^{\mathbf{v}}\]

Look how size of $\mathbf{u}$ and $\mathbf{v}$ is smaller in the superscripts, but $\tn{C}$ and
$\tn{D}$ are the same. Even worse, the hat accent over $\hat{\tn{C}}$ is resized in the subscript, so
it's not consistent

\end{document}

输出是一样的。

相关内容