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.

This is the code I'm currently using the customize the section headers in my table of contents:

\usepackage[dotinlabels]{titletoc}
\titlecontents{section}[1pc]
{\addvspace{0pc}}
{\thecontentslabel.\hspace{3mm}}
{}
{\normalsize\titlerule*[6pt]{.}\contentspage}
[\addvspace{0pt}]

And the result looks like this: enter image description here

Question: How can I modify this such that all the section titles will be properly "left-aligned", even the ones starting with section 10? I want the section number to appropriately "move to the left", as required to make this happen. How do I accomplish this?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

You can use a \parbox and \hfill to push \thecontentslabel to the right; something like:

\parbox{1cm}{\hfill\thecontentslabel}

The width of the \parbox can be set using a length in which you specify the widest label. A complete example in which I set the widest label to the width of 99.99.:

\documentclass[fleqn,12pt,a4paper]{book}
\usepackage[dotinlabels]{titletoc}

\newlength\widest
\settowidth\widest{99.99.}

\titlecontents{section}[1pc]
{\addvspace{0pc}}
{\parbox[t]{\widest}{\hfill\thecontentslabel.}
\hspace{3mm}}
{}
{\normalsize\titlerule*[6pt]{.}\contentspage}
[\addvspace{0pt}]

\begin{document}

\tableofcontents

\chapter{Test}
\section{section-1}
\section{section-2}
\section{section-3}
\section{section-4}
\section{section-5}
\section{section-6}
\section{section-7}
\section{section-8}
\section{section-9}
\section{section-10}
\section{section-11}
\section{section-12}
\section{section-13}

\end{document}

enter image description here

share|improve this answer
    
This works, expect for one problem: For some reasons, this solution causes the section number (e.g. "1.1") to move down a bit, and it makes "1.1." a bit below "section", compared to the baseline. Why would this be happening? –  meh May 11 '12 at 14:00
1  
\parbox[t]{...}{...} –  daleif May 11 '12 at 14:13
    
@daleif thanks, that worked. –  meh May 11 '12 at 15:12
    
@daleif: I incorporated your suggestion to my answer, thanks. –  Gonzalo Medina May 11 '12 at 16:42
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.