5

I would very much like that the the appendix sections of the Table of Contents doesn't have a section numbers, dots, and page numbers. If I do the following

\documentclass{article}
\usepackage{tocloft}
\addtocontents{toc}{\cftpagenumbersoff{section}}
\renewcommand{\cftdot}{}
\begin{document}
\tableofcontents
\newpage
\section{Appendix}
\section*{Another Letter} \addcontentsline{toc}{section}{Another Letter}
\end{document}

then the section "Another Letter" is left aligned, so it doesn't look like the others.

Question

Is it possible to have "Another Letter" styled the same way as normal TOC entries, but just without section number, dots, and page number?

  • 2
    There is an error, it should be \addcontentsline{toc}{section}{Another Letter} – karlkoeller Sep 24 '13 at 16:35
  • What about sections before the appendix? – egreg Sep 24 '13 at 16:55
  • @egreg They should be normal and unaffected. – Sandra Schlichting Sep 24 '13 at 16:56
  • @SandraSchlichting Should \section{Appendix} in the text receive a number? – egreg Sep 24 '13 at 17:13
5

I don't know whether this really answers your question. Basically, I patch the \appendix command to suppress numbering of sections; then it also issues some commands to be written in the toc file to change the behavior from that point on. The double \unexpanded trick is for avoiding several \protect in front of macro names.

As far as I know, leaders are off for section titles in the article class to begin with, so there's no need to act on \cftdot.

\documentclass{article}

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

\appto\appendix{%
  \setcounter{secnumdepth}{-2}
  \addtocontents{toc}{%
    \unexpanded{\unexpanded{%
      \cftpagenumbersoff{section}%
      \setlength\cftsecindent{\cftsecnumwidth}%
    }}%
  }%
}

\begin{document}

\tableofcontents
\clearpage

\section{This has the section number also in the TOC}


\appendix
\section{Appendix}

\section{Another Letter}

\end{document}

enter image description here

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.