# Align the names in \listtheorems (ntheorem)

Question:

How do I align the names of theorems in ntheorem list of theorems?

Screenshot:

Screenshot: (photoshopped)

Context:

I am using the ntheorem package to typeset a list of theorems and definitions (\listtheorems) and have defined several custom theorem environments. The environment names have different word lengths which leads to a non aligned typesetting in the list.

I am writing in German language in which only one environment name is significantly shorter altough noticable minimal meanderings exist between the others as well.

Screenshot:

Related Questions I have found two related questions but both focus only on spacing.

TeX.SE Question: 53353 Titlespacing for \listtheorems in ntheorem

TeX.SE Question: 43166 Spacing numwidth control for \listtheorems

Minimal Example:

\documentclass{article}

\usepackage{ntheorem}

\theoremlisttype{allname}

\newtheorem{axiom}{Axiom}
\newtheorem{proposition}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{corollary}{Corollary}
\newtheorem{converse}{Converse}

\begin{document}
\listtheorems{axiom,proposition,lemma,corollary,converse}

\begin{axiom}[Theorem 1] \end{axiom}
\begin{proposition}[Theorem 2] \end{proposition}
\begin{lemma}[Theorem 3] \end{lemma}
\begin{corollary}[Theorem 4] \end{corollary}
\begin{converse}[Theorem 5] \end{converse}

\end{document}

-

To solve this we need to patch \thm@@thmline in ntheorem.

It's called \thm@@thmline@noname or \thm@@thmline@name depending on the called options all or opt or, respectively allname or optname.

There are two versions of these macros in ntheorem. Those with four parameters are used in non-hyperref documents. Those with five parameters are used in documents when hyperref is loaded.

Therefore you can either patch \thm@@thmline directly and force allname/optname behavior like in the first code snippet or you can patch \thm@@thmline@name as in the second code snippet, which will preserve the ability to use opt and all. Both snippets will work with and without hyperref.

Solution 1

\documentclass{article}

\usepackage{ntheorem}

%\usepackage{hyperref}
%\usepackage[hyperref]{ntheorem}

\makeatletter
\AtBeginDocument{
{
% hyperref version of the macro
\renewcommand\thm@@thmline[5]{%
}
}
{
% standard, non-hyperref version of the macro
\renewcommand\thm@@thmline[4]{%
\@dottedtocline {-2}{0em}{2.3em}{\makebox[\widesttheorem][l]{#1 \protect \numberline {#2}}#3}{#4}%
}


} \settowidth{\widesttheorem}{Proposition 10\quad} } \makeatother \newlength\widesttheorem

\theoremlisttype{allname}

\newtheorem{axiom}{Axiom}
\newtheorem{proposition}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{corollary}{Corollary}
\newtheorem{converse}{Converse}

\begin{document}
\listtheorems{axiom,proposition,lemma,corollary,converse}

\begin{axiom}[Theorem 1]
\end{axiom}
\begin{proposition}[Theorem 2]
\end{proposition}
\begin{lemma}[Theorem 3]
\end{lemma}
\begin{corollary}[Theorem 4]
\end{corollary}
\begin{converse}[Theorem 5]
\end{converse}

\end{document}


Solution 2

\documentclass{article}

\usepackage{ntheorem}

%\usepackage{hyperref}
%\usepackage[hyperref]{ntheorem}

\makeatletter
\def\thm@@thmline@name#1#2#3#4{%
\@dottedtocline{-2}{0em}{2.3em}%
{\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}%
{#4}}
\def\thm@@thmline@name#1#2#3#4#5{%
\ifx\\#5\\%
\@dottedtocline{-2}{0em}{2.3em}%
{\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}%
{#4}
\else
\@dottedtocline{-2}{0em}{2.3em}%
{\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}%
\else
\@dottedtocline{-2}{0em}{2.3em}%
{#4}%
\fi
\fi}
}
\makeatother
\newlength\widesttheorem
\AtBeginDocument{
}

\theoremlisttype{allname}

\newtheorem{axiom}{Axiom}
\newtheorem{proposition}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{corollary}{Corollary}
\newtheorem{converse}{Converse}

\begin{document}
\listtheorems{axiom,proposition,lemma,corollary,converse}

\begin{axiom}[Theorem 1]
\end{axiom}
\begin{proposition}[Theorem 2]
\end{proposition}
\begin{lemma}[Theorem 3]
\end{lemma}
\begin{corollary}[Theorem 4]
\end{corollary}
\begin{converse}[Theorem 5]
\end{converse}

\end{document}


In the argument to \settowidth you put the longest label, the biggest number and a suitable spacing.

-
Thank you very much! :) I've added hyperref compatibility and an alternative which preserves options opt and allopt. The edit is in review at the moment. I hope it's okay to you :) –  Christoph Jul 18 '12 at 16:07
@Christoph I'll look at it; thanks for the addition. –  egreg Jul 18 '12 at 16:43