0

I currently have the following ToC code:

\usepackage{tocloft}
\renewcommand{\cftchapfont}{\chaptername }

\newcommand{\likechapter}[1]{    
    \chapter*{#1}
    \phantomsection
    \addcontentsline{toc}{chapter}{ #1}
}

And section of the document are defined like this:

\likechapter{Introduction}
\chapter{Some chapter}
\section{Some section}
\section{Some subsection}

It produces the following ToC: enter image description here

I don't need "chapter" text for Introduction. If I change \renewcommand{\cftchapfont}{\chaptername } to \renewcommand{\cftchapfont}{}, it removes "chapter" from all chapters. So, how can I remove only for some chapters (defined by \likechapter)?

EDIT: minimal example:

\documentclass{report}
\usepackage[english]{babel}
\usepackage[a4paper]{geometry}
\usepackage{tocloft}
\renewcommand{\cftchapfont}{\chaptername }

\newcommand{\likechapter}[1]{    
    \chapter*{#1}
    \phantomsection
    \addcontentsline{toc}{chapter}{ #1}
}

\begin{document}
\tableofcontents
\newpage

\likechapter{Introduction}
\chapter{Some chapter}
\section{Some section}
\section{Some subsection}

\end{document}
4
  • 1
    Please always post minimal but full examples that others can copy and test as is. Then it is a lot easier to help. And I don't think that is the proper tocloft way of prefixing entries in the toc, I do think it has an interface to add those without messing with a font setting.
    – daleif
    May 5, 2022 at 8:19
  • @daleif I've added the link May 5, 2022 at 10:02
  • Please don't place examples on external links, links rot over time and then your question will not be useful to others.
    – daleif
    May 5, 2022 at 10:10
  • 1
    @daleif thanks, I've added whole text to the question. May 5, 2022 at 11:01

1 Answer 1

1

Use \cftchappresnum to add to word Chapter before the chapter number. (note the space after).

Then enlarge the indent of the chapter title in that amount by expanding the number box.

a

\documentclass{report}
\usepackage[english]{babel}
\usepackage[a4paper]{geometry}
\usepackage{tocloft}

\renewcommand{\cftchapfont}{\bfseries}
\renewcommand{\cftchappresnum}{Chapter }% space after Chapter

\newlength{\xtraspace}
\settowidth{\xtraspace}{\cftchappresnum} % extra space = Chapter + space
\addtolength{\cftchapnumwidth}{\xtraspace} % makes  the indent of the  chapter title larger

\newcommand{\likechapter}[1]{%    
    \chapter*{#1}
    \addcontentsline{toc}{chapter}{#1}
}

\begin{document}
    \tableofcontents
    \newpage
    
    \likechapter{Introduction}
    \chapter{Some chapter}
    \section{Some section}
    \section{Some subsection}
    
\end{document}

You must log in to answer this question.

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