microtype/ntheorem:突出不影响定理的标题

microtype/ntheorem:突出不影响定理的标题

我正在尝试切换到 ntheorem包(而不是amsthm),但我意识到定理的标题没有突出: Whatever.

\documentclass{article}
\usepackage[activate={true, nocompatibility}, factor=2000]{microtype}
\usepackage{ntheorem}
\usepackage[showframe]{geometry}

\makeatletter
\newtheoremstyle{mystyle}
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]}
\makeatother

\theoremstyle{mystyle}
\theorembodyfont{\upshape}
\theoremseparator{.}
\newtheorem{what}{Whatever}

\begin{document}
    \noindent\bfseries Whatever.\normalfont

    \begin{what}
        Something here.\newline
        Whatever.
    \end{what}
\end{document}

我试过了并使\theorem@headerfont\protrudeleft{##1}凸出正确 - 但它也会产生一些错误并影响定理的格式。那么我应该如何修复它?提前感谢您的帮助。

答案1

您尝试使用的另一个答案中的代码的问题在于,此处的拆箱发生在另一个(不兼容的)盒子内,这会导致 tex 出错。正如您在评论中所建议的那样,解决方案是先测量突出部分,然后从标签 sep 中减去它:

\documentclass{article}
\usepackage[activate={true, nocompatibility}, factor=2000]{microtype}
\usepackage{ntheorem}
\usepackage[showframe]{geometry}

\makeatletter
\makeatletter
\newcommand*\protrudeleft[1]{%
    {\everypar{}%
     \setbox\z@\vbox{\noindent#1}%
     \vbadness=\@M
     \splittopskip=\z@
     \global\setbox\z@=\vsplit\z@ to \baselineskip
     \unvbox\z@ \global\setbox\z@=\lastbox
    }%
    \@tempdima=\leftmarginkern\z@ 
}
\newtheoremstyle{mystyle}
{\protrudeleft{\theorem@headerfont ##1}%% measure left margin kern
 \item[\hskip\dimexpr\labelsep+\@tempdima %% add to labelsep
 \theorem@headerfont ##1\ ##2\theorem@separator]}
{\protrudeleft{\theorem@headerfont ##1}%
 \item[\hskip\dimexpr\labelsep+\@tempdima 
 \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]}
\makeatother

\theoremstyle{mystyle}
\theorembodyfont{\upshape}
\theoremseparator{.}
\newtheorem{what}{Whatever}

\begin{document}
    \noindent\bfseries Whatever.\normalfont

    \begin{what}
        Something here.\newline
        Whatever.
    \end{what}
\end{document}

相关内容