2

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

Thanks to Steven B. Segletes, who proposed a brilliant solution to the space problem mentioned above (see this separate question), I can now post a version that works to my satisfaction:

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

A theorem body does not apply a paragraph indentation automatically, instead \indent needs to be added manually within the body of such an environment. This, hoewever, may be even desired, if, for example, two definitions that are closley related are placed within a single paragraph.

Addendum

This is how a typical double page looks like. The page format is DIN A4. The binding correction is 12 mm.

double page wtih margin captions

  • Does anybody see any possible side effects or other drawbacks of this approach? – Matthias Nov 2 '17 at 14:11

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.