1

I have seen the answer to a similar question, but I want more control:

I have roman Chapters and arabic sections. I want the roman numeral to be hidden from the TOC, and from the TOC only (additionally, I will also remove them later from the section titles). The most important is that I need the cross chapter section references to show the chapter number.

I tried titletoc without success (although copying almost identically a command from the manual):

\documentclass[12pt, a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec,titletoc}

\renewcommand{\thechapter}{\Roman{chapter}}
\newcommand{\thesectiononly}{\arabic{section}}  % Do not override \thesection.

% Large bold section titles with section number only
\titleformat{\section}{\Large\bfseries}{\thesectiononly}{24pt}{}

% bold section names in the table of contents, with section number only.
\titlecontents*{section}[12pt]{\bfseries}{\thesectiononly. }{}{\thecontentspage}

\begin{document}

% Here, we should see 1. First section......
\tableofcontents

\chapter{First chapter}

\section{First section}\label{sec:first-section}

First content.

\section{Second section}

Other content.

\chapter{Second chapter}

\section{section in second chapter}

Last content, referring to section~\ref{sec:first-section}. % Displayed as "I.1"

\end{document}

This compiles, but the resulting TOC is:

Imgur

  • How do I get the correct section numbering?
  • How do I get default leading dots to the page number?

I know about tocloft, but haven't found a way to strip off chapter numbers using it.

1 Answers1

0

You only need to redefine \thesection and \p@section.

\documentclass[12pt, a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec,titletoc}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\makeatletter
\renewcommand{\p@section}{\thechapter.} 
\makeatother


\begin{document}

% Here, we should see 1. First section......
\tableofcontents

\chapter{First chapter}

\section{First section}\label{sec:first-section}

First content.

\section{Second section}

Other content.

\chapter{Second chapter}

\section{section in second chapter}

Last content, referring to section~\ref{sec:first-section}. % Displayed as "I.1"

\end{document}
touhami
  • 19,520
  • What is \p@section ? Is it described in the Latex macros? – PlasmaBinturong Jun 02 '20 at 16:29
  • you ca find it in source2e – touhami Jun 02 '20 at 16:34
  • Incredible, here is a latex problem solved in 3 simple lines... and this has the added benefit that titlesec and titletoc packages are not needed anymore. – PlasmaBinturong Jun 02 '20 at 16:34
  • I am being futile, but now from within a chapter, is there a way to refer to same-chapter sections without the \p@section part?... I am using the cleverref package. For example by using a new macro \localcref? – PlasmaBinturong Jun 03 '20 at 20:51
  • @PlasmaBinturong there is. you need to do some tests. I think this was already answered here. – touhami Jun 04 '20 at 21:15
  • 1
    @PlasmaBinturong here you are https://tex.stackexchange.com/questions/262652/how-to-make-the-enumeration-of-theorem-like-environments-indipendent-from-cross/263185#263185 – touhami Jun 04 '20 at 21:22