Page Layout ⇒ Custom Entry in ToC
Re: Custom Entry in ToC
So guys, I need some help, how do I add one little extra line to my table of contents that says "Appendix C.........................TEXT" where "TEXT" is literally a string of text, instead of a page number?
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Re: Custom Entry in ToC
Anyone??
Custom Entry in ToC
Code: Select all
\documentclass{book}
\begin{document}
\tableofcontents
\section{Test}
\addtocontents{toc}{\protect\contentsline {section}{Foo}{bar}}
\end{document}
Custom Entry in ToC
Alright, but when I use that command in that way, for my working example, "Appendix C" is indented, there are no dots between "Appendix C" and "TEXT," and "TEXT" does not appear all the way to the right like it should.
So:
How do I fix this??
(See attachment - this is the output that I get)
Code: Select all
\documentclass[12pt]{book}
\usepackage[dotinlabels]{titletoc}
\usepackage[indentafter,newlinetospace]{titlesec}
\usepackage{ifthen}
\renewcommand{\contentsname}{TABLE OF CONTENTS}
\renewcommand{\listtablename}{LIST OF TABLES}
\renewcommand{\appendixname}{Appendix}
% Format the Chapter in the TOC
\titlecontents{chapter}[0in]{\ifthenelse{\equal{\thecontentslabel}{1}}{
\vspace{1.3\baselineskip}Chapter\\ \normalsize}{
\normalsize\vspace{.2\baselineskip}}}
{\contentspush{\thecontentslabel.~}}
{}
{\titlerule*[.3em]{.}\thecontentspage}
{}
\titlecontents{section}[.3in]{}
{\contentspush{\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
% Format the Appendix in the TOC
\renewcommand{\appendixname}{Appendix}
\let\oldAppendix\appendix
\renewcommand{\appendix}{
\oldAppendix
\addtocontents{toc}{\protect \setcounter{tocdepth}{0} \par}
\titlecontents{chapter}[0in]{\normalsize\vspace{.2\baselineskip}}
{\contentspush{Appendix~\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
}
\linespread{2}
\title{An example with TEXT for a Page Number}
\author{Lava Typer}
\begin{document}
\maketitle
\tableofcontents
\listoftables
\chapter{First Chapter}
\section{First Section}
Here is a table. I have many tables in my project.
\begin{table}[h]
\caption{\label{table:mycaption}Caption goes here}
\begin{tabular}{lcr}
left & center & right \\
\end{tabular}
\end{table}
\section{Second Section of new chapter}
Content
\appendix
\chapter{First Appendix}
\section{Greetings}
I have multiple appendices...
\chapter{Second Appendix}
Here is another appendix.
\section{What I need from LaTeX-Community}
\textbf{After Appendix B in the actual Table of Contents page listing... \\
I need ``Appendix C," dots, and a string of text (say, ``TEXT") instead of a page number.}
But I want the document to end at Appendix B...and not actually have a physical ``Appendix C" in the \LaTeX file.
The suggestion by cgnieder meets my requirement part way, but it doesn't format correctly. "Appendix C" is indented, there are no dots between "Appendix C" and "TEXT," and "TEXT" does not appear all the way to the right like it should.
How do I fix this?
\addtocontents{toc}{\protect\contentsline {appendix}{Appendix C}{TEXT}}
\end{document}
- Attachments
-
- HowDoIFixThis.jpg (41.27 KiB) Viewed 10696 times
Custom Entry in ToC
I didn't say that, did I?LavaTyper wrote:No, Stefan did not tell me **how** to use those commands.

The first argument ofLavaTyper wrote:Alright, but when I use that command in that way, for my working example, "Appendix C" is indented, there are no dots between "Appendix C" and "TEXT," and "TEXT" does not appear all the way to the right like it should.
[...]
Code: Select all
\appendix % code skipped \addtocontents{toc}{\protect\contentsline {appendix}{Appendix C}{TEXT}}
\contentsline
should be the name of the sectioning level you want the entry to appear, i.e., chapter, section, subsection etc. »appendix« is no such level which is why your attempt fails. It is unfortunate that you're not getting an error but that is because \contentsline
calls the relevant internal command via \csname ... \endcsname
which means that if the internal command doesn't exist it is silently defined to \relax
which does nothing.Try
Code: Select all
\addtocontents{toc}{\protect\contentsline {section}{Appendix C}{TEXT}}
Custom Entry in ToC
section
, because then the extra entry just doesn't appear at all in the Table of Contents.And, yes, I made absolutely sure to compile it twice.
See screenshot.
- Attachments
-
- Missing.png (50.55 KiB) Viewed 10693 times
Custom Entry in ToC
That is becauseLavaTyper wrote:It doesn't work when I usesection
, because then the extra entry just doesn't appear at all in the Table of Contents.
\appendix
calls \setcounter {tocdepth}{0}
(I can't remember if this is the default or if this is due to some package you've loaded...) but since your other appendices are chapters, anyway, you will probably want
Code: Select all
\addtocontents{toc}{\protect\contentsline {chapter}{Appendix C }{TEXT}}
It seems to me that the following would even be better:
Code: Select all
\stepcounter{chapter}
\addtocontents{toc}{\protect\contentsline {chapter}{Appendix \thechapter. }{TEXT}}
Regards
Custom Entry in ToC
bibliography.tex
, below:Code: Select all
\chapter*{BIOGRAPHY OF THE AUTHOR}
\addcontentsline{toc}{chapter}{BIOGRAPHY OF THE AUTHOR}
Here is my biography. It has to appear after the last appendix, in both the document and the Table of Contents.
as well as hyper-active, colored links, so I also need the following code added to my example:
Code: Select all
\usepackage[colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=blue, plainpages=false, pdfpagelabels=true, urlcolor=blue]{hyperref}
Your code,
\addtocontents{toc}{\protect\contentsline {chapter}{Appendix C }{TEXT}}
, works fine...but it doesn't work if I require both
hyperref
, in the preamble,and
\input{bibliography}
, after the last actual appendix.I get a bunch of error messages and the end of my table of contents formats incorrectly.
I've attached an updated example...how do I fix this?
Code: Select all
\documentclass[12pt]{book}
% I want clickable links to content in my dissertation:
\usepackage[colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=blue, plainpages=false, pdfpagelabels=true, urlcolor=blue]{hyperref}
\usepackage[dotinlabels]{titletoc}
\usepackage[indentafter,newlinetospace]{titlesec}
\usepackage{ifthen}
\renewcommand{\contentsname}{TABLE OF CONTENTS}
\renewcommand{\listtablename}{LIST OF TABLES}
\renewcommand{\appendixname}{Appendix}
% Format the Chapter in the TOC
\titlecontents{chapter}[0in]{\ifthenelse{\equal{\thecontentslabel}{1}}{
\vspace{1.3\baselineskip}Chapter\\ \normalsize}{
\normalsize\vspace{.2\baselineskip}}}
{\contentspush{\thecontentslabel.~}}
{}
{\titlerule*[.3em]{.}\thecontentspage}
{}
\titlecontents{section}[.3in]{}
{\contentspush{\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
% Format the Appendix in the TOC
\renewcommand{\appendixname}{Appendix}
\let\oldAppendix\appendix
\renewcommand{\appendix}{
\oldAppendix
\addtocontents{toc}{\protect \setcounter{tocdepth}{0} \par}
\titlecontents{chapter}[0in]{\normalsize\vspace{.2\baselineskip}}
{\contentspush{Appendix~\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
}
\linespread{2}
\title{An example with TEXT for a Page Number}
\author{Lava Typer}
\begin{document}
\maketitle
\tableofcontents
\listoftables
\chapter{First Chapter}
\section{First Section}
Here is a table. I have many tables in my project.
\begin{table}[h]
\caption{\label{table:mycaption}Caption goes here}
\begin{tabular}{lcr}
left & center & right \\
\end{tabular}
\end{table}
\section{Second Section of new chapter}
Content
\appendix
\chapter{First Appendix}
\section{Greetings}
I have multiple appendices...
\chapter{Second Appendix}
Here is another appendix.
% Here is the code by: cgnieder
\addtocontents{toc}{\protect\contentsline {chapter}{Appendix C}{TEXT}}
% ^^ This works...
% as long as I don't then include my biography.tex file,
% after the last appendix:
\input{biography}
% If I take out EITHER \usepackage{hyperref} or \input{biography}, then it works again.
% I need both in this order, for my dissertation.
% How do I fix this?
\end{document}
Here is a picture to show you what I get when I comment out the
hyperref
in my preamble: as you can see it works fine up to that point.- Attachments
-
- NoHyperref.jpg (72.9 KiB) Viewed 10685 times
Custom Entry in ToC
\contentsline
.In this case the best would be to safe the original meaning to a new macro before calling hyperref:
Code: Select all
\newcommand*\LTXcontentsline{}
\let\LTXcontentsline\contentsline
\usepackage{hyperref}
\let
.)Now you use the new macro in the relevant line:
Code: Select all
\stepcounter{chapter}
\addtocontents{toc}{\protect\LTXcontentsline{chapter}{Appendix \thechapter. }{TEXT}}
BTW: I just realized by looking at your example again that you yourself redefined
\appendix
where you call \setcounter{tocdepth}{0}
so your previous question shouldn't have been necessary...Regards