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 Can I adjust \tableofcontents in this way ?

enter image description here

\documentclass[12pt,a4paper,x11names]{article}
\usepackage[spanish]{babel}
\usepackage{lipsum}
\usepackage{blindtext}

\begin{document}

\tableofcontents
\newpage
Here stars the document... after the index\\
\part{Part I One}
\blindtext
\section{Section A of I}
\blindtext
\subsection{Subesction Jei}
\blindtext
\subsection{Subesction Jeii}
\blindtext
\section{Section B of I}
\blindtext
\subsection{Subesction Jeiii}
\blindtext
\subsection{Subesction Jeiiiii}
\blindtext
\section{Section C of I}
\blindtext
\subsection{Subesction Jeei}
\blindtext
\subsection{Subesction Jeeei}
\blindtext
\part{Part II Two}
\blindtext
\subsection{Subesction Jeeeei}
\blindtext
\section{Section A of II}
\blindtext
\subsection{Subesction Jerr}
\blindtext
\subsection{Subesction Jeddd}
\blindtext
\section{Section B of II}
\blindtext
\subsection{Subesction Jesss}
\part{Part III Three}
\blindtext
\section{Section A of III}
\subsection{Subesction Jerr}
\section{Section B of III}
\blindtext
\subsection{Subesction Jer}
\part{Part IV Four}
\section{Section A of IV}
\blindtext
\subsection{Subesction Jeittiii}
\blindtext\subsection{Subesction Jeiit}
\blindtext
\end{document}
share|improve this question
    
\usepackage{chngcntr}\counterwithin{section}{part}. –  Gonzalo Medina May 7 at 13:17
    
\gonzalo-medina It doesn´t work well . Number over numbers !! sensa.square7.ch/gfgfd54.jpg –  Mika Ike May 7 at 13:24

1 Answer 1

up vote 7 down vote accepted

You can use

\usepackage{chngcntr}
\counterwithin{section}{part}

Since using Roman numerals for parts leaves now little space between the number and the title for section and subsection entris, some additional adjustment is needed, which can be easily done using the tocloft package (adjust the lengths according to your needs):

\usepackage{tocloft}
\cftsetindents{section}{0em}{2.5em}
\cftsetindents{subsection}{2.5em}{3.5em}

A complete example:

\documentclass[12pt,a4paper,x11names]{article}
\usepackage[spanish]{babel}
\usepackage{tocloft}
\usepackage{chngcntr}
\counterwithin{section}{part}

\cftsetindents{section}{0em}{2.5em}
\cftsetindents{subsection}{2.5em}{3.5em}

\begin{document}

\tableofcontents
\newpage
Here stars the document... after the index\\
\part{Part I One}

\section{Section A of I}

\subsection{Subesction Jei}

\subsection{Subesction Jeii}

\section{Section B of I}

\subsection{Subesction Jeiii}

\subsection{Subesction Jeiiiii}

\section{Section C of I}

\subsection{Subesction Jeei}

\subsection{Subesction Jeeei}

\part{Part II Two}

\subsection{Subesction Jeeeei}

\section{Section A of II}

\subsection{Subesction Jerr}

\subsection{Subesction Jeddd}

\section{Section B of II}

\subsection{Subesction Jesss}
\part{Part III Three}

\section{Section A of III}
\subsection{Subesction Jerr}
\section{Section B of III}

\subsection{Subesction Jer}
\part{Part IV Four}
\section{Section A of IV}

\subsection{Subesction Jeittiii}
\subsection{Subesction Jeiit}

\end{document}

enter image description here

share|improve this answer
    
Gracias (Thank you), and for substitute the roman numbers for 1,2,3.... ? –  Mika Ike May 7 at 13:25
3  
@MikaIke De nada. \renewcommand\thepart{\arabic{part}}. –  Gonzalo Medina May 7 at 13:46
    
Gracias (Thank you), I compile twice and have regular results, but TOC point Part D to page 10, and in the reality Part D is in page 11. Is this normal? –  Mika Ike May 7 at 13:49
2  
@MikaIke No, this is not normal. At this point, I'd suggest you to open a fresh new question and to provide there a minimal complete document illustrating the problem, so we can diagnose the problem and propose solutions. –  Gonzalo Medina May 7 at 16:36

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.