![在每个 \newtheorem 之前和之后添加一个 latex 代码](https://linux22.com/image/466049/%E5%9C%A8%E6%AF%8F%E4%B8%AA%20%5Cnewtheorem%20%E4%B9%8B%E5%89%8D%E5%92%8C%E4%B9%8B%E5%90%8E%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%20latex%20%E4%BB%A3%E7%A0%81.png)
我使用 定义了几个定理amsthm
,\newtheorem
我想hrule
为每个定理添加前缀和后缀。目前我使用
\AddToHook{env/〈env name〉/before}{hrule code}
和
\AddToHook{env/〈env name〉/after}{hrule code}
对每一个\newtheorem
。
有什么想法可以让我的代码更紧凑,以便我AddToHook
只声明一次 s,而不是每次定义新note
样式环境时都声明它?
\documentclass{book}
\usepackage{amsthm}
\newtheoremstyle{note}% 〈name〉
{3pt}% 〈Space above〉
{3pt}% 〈Space below 〉
{}% 〈Body font〉
{}% 〈Indent amount〉
{\itshape}% 〈Theorem head font〉
{:}% 〈Punctuation after theorem head 〉
{.5em}% 〈Space after theorem head 〉3
{}% 〈Theorem head spec (can be left empty, meaning ‘normal’ )
\theoremstyle{note}
\newtheorem{theorem}{Theorem}
\AddToHook{env/theorem/before}{\par\vspace{\baselineskip}\hrule}
\AddToHook{env/theorem/after}{\hrule\vspace{\baselineskip}}
\newtheorem{definition}{Definition}[chapter]
\AddToHook{env/definition/before}{\vspace{\baselineskip}\par\hrule} % same Hook as above
\AddToHook{env/definition/after}{\hrule\vspace{\baselineskip}}
\newtheorem{remark}{Remark}[chapter]
\AddToHook{env/remark/before}{\vspace{\baselineskip}\par\hrule} % Those two hooks again
\AddToHook{env/remark/after}{\hrule\vspace{\baselineskip}}
\begin{document}
Some theorems, definitions and remarks appear here.
\end{document}
我知道thmtools
及其preheadhook
和postfoothook
键。但我只想使用amsthm
。
答案1
您可以使用合适的宏轻松实现该效果。
\newcommand*\newtushtheorem[1]{%
\AddToHook{env/#1/before}{\par\vspace{\baselineskip}\hrule}%
\AddToHook{env/#1/after}{\hrule\vspace{\baselineskip}}%
\newtheorem{#1}%
}
\newtushtheorem{theorem}{Theorem}
\newtushtheorem{definition}{Definition}[chapter]
\newtushtheorem{remark}{Remark}[chapter]
然而,正如评论请注意,这种添加规则的方式可能并不总是按照首选方式运行。