Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to manually add the chapters of my appendix to the ToC, but the result is horrible. The page number is placed directly next to the chapter name, instead of using the regular format where the page number aligns right.

My code:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{geometry}
\usepackage[toc,page,title]{appendix}

\begin{document}
\tableofcontents
\section{Week 1 - Intro \textcolor{blue}{\textbf{R}}}
\begin{appendices}
\addcontentsline{toc}{chapter}{Appendix A} 
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\chapter{\large{\textbf{Appendix A - \textcolor{blue}{R} commando's}}} \\
\chapter{\large{\textbf{Appendix B - Begrippenlijst}}}
\end{appendices}
\end{document}

Screenshot of the code:

Screenshot

So what I want is to have the "regular" ToC format when adding these chapters to the ToC. All manuals I can find offer no explanation as to how the \addcontentsline command works, but I'm almost certain the solution lies in that command, specifically in the "entry" part of the command (third argument).

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

You are using article class and using \chapter which doesn't look correct. Use \section instead.

\documentclass{article}
\usepackage{xcolor}
%\usepackage{geometry}
\usepackage[toc,page,title]{appendix}

\begin{document}
\tableofcontents
\section{Week 1 - Intro \textcolor{blue}{\textbf{R}}}
\begin{appendices}
%\addcontentsline{toc}{section}{Appendix A}
%\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\section{Appendix A - \protect\textcolor{blue}{R} commando's}
\section{Appendix B - Begrippenlijst}
\end{appendices}
\end{document}

enter image description here

I have removed extra commands from the section arguments and modified. Note the \protect since \textcolor is fragile..

Further, you need not add Appendix A in the section title. Use titletoc option for appendix

\documentclass{article}
\usepackage{xcolor}
%\usepackage{geometry}
\usepackage[titletoc,page,title]{appendix}   %% note titletoc

\begin{document}
\tableofcontents
\section{Week 1 - Intro \textcolor{blue}{\textbf{R}}}
\begin{appendices}
%\addcontentsline{toc}{section}{Appendix A}
%\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\section{\protect\textcolor{blue}{R} commando's}
\section{Begrippenlijst}
\end{appendices}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.