1

After the preamble, I have this text:

\begin{document}

\frontmatter 

\maketitle


\input{introduzione.tex}

\tableofcontents

\mainmatter
...

This is the result:

enter image description here

I don't want the "v" letter after "Introduzione". How can I hide that? I tried something using \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}} but it doesn't work.

  • 2
    the fact that the file is \input is not related to the issue, what matters is what is in that file, about which you have given no information. By default unnumbered section headings are not added to the table of contents – David Carlisle Oct 10 '16 at 21:13
  • Welcome to TeX.SX! In order to answer this question we will need you to add a minimal working example (MWE) that illustrates your problem. This should be piece of code which begins \documentclass and ends \end{document} which when compiled produces Introduzione with the v. Try making a copy of your tex file and removing as much as possible such that the problem still occurs on compiling and then post that here. – Dai Bowen Oct 10 '16 at 21:23
  • 2
    The “v” is the page number where the introduction starts off. Since it is in the front matter, pages are labeled with Roman numbers. Why would you remove it? – egreg Oct 10 '16 at 21:30
1

In the default document classes, each entry in the ToC is set via the macro \contentsline{<type>}{<title>}{<page>}. It takes three arguments, the first of which <type> makes the formatting decisions, while the second <title> and third <page> provide the content to be set.

When you compile the following minimal example (at least twice)

\documentclass{book}

\begin{document}

\frontmatter 

\chapter{Introduction}% ...or \input{introduction}...

\tableofcontents

\mainmatter

\chapter{Main chapter}

\end{document}

you'll see the following in the .toc:

\contentsline {chapter}{Introduction}{i}
\contentsline {chapter}{\numberline {1}Main chapter}{1}

Your request would be to ignore the <page> for the first entry, but still keep it for subsequent entries. That is, instead of the regular \contentsline, we want something like \nopagecontentsline:

\let\oldcontentsline\contentsline
\newcommand{\nopagecontentsline}[3]{\oldcontentsline{#1}{#2}{}}

We would have to sleeve redefinitions cautiously as you're dealing with the ToC. So, within the main document, you'll use

\addtocontents{toc}{\let\protect\contentsline\protect\nopagecontentsline}
\chapter{Introduction}% ...or \input{introduction}...
\addtocontents{toc}{\let\protect\contentsline\protect\oldcontentsline}

Now your .toc would resemble

\let \contentsline \nopagecontentsline 
\contentsline {chapter}{Introduction}{i}
\let \contentsline \oldcontentsline 
\contentsline {chapter}{\numberline {1}Main chapter}{1}

where the update is inserted just before usage, and reverted just after usage.

Here is a complete minimal example:

enter image description here

\documentclass{book}

\let\oldcontentsline\contentsline
\newcommand{\nopagecontentsline}[3]{\oldcontentsline{#1}{#2}{}}

\begin{document}

\frontmatter 

\addtocontents{toc}{\let\protect\contentsline\protect\nopagecontentsline}
\chapter{Introduction}
\addtocontents{toc}{\let\protect\contentsline\protect\oldcontentsline}

\tableofcontents

\mainmatter

\chapter{Main chapter}

\end{document}

An easier option would be to set the Introduction as a \chapter* rather than a \chapter. By default, \chapter*s are not included in the ToC, which leaves it to you to do manually:

\chapter*{Introduction}% ...or \input{introduction}...
\addtocontents{toc}{\protect\contentsline{chapter}{Introduction}{}}
| 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.