[Tex/LaTex] Theorem Name/Numbering in Margin

marginspositioningtheorems

I have seen the previous discussion on this same issue before (see Theorem name and number in margin, note in text), however this did not resolve anything as clearly as I had hoped.

Basically, I would like to have a visible margin (i.e:- a vertical line) on the left hand side of the page. Within the margin, I would like the section numbers (but not the name), equations numbers, theorem names and their respective numbers, but I am a bit a newbie in LaTeX and am I unsure how to go about doing this.

An example with the symbol "|" denoting the position of the margin would be:

                3.1. | Continuous Groups
                     |
      Definition 3.1 | Lie Group:.....
             (3.1.1.)| [SOME EQUATION HERE]
      Definition 3.2 | Lie Algebra:....

Thank you in advance.

Just some points of clarification (updated, based on the comments)
1. The document is one-sided, so only the left-hand side margin is of relevance.
2. Any suggestions on which theorem packages will be more suitable are welcome.

Best Answer

I think the following does what you want.

screenshot

The packages I have used are

  • esopic to add the gray vertical bar to the margin
  • titlesec to customize the section numbers using \llap
  • ntheorem to create a customized definition environment- you could equivalently use amsthm, but I'm more familiar with ntheorem

I've borrowed some code/ideas from

Code:

   % arara: pdflatex
% !arara: indent: {overwrite: on}
\documentclass{report}

\usepackage{xcolor}                 % to have colors 
\usepackage{eso-pic}                % put things into background 
\usepackage{lipsum}                 % for sample text
\usepackage{titlesec}     % for customizing sections
\usepackage[leqno]{amsmath}         % for mathematical content
\usepackage[amsmath]{ntheorem}      % for theorem-like environments

% customize the tag form of the equations
\makeatletter
\let\mytagform@=\tagform@
\def\tagform@#1{\maketag@@@{\hbox{\llap{(\ignorespaces#1\unskip\@@italiccorr)\hspace{1mm}}}}\kern1sp}
\renewcommand{\eqref}[1]{{\mytagform@{\ref{#1}}}}
\makeatother

% customize section
\titleformat{\section}%
{\Large\bfseries}% format
{\llap{% label
    \thesection\hskip 9pt}}%
{0pt}% horizontal sep
{}% before

% customize subsection
\titleformat{\subsection}%
{\bfseries}% format
{\llap{% label
    \thesubsection\hskip 9pt}}%
{0pt}% horizontal sep
{}% before

% add vertical bar- change colour and thickness as desired
\AddToShipoutPicture{% from package eso-pic: put something to the background
    % 3. Text area
    \AtTextLowerLeft{% put it at the left bottom of the text area
        \llap{\color{gray}\rule{.1cm}{\LenToUnit\textheight}% can put spacing here, e.g \hspace{.25cm}
        }%
    }%
}

% margin theorem
\makeatletter
\newtheoremstyle{mymargin}%
{\item[\theorem@headerfont \llap{##1 ##2}]}%
{\item[\theorem@headerfont \llap{##1 ##2}| ##3\theorem@separator\hskip\labelsep]}%
\makeatother

% my definition
\theoremstyle{mymargin}
\theorembodyfont{}      % customize these to suit your tastes
\theoremsymbol{}
\theoremprework{}
\theorempostwork{}
\theoremseparator{}
\newtheorem{mydefinition}{Definition}
\numberwithin{mydefinition}{section}

\begin{document}
\chapter{My chapter}
\section{First section}
\lipsum[1]
\begin{mydefinition}
\lipsum[2]
\begin{equation}\label{eq:myequation}
    f(x)=x^2
\end{equation}
Test reference: \eqref{eq:myequation}
\end{mydefinition}

\end{document}
Related Question