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 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
\g@addto@macro\appendix{%
\counterwithin{table}{chapter}
\renewcommand*{\tableformat}{\tablename~\thetable}
\let\oldaddcontentsline\addcontentsline
\newcommand\hackedaddcontentsline[3]{\oldaddcontentsline{loa}{#2}{#3}}
%
%\newcommand\hackedtableaddcontentsline[3]{\oldaddcontentsline{loa}{#2}{\tableformat}}
%
\newcommand\hackedtableaddcontentsline[3]{\oldaddcontentsline{loa}{#2}{#3}}
%
\let\oldpart\part
\renewcommand*\part[1]{%
\let\addcontentsline\hackedaddcontentsline%
\oldpart{#1}%
\let\addcontentsline\oldaddcontentsline%
}
\let\oldchapter\chapter
\renewcommand*\chapter[1]{%
\let\addcontentsline\hackedaddcontentsline%
\oldchapter{#1}%
\let\addcontentsline\oldaddcontentsline%
}
\let\oldsection\section
\renewcommand*\section[1]{%
\let\addcontentsline\hackedaddcontentsline%
\oldsection{#1}%
\let\addcontentsline\oldaddcontentsline%
}
\let\oldsubsection\subsection
\renewcommand*\subsection[1]{%
\let\addcontentsline\hackedaddcontentsline%
\oldsubsection{#1}%
\let\addcontentsline\oldaddcontentsline%
}
\let\oldsubsubsection\subsubsection
\renewcommand*\subsubsection[1]{%
\let\addcontentsline\hackedaddcontentsline%
\oldsubsubsection{#1}%
\let\addcontentsline\oldaddcontentsline%
}
\let\oldtable\table
\renewcommand*\table{%
\let\addcontentsline\hackedtableaddcontentsline%
\oldtable%
}
\let\oldendtable\endtable
\renewcommand*\endtable{%
\oldendtable%
\let\addcontentsline\oldaddcontentsline%
}
}
\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]{%
       \setunit{\addcomma\space}%
       \iffieldsequal{year}{\thefield{datelabelsource}year}
         {\printdateextralabel}%
         {\printfield{labelyear}%
          \printfield{extrayear}}}}%}%

\renewbibmacro*{publisher+location+date}{%
%
  \printlist{publisher}%
  \setunit*{\addcomma\space}%
  %\printlist{publisher}% 
  %\setunit*{\addperiod\space}% 
%
  \printlist{location}%
  \setunit*{\addcomma\space}
  \usebibmacro{date}%
  \newunit}

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

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

\renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
  \setunit*{\addspace}%
  \printfield[parens]{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}


\begin{document}

\tableofcontents     
\listoftables 
\addcontentsline{toc}{chapter}{List of tables}


\nocite{*}
\printbibliography[title={References}]
\addcontentsline{toc}{chapter}{References}

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

\end{document}
share|improve this question
    
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 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 at 1:56
    
add comment

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer
    
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 at 17:23
1  
@TomM -- it's a little more complicated than that. i'll add an edit to the answer. –  barbara beeton Jan 18 at 17:25
    
Thanks for the explanation :) –  TomM Jan 18 at 18:06
add comment

The Koma-Script classes already have facilities for adding standard material to the table of contents.

If you call the class like

\documentclass[
  a4paper,
  12pt,
  headsepline,
  headings=small,
  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
\g@addto@macro\appendix{%
  \counterwithin{table}{chapter}%
  \renewcommand*{\tableformat}{\tablename~\thetable}%
  \let\oldaddcontentsline\addcontentsline
  \renewcommand\addcontentsline[1]{\oldaddcontentsline{loa}}%
}
\makeatother
share|improve this answer
    
Thanks for some very interesting information besides a working solution! :) I assume the question you have asked is adressed to @karlkoeller –  TomM Jan 18 at 18:09
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.