0

I am following the answer provided here: Additional short TOC in scrbook

to create a second TOC. I am using scrreprt. The problem is that the second (shorter) TOC does not include the List of figures, List of tables, etc. Also not Nomenclature. Here is the code from above link:

\documentclass{scrreprt}
\usepackage[english]{babel}
\usepackage{caption}
\addtotoclist[\jobname]{stoc}
\BeforeStartingTOC[stoc]{\value{tocdepth}=0}
\usepackage{xpatch}
\xapptocmd\addtocentrydefault
  {\addxcontentsline{stoc}{#1}[#2]{#3}}
  {}{\PatchFailed}
\usepackage[colorlinks = true,linkcolor = black]{hyperref}

\begin{document}
Here is the Nomenclature...also not covered by second shorter TOC
\clearpage
\listoftoc[Short Contents]{stoc}
\tableofcontents
\listoffigures
\addcontentsline{toc}{chapter}{Figures}
\listoftables
\addcontentsline{toc}{chapter}{Tables}
\chapter{Introduction}
\section{First Section}
\begin{table}
    \caption{Caption of a Table}
\end{table}
\begin{figure}
    \caption{Caption of a Figure}
\end{figure}
\section{Second Section}
%\addchap{Test}
\end{document}

So what I would like to have is a short TOC, which covers all the major headings in the documents. That means TOC (longer one), Nomenclature, list of Tables, list of Figures, all chapters, bibliography. Possibly also the appendix. Can this be done in scrreprt ?

I figured out I can add elements via \addcontentsline{stoc}. However, the page numbers are still wrong (always by one), whereas the TOC page numbers are correct.

EtoAls
  • 309
  • 2
  • 8
  • If you use \addxcontensline{toc}{chapter}{chapter title} (note the x in the macro name) or \addchaptertocentry{chapter title} the chapter title would be added to both the normal ToC and the short ToC. But you add the last page of LoF and LoT to the ToCs. You could use class option listof=totoc to add the entries for LoF and LoT automatically. – esdd May 27 '20 at 22:11
  • @esdd thank you very much that worked. However, the links are still wrong (by a counter of 1) – EtoAls May 27 '20 at 22:57

1 Answers1

1

Update:

In addition to option listof=totoc you can use options bibliography=totoc and index=totoc. Entries for ToC and short ToC can be added to both ToC and short ToC using \setuptoc{toc}{totoc} and \setuptoc{stoc}{totoc}. Then there is also a bookmark for ToC.

Example:

\documentclass[listof=totoc,bibliography=totoc,index=totoc]{scrreprt}
\usepackage[english]{babel}
%\usepackage{caption}% not needed in the example

\addtotoclist[\jobname]{stoc}
\BeforeStartingTOC[stoc]{\value{tocdepth}=0}

\usepackage{xpatch}
\xapptocmd\addtocentrydefault
  {\addxcontentsline{stoc}{#1}[#2]{#3}}
  {}{\PatchFailed}

\setuptoc{toc}{totoc}% ToC entry in ToC (and short ToC)
\setuptoc{stoc}{totoc}% short ToC entry in ToC (and short ToC)

\usepackage[colorlinks = true,linkcolor = black]{hyperref}

\begin{document}
Here is the Nomenclature...also not covered by second shorter TOC
\listoftoc[Short Contents]{stoc}
\tableofcontents
\listoffigures
\listoftables
\chapter{Introduction}
\section{First Section}
\begin{table}
  \caption{Caption of a Table}
\end{table}
\begin{figure}
  \caption{Caption of a Figure}
\end{figure}
\section{Second Section}
\end{document}

enter image description here

Example:


Original answer:

If I use option listof=totoc to get a ToC entry for LoF and LoT I can not reproduce the link issue mentioned in the question. To add an entry for ToC in the short ToC use

\AfterTOCHead[toc]{\addxcontentsline{stoc}{chapter}{\contentsname}}

Example:

\documentclass[listof=totoc]{scrreprt}
\usepackage[english]{babel}
%\usepackage{caption}% not needed in the example
\addtotoclist[\jobname]{stoc}
\BeforeStartingTOC[stoc]{\value{tocdepth}=0}
\usepackage{xpatch}
\xapptocmd\addtocentrydefault
  {\addxcontentsline{stoc}{#1}[#2]{#3}}
  {}{\PatchFailed}
\AfterTOCHead[toc]{\addxcontentsline{stoc}{chapter}{\contentsname}}% ToC entry in short ToC
\usepackage[colorlinks = true,linkcolor = black]{hyperref}

\begin{document}
Here is the Nomenclature...also not covered by second shorter TOC
\listoftoc[Short Contents]{stoc}
\tableofcontents
\listoffigures
\listoftables
\chapter{Introduction}
\section{First Section}
\begin{table}
  \caption{Caption of a Table}
\end{table}
\begin{figure}
  \caption{Caption of a Figure}
\end{figure}
\section{Second Section}
\end{document}

enter image description here

Note that the patch of \addtocentrydefault only affects ToC entries done by this command or by \addchaptertocentry or \addxcontentsline{toc}{chapter}{...}. If other packages use \addcontentsline directly, you will not get an entry in the short ToC automatically.

Then it could be better to use the scrwfile solution:

\documentclass[listof=totoc]{scrreprt}
\usepackage[english]{babel}
%\usepackage{caption}% not needed in the example
\usepackage{scrwfile}
\TOCclone[Short Contents]{toc}{stoc}
\addtocontents{stoc}{\protect\value{tocdepth}=0}% or \BeforeStartingTOC[stoc]{\value{tocdepth}=0}
\AfterTOCHead[toc]{\addxcontentsline{stoc}{chapter}{\contentsname}}% TOC entry in short TOC
\usepackage[colorlinks = true,linkcolor = black]{hyperref}

\begin{document}
Here is the Nomenclature...also not covered by second shorter TOC
\listoftoc[Short Contents]{stoc}
\tableofcontents
\listoffigures
\listoftables
\chapter{Introduction}
\section{First Section}
\begin{table}
  \caption{Caption of a Table}
\end{table}
\begin{figure}
  \caption{Caption of a Figure}
\end{figure}
\section{Second Section}
\end{document}
esdd
  • 85,675
  • Thanks a lot, the example works. I tried scrwfile but the log throws a big warning that this is still in alpha and should be used with caution/there is no support. One problem I encountered is that the TOC is now missing in the bookmarks (of the PDF). Can this be fixed? And one more thing to ask is if the TOC can link on the second TOC (and vice versa) – EtoAls May 28 '20 at 12:33
  • To add to my comment: I found that \usepackage{tocbibind} helps and I need this to reference the bibliography also. But when I use it, the TOC is not listed in the second (short) TOC anymore. How can I have the shorter TOC behave exactly like the larger - I mean contain a link to itself and the larger TOC? – EtoAls May 28 '20 at 15:39
  • You do not need package tocbibind with a KOMA-Script class. Use options bibliography=totoc and index=totoc. – esdd May 28 '20 at 16:15
  • See my updated answer. – esdd May 28 '20 at 17:22
  • thank you so much. Now all works out as intended – EtoAls May 28 '20 at 18:04