0

I'm trying to set my table of contents using the tocloft package (using this question as a guide) to get something like this: enter image description here And this is what I've done so far

\documentclass[10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[paperheight=210mm,paperwidth=170mm,left=2cm,right=1.78cm,top=2.03cm,bottom=1.95cm,heightrounded]{geometry}
\usepackage{tocloft}
\makeatletter
\let\stdl@chapter\l@chapter
\renewcommand*{\l@chapter}[1]{\stdl@chapter{\hfill\underline{#1}}{}}
\makeatother
\setcounter{tocdepth}{2}

\begin{document}

\tableofcontents

\chapter{Hello}

\section{Hi}

\chapter{Goodbye}

\section{See you soon}

\end{document}

enter image description here

1
  • Do you want the chapter number twice: in roman as I and in arabic as 1.? Feb 22, 2022 at 16:57

1 Answer 1

1

The following does what I think you want.

% tocchapprob.tex SE 634861

\documentclass[10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[paperheight=210mm,paperwidth=170mm,left=2cm,right=1.78cm,top=2.03cm,bottom=1.95cm,heightrounded]{geometry}
\usepackage{tocloft}
\makeatletter
%\let\stdl@chapter\l@chapter
%\renewcommand*{\l@chapter}[1]{\stdl@chapter{\hfill\underline{#1}}{}}
\makeatother
\setcounter{tocdepth}{2}

%% eventually the number of the next chapter
\newcounter{nextchap}

%% set nextchap to the number of the next chapter
\newcommand{\incchap}{\setcounter{nextchap}{\value{chapter}}\addtocounter{nextchap}{1}}

%% add centered Chapter number into the ToC
%\newcommand{\addchaptoc}{\addtocontents{toc}{%
%    \vspace{\baselineskip}\centering \underline{\textbf{Chapter \Roman{nextchap}}}\par}

\begin{document}

\tableofcontents

% get the number of the next chapter
\incchap
% add centered Chapter number into the ToC
\addtocontents{toc}{\vspace{\baselineskip}\centering \underline{\textbf{Chapter \Roman{nextchap}}}\par}
\chapter{Hello}

\section{Hi}

Sectional text.


Nextchap is \thenextchap, and chapter is \thechapter.

\incchap
\addtocontents{toc}{\vspace{\baselineskip}\centering \underline{\textbf{Chapter \Roman{nextchap}}}\par}
\chapter{Goodbye}

Nextchap is \thenextchap, and chapter is \thechapter.


\section{See you soon}

\end{document}

enter image description here

You could, perhaps, make the user interface a little simpler, but that is up to you.

EDIT If you wanted dot leaders between the chapter titles and page numbers then add \renewcommand{\cftchapdotsep}{\cftdotsep} into your preamble.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .