2

I have document which creates a new list of examples. The list has a label \label{sec:examples} which labels the title of the list, which is rendered as a section. However, cross referencing sec:examples results in a reference to a subsection.

This is a small but complete example that demonstrates the problem:

\documentclass[conference]{IEEEtran}

\usepackage{lipsum}
\usepackage[titles]{tocloft}

\newcommand{\listexampletitle}{\addtocounter{section}{1}\thesection.~List of Examples\label{sec: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}
\setlength{\cftexamplesnumwidth}{1.5cm}


\begin{document}

\title{Example IEEE with tocleft}

\author{}

\maketitle

\section{Introduction}
Examples are summarised in Section \ref{sec:examples}.

\example{A first example}

\section{A section}
\subsection{A subsection}
\lipsum[1]{}
\example{A second example}

\listofexamples

\end{document}

A picture of the relevant output is below, with the problematic line highlighted in yellow. The first line of the Introduction, which is rendered as:

Examples are summarised in Section II.I.

should read:

Examples are summarised in Section III.

How do I correct this?

Output:

enter image description here

7
  • @HarishKumar: I agree with your objection about the placement of the label, but your suggestion would reference the first section however! – user31729 Aug 28 '14 at 10:02
  • @HarishKumar: I think, we have a misunderstanding... I believe, the OP just wants to add a reference to the 'section' where the list appears. – user31729 Aug 28 '14 at 10:08
  • That's right, it's the list that needs to be referenced, not any particular example. I have added an image of the PDF to clarify. – snim2 Aug 28 '14 at 10:19
  • @ChristianHupfer Yes I misunderstood! :-( – user11232 Aug 28 '14 at 10:43
  • @snim2 Your demand of Examples are summarised in Section II. should have been Examples are summarised in Section III. with regard to the current picture as List of Examples is III not II. – user11232 Aug 28 '14 at 10:51
4

Somehow the \newlistof command seems to group (didn't check this, admittedly) the \refstepcounter command within. It's better to patch the \listofexamples, first stepping the section counter, than immediately correcting it back by decreasing it. This is achieved by the etoolbox package command \pretocmd, which is done in this case a little lazy, I ignored the tests ;-)

I changed the definition of \listofexamples etc. a little bit, making it a true section.

\documentclass[conference]{IEEEtran}

\usepackage{lipsum}
\usepackage[titles]{tocloft}

\usepackage{etoolbox}

\newcommand{\listexampletitle}{List of Examples}


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

% Prepending the \listofexamples command with dummy \refstepcounter{section} etc.
\pretocmd{\listofexamples}{\refstepcounter{section}\addtocounter{section}{-1}}{}{}%



\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}
\setlength{\cftexamplesnumwidth}{1.5cm}


\begin{document}

\title{Example IEEE with tocleft}

\author{}

\maketitle

\section{Introduction}
Examples are summarised in Section \ref{sec:examples}.

\example{A first example}

\section{A section}
\subsection{A subsection}
\lipsum[1]{}
\example{A second example}



\listofexamples\label{sec:examples}
\end{document}

enter image description here

1
  • @snim2: Please test it, give feedback later on -- I will return to it on problems, but for now I am off ;-) – user31729 Aug 28 '14 at 10:27

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.