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.

How do I right-align the section/subsection/.. number in the ToC? The distance between the number and the heading should be fixed.

Instead of

|  1     Section
|        1.1      Subsection

I'd like to have something like

|      1 Section
|             1.1 Subsection

(|= left margin)

There must be a package for that...

(And I'd like to play with the indentation as well)

share|improve this question
    
you might want to think about this a bit more. while i agree with the concept in general, when section numbers are formatted as "chapter.section" and section goes to two digits, to me it looks a bit nicer with the compound number aligned on the decimal point. (of course, there's really no hope for a three-part subsection number with segments numbered 10 or greater.) –  barbara beeton Aug 17 '12 at 12:54
    
@barbarabeeton I have thought about it for quite some time and for my case the best solution is to have the numbers right aligned and only a little bit of indentation to the next sublevel :) I have very, very, very long section numbers. The default is just not feasible. –  topskip Aug 17 '12 at 13:10

1 Answer 1

up vote 10 down vote accepted

\numberline could be redefined:

\documentclass{article}

\makeatletter
\renewcommand*{\numberline}[1]{%
  \hb@xt@\@tempdima{\hfil#1 }%
}
\makeatother

\begin{document}
\tableofcontents

\section{First}
\subsection{Sub}
\addtocounter{subsection}{9}
\subsection{Foo}
\addtocounter{section}{9}
\section{Next}
\subsection{bar}
\end{document}

Table of contents with right aligned numbers

share|improve this answer
    
See also tocloft package, page 11. It offers facilities to play with the indentation. –  Guido Aug 17 '12 at 12:54
    
Thanks Heiko for the perfect solution. I should read latex.ltx more often. –  topskip Aug 17 '12 at 13:12

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.