我使用下面给出的代码使用 thmtools 创建定理框,但出现错误:Package thmtools Error: \declaretheorem key `headformat' not known
。
根据thmtools
文档,headformat
是 的有效参数declaretheoremstyle
。所以我不明白错误是什么。请帮忙。
\documentclass[11pt]{book}
%% boxed theorems
\usepackage{thmtools}
\usepackage{etoolbox}
\declaretheoremstyle[numberwithin=chapter,
shaded={rulecolor=black!50, textwidth=0.95\linewidth, margin=0.8em, rulewidth=1pt, bgcolor={rgb}{0.9,0.9,0.9}},
headformat={\NAME~\NUMBER\hfill\NOTE\smallskip\linebreak}
]{sthm}
\declaretheorem[style=sthm]{hypothesis}
\begin{document}
\begin{hypothesis}[hypothesis name]
Some hypothesis
\end{hypothesis}
\end{document}
答案1
正如评论中提到的,您需要加载xcolor
和amsthm
。我还添加了,headpunct={}
因为大概您不希望在行首出现一个杂散的句号。
\documentclass[11pt]{book}
%% boxed theorems
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{etoolbox}
\declaretheoremstyle[numberwithin=chapter,
shaded={rulecolor=black!50, textwidth=0.95\linewidth, margin=0.8em, rulewidth=1pt, bgcolor={rgb}{0.9,0.9,0.9}},
headformat={\NAME~\NUMBER\hfill\NOTE\smallskip\linebreak},
headpunct={}
]{sthm}
\declaretheorem[style=sthm]{hypothesis}
\begin{document}
\begin{hypothesis}
Some hypothesis
\end{hypothesis}
\begin{hypothesis}[hypothesis name]
Some hypothesis
\end{hypothesis}
\end{document}