4

I want to add my attachments in the table of contents but without having them in my latex file. So I just want to add something like:

**Attachments**
Attachment A: interview .............................. 1
Attachment B: worddoc ................................ 5

So I can print my Word files seperate from my Latex file.

Thanks in advance

My document:

\documentclass[11 pt, twoside, openright, tikz]{report}
\begin{document}
{\let\cleardoublepage\clearpage
\tableofcontents} %error here
\addcontentsline{toc}{chapter}{Referenties}
\bibliographystyle{apalike}
\end{document}

Gives the error:

Runaway argument?
File ended while scanning use of \contentsline.
<inserted text> 
                \par 
l.131 \tableofcontents
                      }
  • Please, test your MWE after deleting the auxiliary files (.aux, .toc). After compiling twice, there is only a warning about an unused global option tikz, no error (with \\error here replaced with % error here). – Heiko Oberdiek Oct 1 '16 at 12:03
  • @HeikoOberdiek I am actually using Overleaf, so i cant remove those files I guess. – user3201911 Oct 1 '16 at 12:07
7

Example with page numbers

The attachments are added at the end of the document/table of contents. Since deferred writing will not work after the last page, the writing is changed to \immediate\write by \zref@wrapper@immediate.

\documentclass{report}
\usepackage{zref-base}

\begin{document}
\tableofcontents
\chapter{Regular chapter}
\section{Regular section}

\clearpage
\begingroup
  \makeatletter
  \def\addtoc#1#2#3{%
    \addtocontents{toc}{%
      \protect\contentsline{#1}{#2}{#3}%
    }%
  }%
  \zref@wrapper@immediate{%
    \addtoc{chapter}{Attachments}{}%
    \addtoc{section}{Attachment A: interview}{\the\numexpr\value{page}-1+1\relax}%
    \addtoc{section}{Attachment B: worddoc}{\the\numexpr\value{page}-1+5\relax}%
  }%
\endgroup
\end{document}

Result with page numbers

Example without page numbers and dots

\NoDottedTocLine is inserted into the .toc file to remove the dots.

\documentclass{report}
\usepackage{zref-base}
\makeatletter
\def\@tocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     % \leaders\hbox{$\m@th
     %    \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
     %    mu$}%
     \hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
     \par}%
  \fi
}
\newcommand*{\NoDottedTocLine}{%
  \let\@dottedtocline\@tocline
}
\makeatother

\begin{document}
\tableofcontents
\chapter{Regular chapter}
\section{Regular section}

\clearpage
\begingroup
  \makeatletter
  \def\addtoc#1#2#3{%
    \addtocontents{toc}{%
      \protect\contentsline{#1}{#2}{#3}%
    }%
  }%
  \zref@wrapper@immediate{%
    \addtocontents{toc}{\protect\NoDottedTocLine}%
    \addtoc{chapter}{Attachments}{}%
    \addtoc{section}{Attachment A: interview}{}%
    \addtoc{section}{Attachment B: worddoc}{}%
  }%
\endgroup
\end{document}

Result

  • It gives an error in my code. But somehow Because an other weird error occurs in my .bib file I cant see the error. But could it give an error because {\let\cleardoublepage\clearpage \tableofcontents} is in my code? – user3201911 Oct 1 '16 at 11:05
  • @user3201911 There is no MWE in the question. Thus, you have to adapt/apply the code of the answer to your real document. I do not even know, if your document class has chapters (book, report, ...) or not (article, ...). – Heiko Oberdiek Oct 1 '16 at 11:10
  • okay im sorry I will make a better question about this. It is a report style btw. – user3201911 Oct 1 '16 at 11:12
  • @user3201911 The code in the answer is also based on class report. Please, update the question with a minimal working example (MWE). – Heiko Oberdiek Oct 1 '16 at 11:17
  • I edited a bit of my question – user3201911 Oct 1 '16 at 11:51

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.