# How to add citation number to bibliography when using bibstyle=authoryear and justification issue

I am formatting citations for a journal that uses a variation of the Vancouver style. I am having two issues:

1. I need the citations in the bibliography to appear with their corresponding in-text citation number. For example, if in the text I cite "You are great (1)." I need the bibliography entry to be: "1. Author, B. ..."
2. In the bibliography, I need the citation to start right after the citation number and not indent when going to a second line.

The the first image shows how the citation should be formatted, and the second image shows how they are currently formatted.

First Image

Second Image

Changing bibstyle=authoryear to bibstyle=numeric produces the image below (image 3). I have the citation number, but now I am dealing with spacing issues. In addition, the authors first-name initials appear before their last name, which is the opposite of how I would like it. It would be perfect if I could make the citation information start immediately after the citation number and justify to the left and have the author's first name initials come after their last name, like in image one.

Third Image

As you can see, I am quite close, but I just can't figure out these last two issues. Here is my MWE for the second image:

\documentclass [12pt]{article}

\usepackage[
backend=bibtex8,
natbib=true,
citestyle=numeric,
isbn=false,
bibstyle=authoryear,
maxnames=3,
minnames=3,
firstinits=true, % Removes period after first name intial
terseinits=true, % Removes period after first name intial
sorting=none] % List citation in order they appear
{biblatex}

\DeclareFieldFormat{pages}{#1} % No prefix for the "pages" field in the bibliography
\renewcommand*{\revsdnamepunct}{} % Removing the comma after last name
\renewcommand*{\revsdnamepunct}{} % Removing the periods after first name intial
\renewcommand{\labelnamepunct}{\addspace} % Removes period after year in bibliography
\DeclareFieldFormat[article]{title}{#1}  % Remove quotes from journal title
\DeclareNameAlias{sortname}{last-first} % Lists all authors with last name first
\renewcommand*{\finalnamedelim}{\addspace\bibstring{and}\space}% removes comma after penultimate name

\usepackage{xpatch}

\xpatchbibmacro{name:andothers}{% maked the et al'' italicized in the bibliography
\bibstring{andothers}%
}{%
\bibstring[\emph]{andothers}%
}{}{}

\renewbibmacro{in:}{% Removes "In" from bibliography entries
\ifentrytype{article}{}{%
\printtext{\bibstring{in}\intitlepunct}}}

\usepackage{filecontents}
\begin{filecontents*}{example.bib}

@article{author2014,
author = {Author, A. B. and Author, A. B. and Author, A. B.},
journal = {Journal of the happy but frustrated biblatex user},
pages = {1070--1074},
title = {{Biblatex hurts so good}},
volume = {10},
date = {2014}
}
@article{author2013,
author = {Author, A. D. and Author, A. B. and Author, A. B.},
journal = {Journal of the happy but frustrated biblatex user},
pages = {1070--1074},
title = {{Biblatex hurts so good}},
volume = {10},
date = {2013}
}
\end{filecontents*}

\bibliography{example}

\begin{document}

Be excellent, Dudes \supercite{author2014,author2013}

\printbibliography

\end{document}

• Welcome to TeX SE! Thank you for providing a complete Minimal Working Example. You need style=numeric or bibstyle=numeric to get the labels printed in the bibliography. It makes no sense to use citestyle=numeric with bibstyle=authoryear. – cfr Mar 30 '14 at 18:26
• \defbibenvironment{bibliography} {\list {\printfield[labelnumberwidth]{labelnumber}} {\setlength{\labelwidth}{\labelnumberwidth}% \setlength{\leftmargin}{0pt}% \setlength{\labelsep}{\biblabelsep}% \setlength{\itemsep}{\bibitemsep}% \setlength{\itemindent}{\labelwidth}% \addtolength{\itemindent}{\labelsep}% \setlength{\parsep}{\bibparsep}}% \renewcommand*{\makelabel}[1]{\hss##1}} {\endlist} {\item} will deal with the spacing... – cfr Mar 30 '14 at 19:38

This answer incorporates the code from my comment and two elements from karlkoeller's answer:

• the redefinition of the label in the bibliography;
• sticking to bibstyle=authoryear (which I'd changed in my original answer).

In addition, I've changed the punctuation to match the target image. Specifically, I've put commas between the last name and initials of authors' names but removed them from between different names in the list. That is, the target format shows

last1, init1 last2, init2 and last3, init3


rather than

last1 init1, last2 init2, and last3 init3


# The code

\documentclass [12pt]{article}

\usepackage[
backend=bibtex8,
natbib=true,
citestyle=numeric,
bibstyle=authoryear, % also thanks to karlkoeller's answer (was in MWE but - see comments)
isbn=false,
maxnames=3,
minnames=3,
firstinits=true, % Removes period after first name intial
terseinits=true, % Removes period after first name intial
sorting=none] % List citation in order they appear
{biblatex}

\DeclareFieldFormat{pages}{#1} % No prefix for the "pages" field in the bibliography
\DeclareFieldFormat[article]{title}{#1}  % Remove quotes from journal title
\DeclareNameAlias{sortname}{last-first} % Lists all authors with last name first
\renewcommand{\labelnamepunct}{\addspace} % Removes period after year in bibliography
\renewcommand*{\revsdnamepunct}{\addcomma}% want a comma between last name and initials
\renewcommand*{\multinamedelim}{\space}% want a space but no comma between names
\renewcommand*{\finalnamedelim}{\addspace\bibstring{and}\space}% want a space but no comma between penultimate name and 'and' followed by final name

\usepackage{xpatch}

\xpatchbibmacro{name:andothers}{% maked the et al'' italicized in the bibliography
\bibstring{andothers}%
}{%
\bibstring[\emph]{andothers}%
}{}{}

\renewbibmacro{in:}{% Removes "In" from bibliography entries
\ifentrytype{article}{}{%
\printtext{\bibstring{in}\intitlepunct}}}

\defbibenvironment{bibliography}
{\list
{\printfield[labelnumberwidth]{labelnumber}}
{\setlength{\labelwidth}{\labelnumberwidth}%
\setlength{\leftmargin}{0pt}%
\setlength{\labelsep}{\biblabelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\itemindent}{\labelwidth}%
\setlength{\parsep}{\bibparsep}}%
\renewcommand*{\makelabel}[1]{\hss##1}}
{\endlist}
{\item}

\usepackage{filecontents}
\begin{filecontents*}{example.bib}

@article{author2014,
author = {Author, A. B. and Author, A. B. and Author, A. B.},
journal = {Journal of the happy but frustrated biblatex user},
pages = {1070--1074},
title = {{Biblatex hurts so good}},
volume = {10},
date = {2014}
}
@article{author2013,
author = {Author, A. D. and Author, A. B. and Author, A. B.},
journal = {Journal of the happy but frustrated biblatex user},
pages = {1070--1074},
title = {{Biblatex hurts so good}},
volume = {10},
date = {2013}
}
\end{filecontents*}

\bibliography{example}

\begin{document}

Be excellent, Dudes \supercite{author2014,author2013}

\printbibliography

\end{document}


# The result

• @karlkoeller But your answer was before mine... It just took me ages to figure out how to get the names reversed. – cfr Mar 30 '14 at 21:04
• As you want. +1 anyway. – karlkoeller Mar 30 '14 at 21:04
• @karlkoeller Thanks. Also, your answer is simpler than mine and closer to the target format. Because I've used bibstyle=numeric, my code reverses the year and title and complicates things in various other ways. I didn't realise that the numbers were available for the redefined bibliography environment even if I'd left bibstyle=authoryear. – cfr Mar 30 '14 at 21:29
• @MikeB I've rolled back your edit because there is no need to renew a command twice. That line is already included in the code I posted and it just confuses things to repeat it. I've put all my renews together with yours now and removed duplicates. – cfr Mar 31 '14 at 1:02

Add the following lines in the preamble:

\DeclareFieldFormat{labelnumberwidth}{#1.}

\defbibenvironment{bibliography}
{\list
{\printfield[labelnumberwidth]{labelnumber}}
{\setlength{\labelwidth}{\labelnumberwidth}%
\setlength{\leftmargin}{0pt}%
\setlength{\labelsep}{\biblabelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\itemindent}{\labelwidth}%
\setlength{\parsep}{\bibparsep}}%
\renewcommand*{\makelabel}[1]{\hss##1}}
{\endlist}
{\item}


MWE:

\documentclass [12pt]{article}

\usepackage[
backend=bibtex8,
natbib=true,
citestyle=numeric,
isbn=false,
bibstyle=authoryear,
maxnames=3,
minnames=3,
firstinits=true, % Removes period after first name intial
terseinits=true, % Removes period after first name intial
sorting=none] % List citation in order they appear
{biblatex}

\DeclareFieldFormat{pages}{#1} % No prefix for the "pages" field in the bibliography
\renewcommand*{\revsdnamepunct}{} % Removing the comma after last name
\renewcommand*{\revsdnamepunct}{} % Removing the periods after first name intial
\renewcommand{\labelnamepunct}{\addspace} % Removes period after year in bibliography
\DeclareFieldFormat[article]{title}{#1}  % Remove quotes from journal title
\DeclareNameAlias{sortname}{last-first} % Lists all authors with last name first

\DeclareFieldFormat{labelnumberwidth}{#1.}

\defbibenvironment{bibliography}
{\list
{\printfield[labelnumberwidth]{labelnumber}}
{\setlength{\labelwidth}{\labelnumberwidth}%
\setlength{\leftmargin}{0pt}%
\setlength{\labelsep}{\biblabelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\itemindent}{\labelwidth}%
\setlength{\parsep}{\bibparsep}}%
\renewcommand*{\makelabel}[1]{\hss##1}}
{\endlist}
{\item}

\usepackage{xpatch}

\xpatchbibmacro{name:andothers}{% maked the et al'' italicized in the bibliography
\bibstring{andothers}%
}{%
\bibstring[\emph]{andothers}%
}{}{}

\renewbibmacro{in:}{% Removes "In" from bibliography entries
\ifentrytype{article}{}{%
\printtext{\bibstring{in}\intitlepunct}}}

\usepackage{filecontents}
\begin{filecontents*}{example.bib}

@article{author2014,
author = {Author, A. B. and Author, A. B. and Author, A. B.},
journal = {Journal of the happy but frustrated biblatex user},
pages = {1070--1074},
title = {{Biblatex hurts so good}},
volume = {10},
date = {2014}
}
@article{author2013,
author = {Author, A. D. and Author, A. B. and Author, A. B.},
journal = {Journal of the happy but frustrated biblatex user},
pages = {1070--1074},
title = {{Biblatex hurts so good}},
volume = {10},
date = {2013}
}
\end{filecontents*}

\bibliography{example}

\begin{document}

Be excellent, Dudes \supercite{author2014,author2013}

\printbibliography

\end{document}


Output:

• Perfect! Thank you. Can you explain to me what this command is telling Latex? That is, can you explain it in words? I would like to understand what this actually does. – scottsmith Mar 30 '14 at 19:51
• @MikeB We are redefining the bibliography environment to suit your needs. With the line before we tell biblatex to format the label as you want (1. instead of [1]). – karlkoeller Mar 30 '14 at 21:03
• +1 I incorporated your code into my answer and did some more tweaking to adjust the punctuation. [I definitely don't think you should delete this answer now mine refers to it!] – cfr Mar 31 '14 at 0:57