3

I am using biblatex and biber with the authoryear styles for my documents. Now I've been asked to format my bibliography like this: enter image description here

It looks like a mixture of the numeric style (labels left of the entry) and authoryear. However, the length of the label is much longer and might for the first line of the entry to wrap. How can I archieve this?

5

edit: biblatex-ext has this function built in as introcite=label. And so the code below can be replaced with

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[style=ext-authoryear, backend=biber, introcite=label, dashed=false]{biblatex}
\addbibresource{biblatex-examples.bib}

\setlength{\bibitemsep}{0.5\baselineskip plus 0.5\baselineskip}
\setlength{\introcitewidth}{6em}

\begin{document}
\cite{sigfridsson,worman,geer,knuth:ct:a}
\printbibliography
\end{document}

The styles of biblatex-ext can be used as drop-in replacements of the corresponding standard styles.

Try this

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear,backend=biber,dashed=false]{biblatex}
\addbibresource{biblatex-examples.bib}

\makeatletter
\setlength{\bibitemsep}{0.5\baselineskip plus 0.5\baselineskip}

\newsavebox\ay@labelbox
\newlength{\labwidthsameline}
\setlength{\labwidthsameline}{6em}

\newbibmacro{labelwidthbib}{%
  \begingroup
  \delimcontext{cite}%
  \DeclareFieldFormat{bibhyperref}{##1}%
  \csuse{blx@hook@cite}%
  \csuse{blx@hook@citekey}%
  \citetrackerfalse\pagetrackerfalse\backtrackerfalse
  \defcounter{maxnames}{\blx@maxcitenames}%
  \usebibmacro{cite}%
  \endgroup
} 
%-----------------------
\newbibmacro{kicklabel}{% 
  \sbox\ay@labelbox{\usebibmacro{labelwidthbib}}%
  \global\togglefalse{blx@insert}%
  \ifdim\wd\ay@labelbox>\labwidthsameline
    \leavevmode\newline
  \fi
}

\defbibenvironment{bibliography}%
  {\list
    {\usebibmacro{labelwidthbib}}%
    {\setlength{\labelwidth}{\labwidthsameline}%
     \setlength{\leftmargin}{\labelwidth}%
     \setlength{\labelsep}{\biblabelsep}%
     \addtolength{\leftmargin}{\labelsep}%
     \setlength{\itemsep}{\bibitemsep}%
     \setlength{\parsep}{\bibparsep}%
     \renewcommand*{\makelabel}[1]{##1\hss}}}%
  {\endlist}%
  {\item\usebibmacro{kicklabel}}
\makeatother

\begin{document}
\cite{sigfridsson,worman,geer,knuth:ct:a}
\printbibliography
\end{document}

example output

This is inspired largely by https://github.com/LukasCBossert/biblatex-archaeologie/issues/79 and https://github.com/LukasCBossert/biblatex-archaeologie/issues/58

  • This is great and the code I am using. How would we modify it so that the YEAR label goes to the second line (of the left-hand tag area)? – Gyalten Jigdrel Dec 17 '17 at 14:21
  • @GyaltenJigdrel Please ask a new question about that. – moewe Dec 18 '17 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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