Skip to content

LaTeX doesn't apply margins to enumerate/itemize within theorems, provide an option to do so. #12

@jdutant

Description

@jdutant

In LaTeX/PDF output, Enumerate and Itemize environment reset paragraphs margins (incl \leftskip, \rightskip). Hence setting left or right margins on theorems using \leftskip and \rightskip doesn't affect lists within theorems. If a theorem isn't a different font (e.g. remark) it may be look to the reader as if the list isn't in the theorem.

Solution: provide an option for applying margin to lists. For reference here's a LaTeX MWE using enumitem:

\documentclass{article}
\usepackage{amsthm}
\usepackage{enumitem}
\usepackage{etoolbox}

% === Margin flag ===
\newif\iftheoremmargins
\theoremmarginsfalse

% === Command to set margins + flag ===
\newcommand{\settheoremmargins}[2]{%
  \theoremmarginstrue%
  \addtolength{\leftskip}{#1}%
  \addtolength{\rightskip}{#2}%
}

% === Redefine itemize/enumerate based on flag ===
\let\origitemize\itemize
\let\origenumerate\enumerate

\renewenvironment{itemize}
  {\iftheoremmargins
     \origitemize[left=2em]
   \else
     \origitemize
   \fi}
  {\endlist}

\renewenvironment{enumerate}
  {\iftheoremmargins
     \origenumerate[left=2em]
   \else
     \origenumerate
   \fi}
  {\endlist}

% === Define theorem style using the new macro ===
\newtheoremstyle{margintheorem}
  {3pt}{3pt}
  {\settheoremmargins{2em}{2em}} % Body font: sets skips and flag
  {}{\bfseries}{.}{.5em}
  {\thmname{#1}~\thmnumber{#2}\thmnote{ \normalfont(#3)}}

\theoremstyle{margintheorem}
\newtheorem{theorem}{Theorem}

% Optional: a plain style for comparison
\newtheoremstyle{plainstyle}
  {3pt}{3pt}{\itshape}{}{\bfseries}{.}{.5em}
  {\theoremmarginsfalse\thmname{#1}~\thmnumber{#2}\thmnote{ \normalfont(#3)}}

\theoremstyle{plainstyle}
\newtheorem{corollary}{Corollary}

\begin{document}

\begin{theorem}
This is a theorem with left/right margins and an indented list:
\begin{itemize}
  \item Indented item
\end{itemize}
More text with adjusted margins.
\end{theorem}

\begin{corollary}
This is a corollary with normal margins:
\begin{itemize}
  \item This list is not indented.
\end{itemize}
\end{corollary}

\end{document}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions