My question is related to Theorem Name/Numbering in Margin and Theorem name and number in margin, note in text , but the answers to these previous questions do not fully solve my problem.
I use package amsthm.
I would like to achieve that theorem name, number and note appear in the margin column, ragged left on left pages and ragged right on right pages.
Here is my current attempt.
\documentclass[fontsize=11pt, paper=a4, DIV=classic]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsthm}
\usepackage{ragged2e}
\usepackage{blindtext}
\KOMAoption{headinclude}{false}
\KOMAoption{footinclude}{false}
\KOMAoption{mpinclude}{true}
\recalctypearea
\setlength{\marginparsep}{2em}
\setlength{\marginparwidth}{10em}
% \RaggedOuter means
% (1) \RaggedRight in one-side mode
% (2) \RaggedLeft on left pages in two-side mode
% (3) \RaggedRight on right pages in two-side mode
\let\RaggedOuter\RaggedRight
% Must be called immediately after opening a float environment
% in order to adjust \RaggedOuter and listing line numbers
\newcommand{\setOddEvenPageLayout}%
{%
\if@twoside%
\ifthispageodd{\let\RaggedOuter\RaggedRight}{\let\RaggedOuter\RaggedLeft}%
\fi%
}
\newtheoremstyle{thmmargin} %
{0pt} % space above
{0pt} % space below
{\normalfont\normalsize} % body font
{0pt} % indent
{\sffamily\bfseries\small} % headfont
{} % punctuation
{\parindent} % space after head
{ % theorem head spec
\setOddEvenPageLayout%
\llap%
{%
\begin{minipage}[t]{\marginparwidth}%
\RaggedOuter\hbadness=10000%
#1~#2\\[.2ex]\normalfont{}#3%
\end{minipage}%
\hspace{\marginparsep}%
}%
}
\theoremstyle{thmmargin}
\newtheorem{definition}{Definition}[chapter]
\newtheorem{theorem}{Satz}[chapter]
\begin{document}
\chapter{Theorems with margin captions}
\blindtext
\begin{definition}[Kellerautomat (KA)\\ pushdown automaton (PDA)]
\blindtext
\end{definition}
\blindtext
\clearpage
\blindtext
\begin{theorem}[Satz von Radó]
Die Radó-Funktion ist nicht berechenbar.
\end{theorem}
\blindtext
\end{document}
There are various problems with this approach:
- The body of the theorem does not float beside the minipage.
- The indent is a little larger than
\parindent. - If a theorem body spans less lines than its description (name, number, note) in the margin par, empty lines are caused. Instead, the next paragraph should just continue without caring about the over-hanging margin note.
- There is no mechanism implemented yet to get the margin note positioned correctly on right sides.
I think I need a completely different approach, but I ran out of ideas how to tackle the issue. Hoewever, I would like to stay with amsthm if possible.
Edit (02-Nov-2017 01:20)
I have made some progress using thmtools. This package allows me to use \marginpar{} in preheadhook or postheadhook. However, the vertical positioning of the margin note is wrong, and the body of the theorem does not start a new paragraph as desired. Furthermore, the key numberwithin is not yet evaluated, but the formatting of the number is hard-coded.
\documentclass[fontsize=11pt, paper=a4, DIV=classic]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsthm}
\usepackage{thmtools}
\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%
}
\makeatother
\declaretheoremstyle[%
spaceabove=0pt,%
spacebelow=0pt,%
headindent=0pt,%
postheadspace=0pt,%
headfont=\sffamily\bfseries\small,%
notefont=\rmfamily\mdseries\small,%
bodyfont=\normalfont,%
preheadhook={},%
headformat={},%
headpunct={},%
postheadhook={\marginpar{\RaggedOuter\the\thm@headfont\thmt@thmname~\thechapter.\arabic{\thmt@envname}\\\the\thm@notefont\thmt@optarg}},%
numberwithin=chapter%
]{thmmargcapt}
\declaretheorem[style=thmmargcapt, name=Definition]{definition}
\declaretheorem[style=thmmargcapt, name=Satz]{theorem}
\begin{document}
\chapter{Theorems with margin captions}
\blindtext
\begin{definition}[Kellerautomat (KA)\\ pushdown automaton (PDA)]
Eine ganz wichtige Definition.
\end{definition}
\blindtext
\clearpage
\blindtext
\begin{theorem}[Satz von Radó]
Die Radó-Funktion ist nicht berechenbar.
\end{theorem}
\blindtext
\end{document}
