# Wrong page number of References in toc (scrreprt)

I got a problem with one page number in the toc: the one of the 'References' generated by biblatex. I am always using the command \addcontentsline{toc}{chapter}{title} to add stuff to the TOC, and in all other cases it worked fine (list of tables etc.).

Problem description: The page number in the toc is always the last page of the References. This means if the References are from page 80 to page 84, then in the TOC page 84 is used (instead of page 80 where the References begin).

edit: KOMA script provides bibliography=totoc which solves the issue. However, if anyone could explain why \addcontentsline{toc}{chapter}{title} works for other lists but not for the library, I would be thankful.

I cannot hand out my lib-file (named Lib1 in the code), but you could simply import one of yours which is a few pages long to see the problem.

Here is my preamble. As I don't know what the reason is, I have kept most of the definitions and macros generated from helpful users of these forums in. I only removed stuff which I was certain that it is harmless (e.g. table definitions etc.). The appendices have been made by @karlkoeller. But I don't think they are the problem because they start after the bibliography.

Thanks for any help!

\documentclass[a4paper, 12pt, headsepline, headings=small, numbers=noendperiod]{scrreprt}
\usepackage{float}
\usepackage[onehalfspacing]{setspace}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}
\usepackage[a4paper,showframe]{geometry}
\geometry{left=2cm,right=5cm,top=2cm,bottom=2cm,foot=1.5cm}
\usepackage{csquotes}
\usepackage{environ}
\usepackage[backend=bibtex8,
style=authoryear-icomp,
dashed=false,
autocite=footnote,
maxcitenames=3,
mincitenames=1,
maxbibnames=100,
firstinits=true,
sorting=nyvt
]{biblatex}
\bibliography{Lib1}
\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\counterwithout{equation}{chapter}
\counterwithout{footnote}{chapter}
\renewcommand{\floatpagefraction}{0.85}
\renewcommand\bottomfraction{0.65}
\setcounter{topnumber}{1}

\newcommand\appendicesname{Appendix}
\newcommand\listofloaname{List of Appendices}
\newcommand*{\listofappendices}{\listoftoc{loa}}
\setuptoc{loa}{totoc}

\makeatletter
\counterwithin{table}{chapter}
\renewcommand*{\tableformat}{\tablename~\thetable}
%
%
%
\let\oldpart\part
\renewcommand*\part[1]{%
\oldpart{#1}%
}
\let\oldchapter\chapter
\renewcommand*\chapter[1]{%
\oldchapter{#1}%
}
\let\oldsection\section
\renewcommand*\section[1]{%
\oldsection{#1}%
}
\let\oldsubsection\subsection
\renewcommand*\subsection[1]{%
\oldsubsection{#1}%
}
\let\oldsubsubsection\subsubsection
\renewcommand*\subsubsection[1]{%
\oldsubsubsection{#1}%
}
\let\oldtable\table
\renewcommand*\table{%
\oldtable%
}
\let\oldendtable\endtable
\renewcommand*\endtable{%
\oldendtable%
}
}
\makeatother

\newlength\myindention
\setlength\myindention{1em}
\let\oldcaption\caption
\renewcommand*\caption[2][]{%
\oldcaption[#1]{#1\\\hspace*{\myindention}#2}%
}

% Biblatex:

\DeclareNameAlias{sortname}{last-first}
\DeclareNameAlias{default}{last-first}

\DeclareFieldFormat{title}{#1}
\DeclareFieldFormat
[article,inbook,incollection,inproceedings,patent,thesis,unpublished]
{title}{#1}
\DeclareFieldFormat{journaltitle}{#1}
\renewbibmacro*{cite:labelyear+extrayear}{%
\iffieldundef{labelyear}
{}
{\printtext[bibhyperref]{%
\printtext[parens]{%
\printfield{labelyear}%
\printfield{extrayear}}}}}

\renewbibmacro*{date+extrayear}{%
\iffieldundef{\thefield{datelabelsource}year}
{}
{%\printtext[parens]{%
\iffieldsequal{year}{\thefield{datelabelsource}year}
{\printdateextralabel}%
{\printfield{labelyear}%
\printfield{extrayear}}}}%}%

\renewbibmacro*{publisher+location+date}{%
%
\printlist{publisher}%
%\printlist{publisher}%
%
\printlist{location}%
\usebibmacro{date}%
\newunit}

\renewbibmacro*{institution+location+date}{%
\printlist{institution}%
\printlist{location}%
\usebibmacro{date}%
\newunit}
\renewbibmacro*{organization+location+date}{%
\printlist{organization}%
\printlist{location}%
\usebibmacro{date}%
\newunit}

\renewbibmacro{in:}{%
\ifentrytype{article}{}{\printtext{\bibstring{in}\intitlepunct}}}

\renewbibmacro*{volume+number+eid}{%
\printfield{volume}%
\printfield[parens]{number}%
\printfield{eid}}

\begin{document}

\tableofcontents
\listoftables

\nocite{*}
\printbibliography[title={References}]

\listofappendices
\begin{appendix}
\setlength{\abovecaptionskip}{-8pt}
\chapter{Appendix Chapter}
\end{appendix}

\end{document}

-
Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. (I see, you did the last one already.) – Speravir Jan 18 '14 at 19:26
@Speravir I am a human and not a machine...I understand that conciseness is a good thing, but on the other hand 1 line saying 'thank you' doesn't add that much space. Most of the threads don't add any further communication once the answers have been provided anyway, right? Not giving thanks if someone helps you is -- to me -- a sign of bad behavior. – TomM Jan 19 '14 at 1:56
– Speravir Jan 19 '14 at 18:36

the \printbibliography command causes the entire bibliography to print, so issuing \addeontentsline after it will of course have the number of the last page.

i assume that the bibliography will start on a new right-hand page. so if you issue the command \cleardoublepage, then \addcontentsline, and then the \printbibliography, the entry in the contents should come out with the correct page number. if the document is one-sided, then \clearpage is sufficient.

(you have to run latex twice, of course.)

edit: it's been asked whether, if it's necessary to add a contents line for a chapter, should the \addcontentsline always be added before \chapter. the answer is, not usually.

in most document classes, \chapter issues a \clearpage (or \cleardoublepage) command, so if the \addcontentsline line precedes \chapter, the page number will be too low by one (or two). thus if you issue the \chapter command yourself, the \addcontents line should be placed right after it. this will rarely be necessary, of course, unless you're using a document class that doesn't automatically add a contents line for \chapter (as book does not for \chapter*).

\printbibliography is a special case -- the command includes the \chapter* but goes right ahead and processes the bibliography, without leaving a "hook" to allow an author to say "i want this chapter title in the table of contents". there are some packages that make this adjustment; the approach taken here does not use a separate package.

-
Thanks for the explanation. I am using a one-sided document, so I guess it would be clearpage instead. So I always have to put \addcontentsline before the chapter headings if I want to use it, correct? – TomM Jan 18 '14 at 17:23
@TomM -- it's a little more complicated than that. i'll add an edit to the answer. – barbara beeton Jan 18 '14 at 17:25
Thanks for the explanation :) – TomM Jan 18 '14 at 18:06

If you call the class like

\documentclass[
a4paper,
12pt,
numbers=noendperiod,
listof=totoc
]{scrreprt}


you won't need any \addcontentsline for \listoftables. For the references, use biblatex facilities:

\printbibliography[title={References},heading=bibintoc]


Note that the Koma-Script classes have their method for defining new floats. If you load also \usepackage{scrhack} before float, you'll avoid an annoying warning.

By the way, wouldn't the following be easier for adding the items in the appendix to the list of appendices?

\makeatletter
\counterwithin{table}{chapter}%
\renewcommand*{\tableformat}{\tablename~\thetable}%

You can just use \clearpage then \addcontentstoline then \listoftables .... like this.. it worked for me..
\addcontentstoline? – Christian Hupfer May 29 at 7:14