0

I thought my previous problem on placing names, numbers and notes of theorems in the margin column had been solved.

In fact, the code proposed in my answer works as expected:

\documentclass[fontsize=11pt, paper=a4, DIV=classic]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{xpatch}
\usepackage{ragged2e}
\usepackage{changepage}
\usepackage{blindtext}

\KOMAoption{mpinclude}{true}
\recalctypearea
\setlength{\marginparsep}{2em}
\setlength{\marginparwidth}{10em}

\makeatletter

\newcommand{\RaggedOuter}%
{%
  \if@twoside%
    \checkoddpage%
    \ifoddpage%
      \RaggedRight%
    \else%
      \RaggedLeft%
    \fi%
  \else%
    \RaggedRight%
  \fi%
}

\newcommand{\cl@ThmMarginCaption}%
{
  \leavevmode%
  \marginpar%
  {%
    \RaggedOuter%
    \hbadness=10000%
    \the\thm@headfont\thmt@thmname~\thechapter.\arabic{\thmt@envname}\\%
    \the\thm@notefont\thmt@optarg%
  }%
}

\declaretheoremstyle%
[%
  spaceabove={\parskip},%
  spacebelow=0pt,%
  headindent=0pt,%
  postheadspace=0pt,%
  headformat={},%
  headpunct={},%
  headfont=\sffamily\bfseries\small,%
  notefont=\rmfamily\mdseries\small,%
  bodyfont=\normalfont,%
  preheadhook={},%
  postheadhook={\cl@ThmMarginCaption},%
]%
{thmmcaption}

\newcommand{\DeclareTheorem}[2][]%
{%
  \declaretheorem[#1]{#2}%
  \expandafter\let\csname cl@orig@#2\expandafter\endcsname\csname#2\endcsname%
  \expandafter\let\csname cl@orig@end#2\expandafter\endcsname\csname end#2\endcsname%
  \renewenvironment{#2}[1][]%
    {\csname cl@orig@#2\endcsname[##1]\ignorespaces}%
    {\csname cl@orig@end#2\endcsname}%
}

\DeclareTheorem[name=Definition, numberwithin=chapter, style=thmmcaption]{definition}
\DeclareTheorem[name=Satz,       numberwithin=chapter, style=thmmcaption]{theorem}

\makeatother


\begin{document}

\chapter{Theorems with margin captions}

\blindtext

\begin{definition}[Kellerautomat (KA)\\pushdown automaton (PDA)]
Eine ganz wichtige Definition, die natürlich länger als eine Zeile sein sollte, um sehen zu können, ob alles funktioniert wie gewünscht.
\end{definition}

\blindtext

\clearpage

\blindtext

\begin{theorem}[Satz von Radó]
Die Radó-Funktion ist nicht berechenbar.
\end{theorem}

\blindtext

\end{document}

The margin note containing the theorem information is placed at the desired position.

Correct position of the margin note

As soon as I started mixing this solution with other code, the option strict for package changepage became mandatory. Using this option, the margin note gets shifted down, as you can see here.

Wrong position of the margin note

Adding % at the end of each line of changepage.sty when it was not present did not help at all.

Why does the option strict have an effect on my definition of \RaggedOuter?

Matthias
  • 1,956

1 Answers1

1

Use the strict form in horizontal mode so it does not force a change in linespacing, also beware misusing %

\documentclass[fontsize=11pt, paper=a4, DIV=classic]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{xpatch}
\usepackage{ragged2e}
\usepackage[strict]{changepage}
\usepackage{blindtext}

\KOMAoption{mpinclude}{true}
\recalctypearea
\setlength{\marginparsep}{2em}
\setlength{\marginparwidth}{10em}

\makeatletter

\newcommand{\RaggedOuter}
{%
  \if@twoside
    \leavevmode\checkoddpage
    \ifoddpage
      \RaggedRight
    \else
      \RaggedLeft
    \fi
  \else
    \RaggedRight
  \fi
  \ignorespaces}

\newcommand{\cl@ThmMarginCaption}
{
  \leavevmode
  \marginpar
  {%
    \RaggedOuter
    \hbadness=10000
    \the\thm@headfont\thmt@thmname~\thechapter.\arabic{\thmt@envname}\\%
    \the\thm@notefont\thmt@optarg
  }%
}

\declaretheoremstyle
[
  spaceabove={\parskip},
  spacebelow=0pt,
  headindent=0pt,
  postheadspace=0pt,
  headformat={},
  headpunct={},
  headfont=\sffamily\bfseries\small,
  notefont=\rmfamily\mdseries\small,
  bodyfont=\normalfont,
  preheadhook={},
  postheadhook={\cl@ThmMarginCaption},
]
{thmmcaption}

\newcommand{\DeclareTheorem}[2][]
{%
  \declaretheorem[#1]{#2}%
  \expandafter\let\csname cl@orig@#2\expandafter\endcsname\csname#2\endcsname
  \expandafter\let\csname cl@orig@end#2\expandafter\endcsname\csname end#2\endcsname
  \renewenvironment{#2}[1][]%
    {\csname cl@orig@#2\endcsname[##1]\ignorespaces}
    {\csname cl@orig@end#2\endcsname}
}

\DeclareTheorem[name=Definition, numberwithin=chapter, style=thmmcaption]{definition}
\DeclareTheorem[name=Satz,       numberwithin=chapter, style=thmmcaption]{theorem}

\makeatother


\begin{document}

\chapter{Theorems with margin captions}

\blindtext

\begin{definition}[Kellerautomat (KA)\\pushdown automaton (PDA)]
Eine ganz wichtige Definition, die natürlich länger als eine Zeile sein sollte, um sehen zu können, ob alles funktioniert wie gewünscht.
\end{definition}

\blindtext

\clearpage

\blindtext

\begin{theorem}[Satz von Radó]
Die Radó-Funktion ist nicht berechenbar.
\end{theorem}

\blindtext

\end{document}
David Carlisle
  • 757,742
  • Thank you so much for your quick replay. You saved my day (more precisely, my night). By the way, what is the general rule when to use % at the end of a line in the definition of a command and when not? – Matthias Nov 02 '17 at 21:06
  • @Matthias an end of line is a space, so you just need an end of line if you want a space ir comment it out if you don't. After a \foo spaces are ignored so most of your % were harmless but did nothing at all, but you need a space to terminate the numeric literal 10000 so having the % there is a bad idea, in this case it just meant that \the\thm@headfont was expanded before \hbadness was set not afterwards but you can get lots of strange bugs by changing the expansion order in that way. – David Carlisle Nov 02 '17 at 21:12
  • Thanks again for your help and your patience with me. Though I studied computer science (some time ago) I guess I will never be able to know what really happens "inside" TeX and LaTeX. Good to know that at least some people do ... ;-) – Matthias Nov 02 '17 at 21:16