I have a problem with my LaTeX document. It either prints out the wrong page number of the chapter of my sources (Version 1), or it jumps to the wrong page (Version 2). (Minimal reproducible example below)
Version 1: Whenever I click on "Literatur", it jumps to the previous chapter and not to the chapter I want, but at least it prints out the correct page number in my table of contents.
\newpage
\setstretch{1.5}
\fancypagestyle{plain}{
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\normalsize \bfseries \thepage}
\fancyhead[L]{\normalsize \bfseries Literatur}
\renewcommand{\headrulewidth}{0.75pt}
\renewcommand{\footrulewidth}{0pt}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\pagestyle{plain}
\addcontentsline{toc}{chapter}{Literatur}
\printbibliography
Version 2: Whenever I click on "Literatur", it jumps to the correct chapter, but it prints out the wrong page number in my table of contents. It doesn't print out the first page number of this chapter but the last page number.
\newpage
\setstretch{1.5}
\fancypagestyle{plain}{
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\normalsize \bfseries \thepage}
\fancyhead[L]{\normalsize \bfseries Literatur}
\renewcommand{\headrulewidth}{0.75pt}
\renewcommand{\footrulewidth}{0pt}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\pagestyle{plain}
\printbibliography
\addcontentsline{toc}{chapter}{Literatur}
I have already tried adding \phantomsection and \cleardoublepage in every line possible, but they don't seem to work.
In case it's important, this is the class I'm using:
\documentclass[fontsize=11pt,paper=a4,oneside,toc=listof,listof=totocnumbered,ngerman]{scrreprt}
And I can't change the class or all of the stuff before \printbibliography because it's the template of my university. I also can't add all of the sources manually (I've seen this in some answers) because I have over 200 sources.
I appreciate any help that you can provide because I'm running out of ideas and I have to give in my thesis soon! :)
Minimal reproducible example
bibliography.bib path: content/bib/bibliography.bib
@misc{a,
author = {a},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{b,
author = {b},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{c,
author = {c},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{d,
author = {d},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{e,
author = {e},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{f,
author = {f},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{g,
author = {g},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{h,
author = {h},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{i,
author = {i},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{j,
author = {j},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
main.tex (Version 1)
\documentclass[fontsize=11pt,paper=a4,oneside,toc=listof,listof=totocnumbered,ngerman]{scrreprt}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[babel,german=guillemets]{csquotes}
\usepackage[sfdefault]{FiraSans}
\usepackage[T1]{fontenc}
\renewcommand*\oldstylenums[1]{{\firaoldstyle #1}}
%SPACING
\usepackage{setspace}
\setstretch{1,3}
%PAGE SETUP
\usepackage{pdflscape}
%margins
\usepackage[paper=a4paper,left=25mm,right=25mm,top=25mm,bottom=20mm]{geometry}
%header footer
\usepackage{fancyhdr} % header field
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\normalsize \bfseries \thepage}
\fancyhead[L]{\normalsize \bfseries \thechapter \hspace{0.5em}\leftmark}
\renewcommand{\headrulewidth}{0.75pt}
\renewcommand{\footrulewidth}{0pt}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}
}
%BIBLIOGRAPHY
\usepackage{bibgerm}
\usepackage[sortcites,style=numeric,sorting=none,backend=biber]{biblatex}
\IfFileExists{content/bib/bibliography_final.bib}
{\bibliography{content/bib/bibliography_final.bib}}%
{%
\IfFileExists{content/bib/bibliography.bib}%
{\bibliography{content/bib/bibliography.bib}}%
{%
\typeout{bibliography not found, using empty!}%
\bibliography{content/bib/empty.bib}%
}%
}%
%HYPERLINKS BOOKMARKS
\usepackage{hyperref} %Links
\hypersetup{colorlinks =false,linkbordercolor = {0 0 0},linktoc = all,pdfborder = {0 0 0},bookmarksdepth = subsection,bookmarksnumbered = true}
\urlstyle{same}
\usepackage[]{bookmark}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\tableofcontents
\chapter{Chapter}
Text \cite{a,b,c,d,e,f,g,h,i,j}
\section{Section}
More text
\newpage
\setstretch{1.5}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\normalsize \bfseries \thepage}
\fancyhead[L]{\normalsize \bfseries Literatur}
\renewcommand{\headrulewidth}{0.75pt}
\renewcommand{\footrulewidth}{0pt}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\pagestyle{plain}
\addcontentsline{toc}{chapter}{Literatur}
\printbibliography
\end{document}
main.tex (Version 2)
\documentclass[fontsize=11pt,paper=a4,oneside,toc=listof,listof=totocnumbered,ngerman]{scrreprt}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[babel,german=guillemets]{csquotes}
\usepackage[sfdefault]{FiraSans}
\usepackage[T1]{fontenc}
\renewcommand*\oldstylenums[1]{{\firaoldstyle #1}}
%SPACING
\usepackage{setspace}
\setstretch{1,3}
%PAGE SETUP
\usepackage{pdflscape}
%margins
\usepackage[paper=a4paper,left=25mm,right=25mm,top=25mm,bottom=20mm]{geometry}
%header footer
\usepackage{fancyhdr} % header field
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\normalsize \bfseries \thepage}
\fancyhead[L]{\normalsize \bfseries \thechapter \hspace{0.5em}\leftmark}
\renewcommand{\headrulewidth}{0.75pt}
\renewcommand{\footrulewidth}{0pt}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}
}
%BIBLIOGRAPHY
\usepackage{bibgerm}
\usepackage[sortcites,style=numeric,sorting=none,backend=biber]{biblatex}
\IfFileExists{content/bib/bibliography_final.bib}
{\bibliography{content/bib/bibliography_final.bib}}%
{%
\IfFileExists{content/bib/bibliography.bib}%
{\bibliography{content/bib/bibliography.bib}}%
{%
\typeout{bibliography not found, using empty!}%
\bibliography{content/bib/empty.bib}%
}%
}%
%HYPERLINKS BOOKMARKS
\usepackage{hyperref} %Links
\hypersetup{colorlinks =false,linkbordercolor = {0 0 0},linktoc = all,pdfborder = {0 0 0},bookmarksdepth = subsection,bookmarksnumbered = true}
\urlstyle{same}
\usepackage[]{bookmark}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\tableofcontents
\chapter{Chapter}
Text \cite{a,b,c,d,e,f,g,h,i,j}
\section{Section}
More text
\newpage
\setstretch{1.5}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\normalsize \bfseries \thepage}
\fancyhead[L]{\normalsize \bfseries Literatur}
\renewcommand{\headrulewidth}{0.75pt}
\renewcommand{\footrulewidth}{0pt}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\pagestyle{plain}
\printbibliography
\addcontentsline{toc}{chapter}{Literatur}
\end{document}
You can use \phantomsection
before the \addcontentsline{toc}{chapter}{Literatur}
line to give hyperref something it can jump to.
Please also note, that the biblatex syntax for adding a bib file is \addbibressource
instead of \bibliography
\documentclass[fontsize=11pt,paper=a4,oneside,toc=listof,listof=totocnumbered,ngerman]{scrreprt}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[babel,german=guillemets]{csquotes}
\usepackage[sfdefault]{FiraSans}
\usepackage[T1]{fontenc}
\renewcommand*\oldstylenums[1]{{\firaoldstyle #1}}
%SPACING
\usepackage{setspace}
\setstretch{1,3}
%PAGE SETUP
\usepackage{pdflscape}
%margins
\usepackage[paper=a4paper,left=25mm,right=25mm,top=25mm,bottom=20mm]{geometry}
%header footer
\usepackage{fancyhdr} % header field
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\normalsize \bfseries \thepage}
\fancyhead[L]{\normalsize \bfseries \thechapter \hspace{0.5em}\leftmark}
\renewcommand{\headrulewidth}{0.75pt}
\renewcommand{\footrulewidth}{0pt}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}
}
\begin{filecontents*}[overwrite]{\jobname.bib}
@misc{a,
author = {a},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{b,
author = {b},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{c,
author = {c},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{d,
author = {d},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{e,
author = {e},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{f,
author = {f},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{g,
author = {g},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{h,
author = {h},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{i,
author = {i},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
@misc{j,
author = {j},
title = {asdfs},
url = {https://stackoverflow.com/questions/73990151/bibliography-in-latex-either-has-a-wrong-number-or-reference-is-wrong-how-can-i?noredirect=1#comment130644039_73990151}
}
\end{filecontents*}
%BIBLIOGRAPHY
\usepackage{bibgerm}
\usepackage[sortcites,style=numeric,sorting=none,backend=biber]{biblatex}
\addbibresource{\jobname.bib}
%HYPERLINKS BOOKMARKS
\usepackage{hyperref} %Links
\hypersetup{colorlinks =false,linkbordercolor = {0 0 0},linktoc = all,pdfborder = {0 0 0},bookmarksdepth = subsection,bookmarksnumbered = true}
\urlstyle{same}
\usepackage[]{bookmark}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\tableofcontents
\chapter{Chapter}
Text \cite{a,b,c,d,e,f,g,h,i,j}
\section{Section}
More text
\newpage
\setstretch{1.5}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[R]{\normalsize \bfseries \thepage}
\fancyhead[L]{\normalsize \bfseries Literatur}
\renewcommand{\headrulewidth}{0.75pt}
\renewcommand{\footrulewidth}{0pt}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\pagestyle{plain}
\phantomsection
\addcontentsline{toc}{chapter}{Literatur}
\printbibliography
\end{document}