1

I have a document in IEEE (conf) format and I want to add a new environment using tocloft. The relevant code looks like this (slightly abbreviated):

\documentclass[conference]{IEEEtran}
\usepackage[titles]{tocloft}
\newcommand{\listexampletitle}{List of Examples}
% FIXME: Should be styled as a "normal" subsection
\newlistof{examples}{exp}{\listexampletitle}
% FIXME: Remove page numbers
\newcommand{\examplelist}[1]{%
  \refstepcounter{examples}
  \addcontentsline{exp}{examples}
  {\protect\numberline{\theexamples}#1}
}
\newcommand{\example}[1]{\examplelist{#1}\textbf{Example}: #1}
\begin{document}
\section{A section}
\example{A first example}
\listofexamples
\end{document}

And the result looks something like this:

Output of the code above

Despite using the titles option with \usepackage[titles]{tocloft} the heading for the list of examples looks like a \section* rather than a \section. This makes sense as a default, usually a table would be generated as part of the front matter of a book. However, I would like that heading to be a normal \section since it will appear in the middle of the document. Is this possible?

Secondly, how can the page numbers against each item in the \listofexamples be removed, so only the examples themselves are listed?

  • 1
    I think minitoc package is of more use here – user31729 Aug 21 '14 at 16:38
  • Thanks. I had a brief look at the minitoc documentation. I can see how it would work for reformatting a list of figures or a ToC, but I couldn't see how it could be used for a completely new list. Have I missed something obvious here? – snim2 Aug 22 '14 at 9:53
2

The first part of this question can be resolved by incrementing the section counter automatically and inserting it into the table title manually, like this:

\newcommand{\listexampletitle}{\addtocounter{section}{1}\thesection.~List of Examples}

The second part of this question (how to remove the page numbers) can be answered by using the \cftpagenumbersoff{XXX} macro (where XXX is the long-form name of the new list).

In this case the corrected code looks like this:

\newcommand{\listexampletitle}{\addtocounter{section}{1}\thesection.~List of Examples}

\newlistof[section]{examples}{exp}{\listexampletitle}

\newcommand{\examplelist}[1]{%
  \refstepcounter{examples}
  \addcontentsline{exp}{examples}
  {\protect\numberline{\theexamples}#1}
}

\newcommand{\example}[1]{\examplelist{#1}\textbf{Example \theexamples}: #1}

\cftsetindents{examples}{1.5em}{3.0em}
\cftpagenumbersoff{examples} % Don't print page numbers with examples
\setlength{\cftexamplesnumwidth}{1.5cm} % Add space around example numbers

The result looks like this:

enter image description here

1

That the first part of the question requires such a hack method to solve is really unfortunate. tocloft is set up to define its very own heading formatting, and titles simply turns that off to use whatever is defined by the class (e.g. \section*). So there's no way within tocloft (yet) to change that to an unstarred section.

I've added an issue in its Github page to address this.

To get this working now, you can redefine the \listofexamples command: (its definition is fairly understandable)

\makeatletter
\renewcommand\listofexamples{%
  \@cfttocstart
  \if@cfthaschapter
    \chapter{\listexampletitle}%
  \else
    \section{\listexampletitle}%
  \fi
  \@nameuse{cftmarkexp}%
  \@starttoc{exp}%
  \@cfttocfinish 
}
\makeatother

Alternatively, the \patchcmd command from toolbox is really good for this sort of fix:

\usepackage{etoolbox}
\patchcmd\listofexamples{\section*}{\section}{}{}
  • Many thanks for this, Will. The answer here also recommends using etoolbox to resolve what I now realise is the same problem. Great to here that you've added the problem to the package Issues list. – snim2 Aug 30 '14 at 21:22

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.