0

I read the following post on how to add an author-year block to each bibliography entry: Adding an [AuthorYear] block at the beginning of bibliography entries. My code looks just like it does in the solution.

At the moment my bibliography looks like this: momentan

It comes very close to what my bibliography should look like. However I would like to change the indentation of the second line of each bibliography entry, so that it is in line with the fist line of the bibliography entry.

Alternatively it would also work to create a fixed block for the bibliography entries similar to this: Creating a bibliography with fixed indention and authoryear labels using biblatex and biber. That solution doesn't work for me, because it uses the horizontal space between label and bibliography entry.

If I use this solution, it looks like this: loesungtest

From what I understand, it isn't possible to customize a label so that it looks like the author year block. That's why it was added additionally. As we can see, the second entry seems to have a label additionally to the author year block.

I would like to have a similar look with an author year block instead of a label.

The solution by moewe looks like this: (note: I only used moewe's new code without the code from Adding an [AuthorYear] block at the beginning of bibliography entries)

enter image description here

SOLUTION: For everyone interested, the missing label was due to two lines of additional code needed if you use the authoryear-icomp style.

This is my code with moewes solution:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}

\usepackage[
backend=biber,
citestyle=authoryear-icomp,
bibstyle=authortitle,
sorting=nyt,
firstinits=true,
sortlocale=de_DE,
hyperref=true,
url=true,
doi=false,
eprint=false,
maxcitenames=1,
useprefix=true
]{biblatex}


\DeclareNameAlias{sortname}{last-first}

\addbibresource{Literatur.bib}

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

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

\newbibmacro{labelwidthbib}{%
  \begingroup
  \DeclareFieldFormat{bibhyperref}{##1}%
  \csuse{blx@hook@cite}%
  \csuse{blx@hook@citekey}%
  \global\undef\cbx@lasthash
  \global\undef\cbx@lastyear
  \citetrackerfalse\pagetrackerfalse\backtrackerfalse
  \defcounter{maxnames}{\blx@maxcitenames}%
  \printtext[brackets]{\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


\DefineBibliographyStrings{ngerman}{andothers = {{et\,al\adddot}},}%et al  statt u.a.


\begin{document}

%Testcitation
\textcite{Gluck.1991}
\parencite{Best.2016a}

\newpage

\printbibliography

\end{document}

This is the .bib file:

@misc{Best.2016a,
 author = {Best, Isabelle and Orozaliev, Janybek},
 title = {{Renewable Low-Temperature District Heating for a New Housing   Area in Kassel, Germany -- A Case Study of IEA EBC Annex 64}},
 abstract = {},
 date = {2016-05-25},
 pagerange = {14},
}


@book{Gluck.1991,
 author = {Gl{\"u}ck, Bernd},
 year = {1991},
 title = {{Zustands- und Stoffwerte}},
 edition = {2., bearb. u. erw. Aufl.},
 publisher = {{Verlag f{\"u}r Bauwesen GmbH}},
 isbn = {3-345-00487-9},
 subtitle = {{Wasser, Dampf, Luft ; Verbrennungsrechnung}},
 location = {Berlin},
 series = {{Bausteine der Heizungstechnik}},
 abstract = {},
 pagetotal = {140},
}
  • 1
    I don't quite understand why the second solution does not work for you. Specifically, what is the difference between the 'label' and 'author year block'. Maybe you can explain what would have to be different. Ideally with a picture mock-up what you have now and what needs to be changed. – moewe Jul 26 '17 at 10:39
  • I think you want \setlength{\bibhang}{0pt}. If you want space between the entries increase \bibitemsep. – David Purton Jul 26 '17 at 11:33
  • What if you use only the code from the second link and not the first link? – moewe Jul 26 '17 at 11:37
  • @David Purton The \setlength{\bibhang}{0pt} doesn't do what I want, because it only changes the second line. – Weena Jul 26 '17 at 12:07
  • @Weena, no worries. I misunderstood question. – David Purton Jul 26 '17 at 12:11
3

Try a slightly modified version of my answer to Creating a bibliography with fixed indention and authoryear labels using biblatex and biber

\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{parencite}%
  \DeclareFieldFormat{bibhyperref}{##1}%
  \csuse{blx@hook@cite}%
  \csuse{blx@hook@citekey}%
  \global\undef\cbx@lasthash
  \global\undef\cbx@lastyear
  \citetrackerfalse\pagetrackerfalse\backtrackerfalse
  \defcounter{maxnames}{\blx@maxcitenames}%
  \printtext[brackets]{\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}

enter image description here

  • Thank you, this is exactly what I want. However one of my entries seems to have no label, any idea why? – Weena Jul 26 '17 at 12:05
  • @Weena Please show an MWE/MWEB of the problematic entry. – moewe Jul 26 '17 at 12:16
  • I posted a MWE in my question. – Weena Jul 26 '17 at 12:51
  • 1
    @Weena If the solution is helpful then you should up-vote it (not up-voting does not incentivize the poster to answer follow-up questions in the comments). If the solution answers your question and you think it the best answer you should also give a a green tick. – Andrew Jul 26 '17 at 13:25
  • @moewe I already tried to do that but it seems I don't have enough reputation, so that it is shown. Sorry, your answer is really helpful! – Weena Jul 26 '17 at 13:28

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.