kks32 / phd-thesis-template

A LaTeX / XeLaTeX / LuaLaTeX PhD thesis template for Cambridge University Engineering Department (CUED)
http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/ThesisStyle/
MIT License
820 stars 392 forks source link

authoryear citation gives a number within parenthesis (e.g. "(145)" instead of "Smith et al. (2021)" #228

Closed TorkelE closed 2 years ago

TorkelE commented 2 years ago

I am trying to use the authoryear citation style by setting

\documentclass[a4paper,12pt,times,authoryear,print,index]{Classes/PhDThesisPSnPDF}

unfortunately, it doesn't work, and yields stuff like: image from the text

While its effect was not always fully grasped, the presence of cellular noise in individual systems was documented already in the middle of the 20th century \citep{1953Benzer,1957Novick}. Furthermore,

It looks the same if I try \cite{1953Benzer}. I have many citations in the text, some with several references, some with only one. All return this style of citation.

If I try changing to

\documentclass[a4paper,12pt,times,numbered,print,index]{Classes/PhDThesisPSnPDF}

I get this: image just like expected (so that works).

I do not know why this is the case. At some point in the beginning I occasionally had the desired format, but it would kind of change as I added the references in, every time I recompiled it might change. But now that has not happened since I added in the last references.

I am using overleaf. I have no idea what might be causing this, but the behaviour is rather distinct, so I figured it might be helpful to ask.

GR8DAN commented 2 years ago

Try explicitly using natbib.

For example, in Preamble/preamble.tex replace the Bibliography section (lines 112 to 126 in the GitHub version) with:

% Replaced current bibliography style with a Harvard style
\usepackage{natbib} % Bibliography management
% Use 'numbers' option in natbib if you want a numbered Bibliography
% \usepackage[numbers]{natbib} % Numbered Bibliography
% See https://www.overleaf.com/learn/latex/Bibliography_management_with_natbib
\bibliographystyle{apalike} % e.g., Harvard style

In thesis.tex replace the lines between \begin{spacing}{0.9} and \end{spacing} (lines 154 to 170 in GitHub) with:

\cleardoublepage
\bibliography{References/references} % Bibliography comes from references.bib file

Choose style as appropriate, APA example shown above. See also Overleaf's article Bibliography management with natbib

TorkelE commented 2 years ago

I tried it, but there is no change. Although my .tex document is a bit different, I don't think I got it from GitHub, but maybe directly from overleaf.

First I replaced:

% *****************************************************************************
% *************************** Bibliography  and References ********************

%\usepackage{cleveref} %Referencing without need to explicitly state fig /table

% Add `custombib' in the document class option to use this section
\ifuseCustomBib
   \RequirePackage[square, sort, numbers, authoryear]{natbib} % CustomBib

% If you would like to use biblatex for your reference management, as opposed to the default `natbibpackage` pass the option `custombib` in the document class. Comment out the previous line to make sure you don't load the natbib package. Uncomment the following lines and specify the location of references.bib file

%\RequirePackage[backend=biber, style=numeric-comp, citestyle=numeric, sorting=nty, natbib=true]{biblatex}
%\bibliography{References/references} %Location of references.bib only for biblatex

\fi

% changes the default name `Bibliography` -> `References'
\renewcommand{\bibname}{References}

with

% *****************************************************************************
% *************************** Bibliography  and References ********************

% Replaced current bibliography style with a Harvard style
\usepackage{natbib} % Bibliography management
% Use 'numbers' option in natbib if you want a numbered Bibliography
% \usepackage[numbers]{natbib} % Numbered Bibliography
% See https://www.overleaf.com/learn/latex/Bibliography_management_with_natbib
\bibliographystyle{apalike} % e.g., Harvard style

% changes the default name `Bibliography` -> `References'
\renewcommand{\bibname}{References}

(in the preamble.tex file)

and then I replaced

\begin{spacing}{0.9}

% To use the conventional natbib style referencing
% Bibliography style previews: http://nodonn.tipido.net/bibstyle.php
% Reference styles: http://sites.stat.psu.edu/~surajit/present/bib.htm

\bibliographystyle{apalike}
%\bibliographystyle{unsrt} % Use for unsorted references  
%\bibliographystyle{plainnat} % use this to have URLs listed in References
\cleardoublepage
\bibliography{References/references} % Path to your References.bib file

% If you would like to use BibLaTeX for your references, pass `custombib' as
% an option in the document class. The location of 'reference.bib' should be
% specified in the preamble.tex file in the custombib section.
% Comment out the lines related to natbib above and uncomment the following line.

%\printbibliography[heading=bibintoc, title={References}]

\end{spacing}

with

\cleardoublepage
\bibliography{References/references} % Bibliography comes from references.bib file

(in the thesis.tex file)

GR8DAN commented 2 years ago

I just tried the Cambridge template on Overleaf and both the original authoryear option and the suggestion above works. If the build logs in Overleaf don't provide any additional information, and you don't know which change was made to break the authoryear option, you may need to try another approach. Maybe start a new Overleaf project and move some content over to make sure that it is not an issue with the default template.

TorkelE commented 2 years ago

The log files! Of course! I check them, and I get this output: image text form as well, for copying and searchability:

Package natbib Error: Bibliography not compatible with author-year citations.(natbib) Press <return> to continue in numerical citation style.

Searcing on this lead me to https://tex.stackexchange.com/questions/54480/package-natbib-error-bibliography-not-compatible-with-author-year-citations which suggested that an entry missing a year could cause it. I did not find any missing year in any entries, but I did find an entry that was malformed. Fixing that caused the citation style to become the desired one!

Thanks a lot :)

See the natbib package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.349 ...and\NAT@force@numbers{}\NAT@force@numbers

Check the bibliography entries for non-compliant syntax,
or select author-year BibTeX style, e.g. plainnat
roiholtzman commented 4 weeks ago

I tried this and this does not work. I have no errors in the log file. Any ideas?

GR8DAN commented 3 weeks ago

Is your issue occurring in the starting template? I.e., you can start a new project with the blank template and copy over one or two of your references and relevant text to see if that works. If that works, try a divide-and-conquer approach on a copy of your project to find where possible bad formatting lays. Note that the Overleaf template is not the latest version but you can upload the updated files, though that may not be a factor.

roiholtzman commented 3 weeks ago

actually \bibliographystyle{apalike} does not work also on the original version of the Overleaf template.