Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Question:

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

Screenshot: Current output

Screenshot: Intentended output (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: image

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}
share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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{
    \@ifpackageloaded{hyperref}
     {
      % hyperref version of the macro
      \renewcommand\thm@@thmline[5]{%
        \@dottedtocline {-2}{0em}{2.3em}{\hyper@linkstart{link}{#5}{\makebox[\widesttheorem][l]{#1 \protect \numberline {#2}}#3}\hyper@linkend}{#4}%
      }
     }
     {
      % 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}}
\@ifpackageloaded{hyperref}{
\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
        \ifHy@linktocpage\relax\relax
            \@dottedtocline{-2}{0em}{2.3em}%
                {\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}%
                {\hyper@linkstart{link}{#5}{#4}\hyper@linkend}%
        \else
            \@dottedtocline{-2}{0em}{2.3em}%
                {\hyper@linkstart{link}{#5}%
                  {\makebox[\widesttheorem][l]{#1 \protect\numberline{#2}}#3}\hyper@linkend}%
                    {#4}%
        \fi
    \fi}
}
\makeatother
\newlength\widesttheorem
\AtBeginDocument{
  \settowidth{\widesttheorem}{Proposition 10\quad}
}

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

enter image description here

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.