答案1
下面的例子用基本的 TeX 方法实现了线条,两个框和两条线。注释中解释了这个过程。
\documentclass{article}
\usepackage{siunitx}
\makeatletter
\newcommand*{\NegationLike}[1]{%
\mathop{%
\mathpalette\@NegationLike{#1}%
}%
% A little space is added automatically,
% if a math ord atom follows.
}
\newdimen\BarLineWidth
\newcommand*{\@NegationLike}[2]{%
% #1: math style
% #2: argument
\vbox{%
% The rule thickness of \overline or \underline
% is available in the font dimen register 8
% of the math family 3 of the current size.
\BarLineWidth=%
\the\fontdimen8%
\ifx\displaystyle#1\textfont
\else\ifx\textstyle#1\textfont
\else\ifx\scriptstyle#1\scriptfont
\else\scriptscriptfont
\fi\fi\fi
3\relax
% The rule at the top
\hrule height\BarLineWidth
% Move the box with the vertical line
% as height as the top of the upper line
% to get a better corner.
\kern-\BarLineWidth
% First save the formula in a box.
% Then the height can be manipulated
% later for the space between the
% formula and the upper line.
\sbox0{%
% The formula (#2) in the current math style (#1)
% without additional space around the formula (\m@th).
$#1#2\m@th$%
% A little space before the right line, adjust
% to your taste.
\kern2\BarLineWidth
% The vertical line automatically stretches with
% the height and depth of the box.
\vrule width\BarLineWidth
}%
% Increase the height of the box to get
% some space between the formula and the upper line.
% TeX uses three \BarLineWidth in \overline and
% \underline. The fourth \BarLineWidth compensates
% the negative kerning from above.
\ht0=\dimexpr\ht0 + 4\BarLineWidth
% Output the box.
\copy0 %
}%
}
\makeatother
\begin{document}
\[
Rs_{\,\NegationLike{14-(-1)}\SI{1.5}{\percent}}(1 + \SI{1.5}{\percent})
\]
\end{document}
如果公式低于一条线(分数的分母、根等),TeX 将使用狭窄样式。狭窄样式意味着 TeX 会尝试降低高度,例如,如果有上标。可以通过
\cramped
包中的宏强制执行mathtools
:
\RequirePackage{mathtools}
\makeatletter
\newcommand*{\NegationLike}[1]{%
\mathop{%
\mathpalette\@NegationLike{#1}%
}%
}
\newdimen\BarLineWidth
\newcommand*{\@NegationLike}[2]{%
\vbox{%
\BarLineWidth=%
\the\fontdimen8%
\ifx\displaystyle#1\textfont
\else\ifx\textstyle#1\textfont
\else\ifx\scriptstyle#1\scriptfont
\else\scriptscriptfont
\fi\fi\fi
3\relax
\hrule height\BarLineWidth
\kern-\BarLineWidth
\sbox0{%
$\cramped[#1]{#2}\m@th$%
\kern2\BarLineWidth
\vrule width\BarLineWidth
}%
\ht0=\dimexpr\ht0 + 4\BarLineWidth
\copy0 %
}%
}
\makeatother
替代方案:软件包actuarialangle
\documentclass{article}
\usepackage{siunitx}
\usepackage{actuarialangle}
\begin{document}
\[
Rs_{\angl{14-(-1)}\SI{1.5}{\percent}}(1 + \SI{1.5}{\percent})
\]
\end{document}
包裹stix
该包定义了一个数学重音\annuity
,但适用于单个符号,而不是更大的表达式,因此改变了示例:
\documentclass{article}
\usepackage{siunitx}
\usepackage{stix}
\begin{document}
\[
Rs_{\,\annuity{n}\;\SI{1.5}{\percent}}(1 + \SI{1.5}{\percent})
\]
\end{document}