3

So I want to indent my theorem text like on this post but when I use \usepackage{hyperref}, the theorem name gets shifted out of the document frame. E.g.

\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}

outputs

enter image description here

instead of

enter image description here

The second picture is the same code as above, but with the hyperref package removed. How do I fix this?

2
  • 1
    Welcome on SE, @HannaBloom! In the above MWE there is no hyperref command. Could you include it? Because the position of this command within the document is relevant.
    – tanGIS
    Jun 19 '20 at 20:13
  • @tanGIS thanks! it was all the way at the top Jun 19 '20 at 20:36
2

The hyperref package does its own patching to \@thm, so we need to delay ours after it.

\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}

enter image description here

1
  • that's awesome, thanks! Jun 19 '20 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.