10

I have this document with a huge numbered bibliography e.g. from 1 to 600. I would like the first and the last reference number of the page to be inserted in the heading of the page. Like in the following example:

enter image description here

I am using fancyhdr has explained in this answer.

\documentclass[a4,11pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[LE]{\slshape My text}
\fancyhead[RE]{}
\fancyhead[LO]{\hfill \slshape \leftmark}

\renewcommand{\headrulewidth}{0pt}

\usepackage{kantlipsum}

\title{My title}
\author{My name}
\date{}

\begin{document}

\renewcommand{\headrulewidth}{.4pt}

\chapter{example}

\kant[1-3]\clearpage

\fancyhead[LE]{\slshape BIBLIOGRAPHY 19 - 42}

\begin{thebibliography}{99}

\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}
\bibitem{example}

\end{thebibliography}

\end{document}

Is it possible to have a method that works also with \usepackage[backend=biber]{biblatex}?

marked as duplicate by G M, schtandard, Raaja, Community Sep 25 at 8:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

12

biblatex

Here is a solution for biblatex. We can (ab)use the mark mechanism, each entry sets the marks and then the header grabs \rightmark and \leftmark, which contain the first and last reference number on each page.

\documentclass[british]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=numeric, backend=biber]{biblatex}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[LE]{\slshape My text}
\fancyhead[RE]{}
\fancyhead[LO]{\hfill \slshape \leftmark}

\defbibheading{bibliography}[\bibname]{%
  \chapter*{#1}%
  \fancyhead{}%
  \fancyhead[RO,LE]{#1 \rightmark{} -- \leftmark}}

\makeatletter
\providecommand*{\@mkdouble}[1]{\@mkboth{#1}{#1}}

\newcommand*{\markbib}{%
  \@mkdouble{\thefield{labelprefix}\thefield{labelnumber}}}
\makeatother

\renewbibmacro*{begentry}{\markbib}


\addbibresource{biblatex-examples.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

Header with citation numbers.


thebibliography/BibTeX

A structurally similar approach works for standard thebibliography (the definitions may need to be adjusted if you use a different document class or a more sophisticated bibliography package like natbib).

Things get a bit more @y because we have to redefine the complete thebibliography environment in order to change the headers and \@lbibitem as well as \@bibitem to get the citation label into the mark mechanism.

\documentclass[british]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}


\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[LE]{\slshape My text}
\fancyhead[RE]{}
\fancyhead[LO]{\hfill \slshape \leftmark}

\makeatletter
% \@lbibitem & \@bibitem from latex.ltx
% the only change apart from indentation is the addition of \markbib
\def\@lbibitem[#1]#2{%
  \item[\@biblabel{#1}\hfill]%
  \markbib{#1}% <-- added
  \if@filesw
    {\let\protect\noexpand
     \immediate\write\@auxout
       {\string\bibcite{#2}{#1}}}%
  \fi
  \ignorespaces}
\def\@bibitem#1{%
  \item
  \markbib{\the\value{\@listctr}}% <-- added
  \if@filesw
    \immediate\write\@auxout
       {\string\bibcite{#1}{\the\value{\@listctr}}}%
  \fi
  \ignorespaces}

% from book.cls
% only change was to add the two \fancyhead calls
\renewenvironment{thebibliography}[1]
     {\chapter*{\bibname}%
      \fancyhead{}% <-- added
      \fancyhead[RO,LE]{\bibname{} \rightmark{} -- \leftmark}% <-- added
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}

\providecommand*{\@mkdouble}[1]{\@mkboth{#1}{#1}}

\newcommand*{\markbib}{\@mkdouble}
\makeatother


\begin{document}
\nocite{*}
\begin{thebibliography}{99}

\bibitem{example01}
\bibitem{example02}
\bibitem{example03}
\bibitem{example04}
\bibitem{example05}
\bibitem{example06}
\bibitem{example07}
\bibitem{example08}
\bibitem{example09}
\bibitem{example10}
\bibitem{example11}
\bibitem{example12}
\bibitem{example13}
\bibitem{example14}
\bibitem{example15}
\bibitem{example16}
\bibitem{example17}
\bibitem{example18}
\bibitem{example19}
\bibitem{example20}
\bibitem{example21}
\bibitem{example22}
\bibitem{example23}
\bibitem{example24}
\bibitem{example25}
\bibitem{example26}
\bibitem{example27}
\bibitem{example28}
\bibitem{example29}
\bibitem{example30}
\bibitem{example31}
\bibitem{example32}
\bibitem{example33}
\bibitem{example34}
\bibitem{example35}
\bibitem{example36}
\bibitem{example37}
\bibitem{example38}
\bibitem{example39}
\bibitem{example40}
\bibitem{example41}
\bibitem{example42}
\bibitem{example43}
\bibitem{example44}
\bibitem{example45}
\bibitem{example46}
\bibitem{example47}

\end{thebibliography}
\end{document}

Not the answer you're looking for? Browse other questions tagged or ask your own question.