0

I am having problems setting up my bibliography. I am using Harvard citation style yet my citations are appearing as numbers as shown in the picture below:
Problem description If I remove the options super,comma,numbers of the natbib package, I get the desired output though this will result in the disappearance of the numbering labels of my references in the Bibliography which is something I do not like. Below is my MWE:

\documentclass[12pt,openany]{book}
\usepackage[ 
left=2.5cm,
right=2.5cm, 
top=3cm,
bottom=3cm,
headheight = 3\baselineskip,
headsep = 5mm,
a4paper
]{geometry}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{fancyhdr}
\usepackage{hhline}
\pagestyle{fancy}

\usepackage[super,comma,numbers]{natbib} \renewcommand{\bibnumfmt}[1]{\textsuperscript{#1}} \setlength\bibindent{0pt} \bibliographystyle{apalike2} \usepackage{etoolbox} \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=blue, citecolor=red,
urlcolor=yellow, } \usepackage{showframe} \begin{document}

\chapter*{Acknowledgements}
I want this citation \cite{hapa:graphenum} to be \textcolor{red}{Harary and Palmer }\textcolor{black}{(\textcolor{red}{1973})}. I want this citation \cite{Knuth94:TheTeXbook} to be \textcolor{red}{Knuth }\textcolor{black}{(\textcolor{red}{1994})}.This text is quoted from \cite{datta2017latex} should be (\textcolor{red}{Datta\textcolor{black}{,} 2017}).
\mainmatter
\setcounter{tocdepth}{1}

\chapter{Introduction}

\backmatter

\nocite{*}
\bibliography{references}

\end{document}

Below is the references.bib:

@book{hapa:graphenum,
    author =     {F. Harary and E. M. Palmer},
    title =      {Graphical Enumeration},
    publisher =      {Academic Press},
    pages={465--523},
    year =   1973
}
@book{Knuth94:TheTeXbook,
    author =     {Knuth, Donald Ervin},
    title =      {The \TeX book},
    publisher =      {Addison-Wesley Publishing Company},
    pages={465--523},
    year =   1994,
    series =     {Computers \& Typesetting A},
    address =    {Reading, MA},
    titlenote  =        {with illustrations by Duane Bibby}
}
@book{datta2017latex,
    title={LaTeX in 24 Hours: A Practical Guide for Scientific Writing},
    author={Datta, Dilip},
    pages={465--523},
    year={2017},
    publisher={Springer}
}
itc
  • 657
  • I think you should take a look at biblatex functionalities. – Bernard Aug 07 '22 at 22:33
  • You're loading natbib this way: \usepackage[super,comma,numbers]{natbib}. Not surprisingly you're getting superscripted numeric citations. Remove those options and see what you get. If you need conforming APA style, you should use either the apacite package or biblatex with the apa style. See How can I implement a comprehensive apa-style citation and bibliography for examples. – Alan Munn Aug 08 '22 at 01:07
  • Easiest to do this with biblatex. See https://tex.stackexchange.com/q/373336/2693 or https://tex.stackexchange.com/q/537992/2693 – Alan Munn Aug 08 '22 at 04:40
  • If you use author-year citations in your text, there is little point in adding numbers in the bibliography. In fact those numbers can take away focus from what is important to find the relevant item in the bibliography (namely name and year). That's why the default settings don't let you combine author-year citations and a numeric bibliography like this. Do you really, absolutely need this? – moewe Aug 08 '22 at 05:40
  • If that is the case, have a look at https://tex.stackexchange.com/q/537992/35864. The first part of the answer was written with apacite in mind, but you get the structurally same result (and the result you want) if you replace \usepackage[natbibapa]{apacite} with just \usepackage{natbib} and \bibliographystyle{apacite} with \bibliographystyle{apalike}/\bibliographystyle{apalike2}. – moewe Aug 08 '22 at 15:31
  • Are you sure? I just verified that the code works as intended in the following MWE: https://gist.github.com/moewew/1b38e4f32990da5f99d0c88d7ba23250. You need to use \numbibliography{<bib file name>} and not \bibliography{<bib file name>}. – moewe Aug 08 '22 at 15:56
  • That's what I see after the first pdfLaTeX run. If I run BibTeX and then pdfLaTeX twice more I see https://i.stack.imgur.com/Mkznm.png. Do you get any warnings or errors in the .log or .blg files? – moewe Aug 08 '22 at 16:06
  • What does the .blg file say when you run BibTeX? – moewe Aug 08 '22 at 16:28
  • This is what it says: `Process started: bibtex.exe "texstudio_QiTrwL"

    This is BibTeX, Version 0.99d (TeX Live 2022) The top-level auxiliary file: texstudio_QiTrwL.aux The style file: apalike2.bst I couldn't open database file apa5ex.bib ---line 6 of file texstudio_QiTrwL.aux : \bibdata{apa5ex : } I'm skipping whatever remains of this command I found no database files---while reading file texstudio_QiTrwL.aux Warning--I didn't find a database entry for "apa6:ch7-ex38" (There were 2 error messages) Process exited with error(s)`

    – itc Aug 08 '22 at 16:32
  • Alright, but that message is just because your system does not have the example .bib file used in the code (which is weird, but could be explained if you did not install a full system). I have updated the example at https://gist.github.com/moewew/1b38e4f32990da5f99d0c88d7ba23250 to come with its own example .bib entry. Can you get it to work now? – moewe Aug 09 '22 at 05:17
  • Thank you very much. It worked well though the number labels are not aligned to the left margin. – itc Aug 09 '22 at 11:49
  • As I wrote in the answer https://tex.stackexchange.com/q/537992/35864 apalike2 does not provide information about the longest label, so the label width is hard-coded (to 1em in the example with \setlength{\labelwidth}{1em}%), this might not be the best value if your have many entries, so you may have to experiment with the value. – moewe Aug 09 '22 at 19:57
  • Noted with many thanks @moewe – itc Aug 09 '22 at 20:01

0 Answers0