ntheorem - 章节开头的缩进

ntheorem - 章节开头的缩进

我正在使用该类编写文档book,该类在设计上不会缩进章节/部分/小节的第一行。我注意到,如果我以框架定理开始一章,那么出于某种原因,首行\noindent 会推迟到定理之后的第一行。如果我改用非框架定理,则不会发生同样的情况。这是一个 mwe:

\documentclass[oneside]{book}
\usepackage{framed}
\usepackage[framed]{ntheorem}

\newframedtheorem{theorem}{theorem}
\newtheorem{plainthm}{theorem}

\begin{document}
    
\section{section}
\begin{theorem}
    This is a theorem
\end{theorem}

some text

\begin{theorem}
    this is another theorem
\end{theorem}

some other text

\section{other section}
\begin{plainthm}
    This is a plainthm
\end{plainthm}

some text

\begin{plainthm}
    this is another plainthm
\end{plainthm}

some other text
\end{document}

这是输出: 输出

虽然这似乎不是一个很重要的问题(我怀疑我是否会以定理开始一个部分),但我想了解为什么会发生这种情况(我猜这与框架定理是在框内绘制的事实有关)以及解决这个问题的“正确”方法是什么。我可以想到几种解决方法(例如\vskip在框架定理之前添加一条虚线和一个负数),但我对更灵活的解决方案感兴趣(例如,在我更改文档类时不会破坏的东西)。

答案1

由于对框架定理存在所有可能的保留,尤其是 提供的丑陋格式ntheorem,您需要确保\if@afterindent设置为 true。

tcolorbox对于这类工作,我建议看一下。

章节标题之后的环境theorem会将条件设置为真,但由于它是在环境内部完成的,因此设置不会超出\end{theorem}

\documentclass[oneside]{book}
\usepackage{framed}
\usepackage[framed]{ntheorem}
%\usepackage{etoolbox} % with an older LaTeX version

\newframedtheorem{theorem}{theorem}
\newtheorem{plainthm}{theorem}

\makeatletter
\AfterEndEnvironment{theorem}{\@afterindenttrue}
\makeatother


\begin{document}
    
\section{section}
\begin{theorem}
    This is a theorem
\end{theorem}

some text

\begin{theorem}
    this is another theorem
\end{theorem}

some other text

\section{other section}
\begin{plainthm}
    This is a plainthm
\end{plainthm}

some text

\begin{plainthm}
    this is another plainthm
\end{plainthm}

some other text
\end{document}

在此处输入图片描述

答案2

\leavevmode只需在环境结束后添加:

\documentclass[oneside]{book}
\usepackage{framed}
\usepackage[framed]{ntheorem}
\newframedtheorem{theorem}{theorem}
\newtheorem{plainthm}{theorem}

\begin{document}

\section{section}
\begin{theorem}
    This is a theorem
\end{theorem}\leavevmode

some text

\begin{theorem}
    this is another theorem
\end{theorem}

some other text

\section{other section}
\begin{plainthm}
    This is a plainthm
\end{plainthm}

some text

\begin{plainthm}
    this is another plainthm
\end{plainthm}

some other text

\end{document} 

在此处输入图片描述

相关内容