1

I have a big document which consists of several parts and inside them several chapters. It has a common ToC at the beginning, which only shows the parts, and then each part has its own ToC. When I put the bibliography with \printbibliography, the bibliography is put as a chapter so it shows on the ToC of the last part, and I would like to have it at the first ToC, with all the parts.

Here is my MWE, which, as I said, shows the bibliography on the last part:

\documentclass[toc=bibliography]{scrbook}
\usepackage[backend=biber,style=ieee,bibliography=totoc,dashed=false]{biblatex}
\urlstyle{same}
\addbibresource{bibliography.bib}
\usepackage[final]{pdfpages}
\usepackage{xpatch}
\usepackage{xparse}

% Partial TOC
\makeatletter
\newif\ifuseparttoc
\newcommand*{\parttoc}[1][\thepart]{% new command to generate and show a chapter toc
  \useparttoctrue% switch on part-toc-entries
  \edef\ext@parttoc{tcp#1}% extension of the part-toc-file, e.g., tcpI
  \DeclareNewTOC[
    listname=Table of Contents,
    %unset=onecolumn% if the part toc should use twocolumn
  ]{\ext@parttoc}% declare a new toc file
  \begingroup
    \value{tocdepth}=\paragraphtocdepth% we want entries down to chapter
    \listoftoc{\ext@parttoc}% show the toc with header
  \endgroup
}
\xapptocmd\addtocentrydefault{% patch the KOMA-Script's generic toc entry generator
  \ifuseparttoc% if part toc entries should be generated
    \expandafter\tocbasic@addxcontentsline\expandafter{\ext@parttoc}{#1}{#2}{#3}% do it
  \fi
}{}{}
\xpretocmd\part{\useparttocfalse}{}{}% entries in part toc are automatically switched off at start of \part
\newif\ifusechaptertoc% Switch to tell \addtocentrydefault to not only make entries to the toc-file but also to the current section-toc-file

\xapptocmd\addtocentrydefault{% patch the KOMA-Script's generic toc entry generator
  \ifusechaptertoc% if chapter toc entries should be generated
    \Ifstr{#1}{chapter}{}
      {\expandafter\tocbasic@addxcontentsline\expandafter{\ext@chaptoc}{#1}{#2}{#3}}% do it
  \fi
}{}{}
\xpretocmd\part{\usechaptertocfalse}{}{}% entries in part toc are automatically switched off at start of \part
\makeatother

\setcounter{tocdepth}{\partnumdepth}% depth of TOC

\begin{document}
    \tableofcontents
    \part{PART 1}
    \parttoc
    \chapter{smth}
    something on new chapter \autocite{Ambit2019-rj}
    \part{PART 2}
    \parttoc
    \chapter{somethung}
    New chapter.
    \printbibliography
\end{document}
2
  • Please, make your code a MWE (minimal working example) following the demands you find here: tex.meta.stackexchange.com/q/228/231952. For the creation of a MWEB (minimal working example with Bibliography) see also: tex.meta.stackexchange.com/a/4408/231952
    – Ivan
    Dec 19, 2021 at 21:09
  • Thank you for your feedback, as you can see this is my first time posting, so this is very useful information!
    – Ana
    Dec 19, 2021 at 22:14

1 Answer 1

1

biblatex's default bibliography headings are usually \chapter/\section-based. If you want your bibliography to be a \part you may have to redefine the heading definition with \defbibheading.

In a KOMA-Script class you probably want to use \addpart for an unnumbered part with ToC entry.

\documentclass[toc=bibliography]{scrbook}
\usepackage[backend=biber,style=ieee,bibliography=totoc,dashed=false]{biblatex}
\urlstyle{same}

\usepackage{xpatch}

\defbibheading{bibliography}[\bibname]{\addpart{#1}}

% Partial TOC
\makeatletter
\newif\ifuseparttoc
\newcommand*{\parttoc}[1][\thepart]{% new command to generate and show a chapter toc
  \useparttoctrue% switch on part-toc-entries
  \edef\ext@parttoc{tcp#1}% extension of the part-toc-file, e.g., tcpI
  \DeclareNewTOC[
    listname=Table of Contents,
    %unset=onecolumn% if the part toc should use twocolumn
  ]{\ext@parttoc}% declare a new toc file
  \begingroup
    \value{tocdepth}=\paragraphtocdepth% we want entries down to chapter
    \listoftoc{\ext@parttoc}% show the toc with header
  \endgroup
}
\xapptocmd\addtocentrydefault{% patch the KOMA-Script's generic toc entry generator
  \ifuseparttoc% if part toc entries should be generated
    \expandafter\tocbasic@addxcontentsline\expandafter{\ext@parttoc}{#1}{#2}{#3}% do it
  \fi
}{}{}
\xpretocmd\part{\useparttocfalse}{}{}% entries in part toc are automatically switched off at start of \part
\newif\ifusechaptertoc% Switch to tell \addtocentrydefault to not only make entries to the toc-file but also to the current section-toc-file

\xapptocmd\addtocentrydefault{% patch the KOMA-Script's generic toc entry generator
  \ifusechaptertoc% if chapter toc entries should be generated
    \Ifstr{#1}{chapter}{}
      {\expandafter\tocbasic@addxcontentsline\expandafter{\ext@chaptoc}{#1}{#2}{#3}}% do it
  \fi
}{}{}
\xpretocmd\part{\usechaptertocfalse}{}{}% entries in part toc are automatically switched off at start of \part
\makeatother

\setcounter{tocdepth}{\partnumdepth}% depth of TOC

\addbibresource{biblatex-examples.bib}

\begin{document}
  \tableofcontents
  \part{PART 1}
  \parttoc
  \chapter{smth}
  something on new chapter \autocite{sigfridsson}
  \part{PART 2}
  \parttoc
  \chapter{somethung}
  New chapter.
  \printbibliography
\end{document}

Part ToC showing the bibliography.

1
  • Thank you so much for your answer! It worked like a charm!
    – Ana
    Dec 19, 2021 at 22:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .