所以我想像这样缩进我的定理文本邮政但当我使用时\usepackage{hyperref}
,定理名称会移出文档框架。例如
\documentclass[
toc=chapterentrydotfill,
numbers=endperiod
]
{scrreprt}
\usepackage{hyperref}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{thmtools}
\usepackage{lipsum}
\swapnumbers
\makeatletter
\patchcmd\@thm
{\trivlist}
{\list{}{\leftmargin2.5em\itemindent-15em}}
{}{}
\newcommand{\xdeclaretheorem}[2][]{%
\declaretheorem[#1]{#2}%
\expandafter\patchcmd\csname thmt@original@end#2\endcsname
{\endtrivlist}{\endlist}{}{}%
}
\declaretheoremstyle[
headfont=\kern-2.5em\bfseries,
headpunct = {.},
notebraces = {[}{]},
bodyfont = \normalfont,
postheadspace = 5pt,
spacebelow = 5pt,
spaceabove = 5pt]{thms}
\xdeclaretheorem[style = thms, name = Theorem, numberwithin = chapter]{thm}
\xdeclaretheorem[style = thms, name = Lemma, sibling = thm]{lem}
\begin{document}
\chapter{Chapter}
\begin{lem}
\lipsum[1]
\end{lem}
\end{document}
输出
代替
第二张图片是与上面相同的代码,但删除了 hyperref 包。我该如何修复这个问题?
答案1
该hyperref
软件包会自行对进行修补\@thm
,因此我们需要在其之后延迟我们的修补。
\documentclass[
toc=chapterentrydotfill,
numbers=endperiod
]{scrreprt}
\usepackage{etoolbox}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{hyperref}
\usepackage{lipsum}
\swapnumbers
\makeatletter
\AtBeginDocument{% we need to wait after hyperref has done its own patching
\patchcmd\@thm
{\trivlist}
{\list{}{\leftmargin2.5em\itemindent-15em}}
{}{}%
}
\newcommand{\xdeclaretheorem}[2][]{%
\declaretheorem[#1]{#2}%
\expandafter\patchcmd\csname thmt@original@end#2\endcsname
{\endtrivlist}{\endlist}{}{}%
}
\declaretheoremstyle[
headfont=\kern-2.5em\bfseries,
headpunct = {.},
notebraces = {[}{]},
bodyfont = \normalfont,
postheadspace = 5pt,
spacebelow = 5pt,
spaceabove = 5pt]{thms}
\xdeclaretheorem[style = thms, name = Theorem, numberwithin = chapter]{thm}
\xdeclaretheorem[style = thms, name = Lemma, sibling = thm]{lem}
\begin{document}
\chapter{Chapter}
\begin{lem}\label{test}
\lipsum[1][1-4]
\end{lem}
\ref{test}
\end{document}