1

I am trying tu customize how the numbering format of sections, subsections, etc. in the table of contents using the book class. Basically, the problem is that changing any style with \renewcommand changes it everywhere, and I want to change it for the table of contents independently from the style for the cross references.

I know the titlesec package, but it only changes the style of the actual headers, and not the cross references.

More precisely, my MWE is the following.

\documentclass[oneside,12pt]{book}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\thesubsection}{\thechapter.\arabic{section}.\alph{subsection}}
\renewcommand{\theparagraph}{\roman{chapter}.\arabic{paragraph}.}

\setcounter{secnumdepth}{4}

\begin{document}

\tableofcontents

\chapter{First Chapter}
\section{Section one}\label{sec:one}
\subsection{Subsection A}\label{subsec:one.a}

\subsection{Subsection B}

\section{Section two}
Same as Section~\ref{sec:one}.

\section{Section three}
\subsection{Subsection A}
Same as Subsection~\ref{subsec:one.a}.

\end{document}

It produces the table of contents

and the body of the book

Now, I am happy with how the body looks, but I would like, for example, to drop the roman "I" in front of the section and subsection numbers in the table of contents, and NOT in the cross references.

I would appreciate all your suggestions.

2

When writing out the toc-entry LaTeX sets \label to \@gobble. So you could test for it:

\documentclass[oneside,12pt]{book}

\renewcommand{\thechapter}{\Roman{chapter}}
\makeatletter
\renewcommand{\thesection}{\ifx\label\@gobble\else\thechapter.\fi\arabic{section}}
\renewcommand{\thesubsection}{\ifx\label\@gobble\else\thechapter.\fi\arabic{section}.\alph{subsection}}
\renewcommand{\theparagraph}{\roman{chapter}.\arabic{paragraph}.}

\setcounter{secnumdepth}{4}

\begin{document}

\tableofcontents

\chapter{First Chapter}
\section{Section one}\label{sec:one}
\subsection{Subsection A}\label{subsec:one.a}

\subsection{Subsection B}

\section{Section two}
Same as Section~\ref{sec:one}.

\section{Section three}
\subsection{Subsection A}
Same as Subsection~\ref{subsec:one.a}.

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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