2

I'm doing a custom document type with article. I'm using titletoc, titlesec and tocloft. Due to internal style guides, I need the titles "Contents", "List of Tables" and "List of Figures" to appear in a different style than the \section or \section* heading.

I think that the easiest way to do this is to simply suppress the "Contents," "List of Tables" and "List of Figures" text when \tableofcontents is run, and print it myself.

How do I suppress "Contents"?

3
  • \renewcommand{\contentsname}{} will suppress the text, but not the space used. – John Kormylo Oct 25 '16 at 21:06
  • The tocloft docs also give instructions for styling the headers (sec. 2.2), if you want to do it that way. (I don't know if that conflicts with the other packages you use, though.) – Emma Oct 25 '16 at 22:16
  • @JohnKormylo, I need to suppress the generation of the \section*{}, because my \section's are white text on a black background. – vy32 Oct 26 '16 at 14:52
2

Probably one of the easiest ways to suppress printing the ToC/LoF/LoT headings would be to make \section gobble its arguments and just do nothing. That not only suppresses the heading, but also any space insertions (before and after).

One way of achieving this voiding of \section via a redefinition using xparse, since it's easy to manage the starred version \section* which is typical of \tableofcontents, \listoffigures and \listoftables:

enter image description here

\documentclass{article}

\usepackage{xparse}

\let\oldsection\section
\newcommand{\voidsections}{\RenewDocumentCommand{\section}{ s o m }{}}
\newcommand{\restoresections}{\let\section\oldsection}

\begin{document}

\voidsections% Totally remove functionality of \section
\tableofcontents
\restoresections% Restore \section functionality

\listoffigures

\voidsections% Totally remove functionality of \section
\listoftables
\restoresections% Restore \section functionality

\section{First section}
\begin{figure}\caption{A figure}\end{figure}
\begin{table}\caption{A table}\end{table}
\begin{figure}\caption{A figure}\end{figure}
\begin{table}\caption{A table}\end{table}

\section{Second section}
\begin{figure}\caption{A figure}\end{figure}
\begin{table}\caption{A table}\end{table}
\begin{figure}\caption{A figure}\end{figure}
\begin{table}\caption{A table}\end{table}

\section{Third section}
\begin{figure}\caption{A figure}\end{figure}
\begin{table}\caption{A table}\end{table}
\begin{figure}\caption{A figure}\end{figure}
\begin{table}\caption{A table}\end{table}

\section{Last section}
\begin{figure}\caption{A figure}\end{figure}
\begin{table}\caption{A table}\end{table}
\begin{figure}\caption{A figure}\end{figure}
\begin{table}\caption{A table}\end{table}

\end{document}

In the above example, \voidsections removes the functionality of \section, while \restoresections restores it. It should work with any package, assuming that you add the preamble content after loading your sectioning packages, as the structure remains fairly similar (they all use \section* for the ToC/LoF/LoT).

The example specifically nullifies the heading of the ToC and LoT, while still keeping other sectioning (LoF and the remainder of the document).

1
  • Thanks. That's what I am looking for. I thought about redefining \section*, but didn't know how to stash the copy. – vy32 Oct 26 '16 at 14:53
0

It is also possible to select between multiple versions of \section (and \section*)

\documentclass{article}
\let\oldsection=\section

\usepackage{titlesec}
\titleformat*{\section}{\itshape}
\let\newsection=\section

\begin{document}
\let\section=\oldsection
\tableofcontents

\let\section=\newsection
\section{Demo}

\end{document}

demo

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.