[Tex/LaTex] Texstudio does not display citations and bibliography properly

bibliographiestexstudio

I installed texlive-full and texstudio under Ubuntu and created a MyLibrary.bib file by exporting my zotero library. In my main.tex-file I have given the following instructions to include my library:

    \begin{document}
    \bibliographystyle{plain}

which I'd like to change to:

    \usepackage[authoryear, round]{natbib}
    \begin{document}
    \bibliographystyle{natdin}

… but it just keeps giving me the old formatting for citations and the references-sextion. I don't know why I cant set the bibliographystyle to natdin or plainnat and why I can't use author-year-citations. A complete reinstall of texlive and texstudio didn't make a difference.

Here's MAIN.tex

    \documentclass[12pt,a4paper,twoside,]{article}
    \usepackage[margin=2.5cm]{geometry}
    \usepackage[utf8]{inputenc}
    \usepackage[ngerman]{babel}
    \usepackage{graphicx}
    \usepackage{enumerate}
    %\graphicspath{ {images/} }
    %\usepackage[round]{natbib}
    \begin{document}
    \bibliographystyle{plain}
    \title{Studienprotokoll}
    \author{BlaBla}
    \date{\today}
    \include{TITLE}
    \include{Preface}
    \include{Section1}
    \include{Section2}
    \include{Section3}
    \include{Section4}
    \include{Section5}
    \include{Section6}
    \include{Section7}
    \include{References}
    \include{Anhang}
    \end{document}

And here's References.tex

    \bibliography{MyLibrary}
    \addcontentsline{toc}{section}{Literaturverzeichnis}

If I activate the usepackage{natbib} command, I get this error-message:

    Package natbib Error: Bibliography not compatible with author-year citations ...mand\NAT@force@numbers{}\NAT@force@numbers

referring to this line in the MAIN.aux file

    \providecommand\NAT@force@numbers{}\NAT@force@numbers

I also get a bunch of over- and underful \hbox error messages which I usually don't get.

Best Answer

When changing bibliography styles, it's usually a good idea to blow away the .aux file before recompiling with LaTeX, BibTeX, and LaTeX twice more. (This is especially true when switching from a style, such as plain, that generates numeric-style citation call-outs to another style that generates authoryear-style call-outs.) In your case, the messages you get from natbib after switching to natdin aren't so much error messages as they are warning messages. If you don't delete the aux files first, just hit "r" ("run") all three times when the warning messages are generated, and you'll end up with the correctly formatted entries in the references as well as the correct citation callout style.

Incidentally, the configuration file that goes with the natdin bibliography style file contains the instruction

\bibpunct{(}{)}{;}{a}{}{,~}

This instruction tells natbib to use round parentheses (cf the first two arguments) as well as authoryear-style call-outs (the fourth argument) for the citations. Hence, it's actually not necessary to specify the options round and authoryear when loading natbib. Of course, it doesn't hurt to specify the options anyway. It's just that \bibpunct takes precedence over the options specified when natbib is loaded.

Here's the output of a program that uses the natdin style:

enter image description here

Just for comparison, here's the output of the same program when using the plainnat style -- natbib's re-implementation of the venerable plain style -- instead (note that plainnat, unlike plain, can generate authoryear-style citation call-outs):

enter image description here

\RequirePackage{filecontents}  % make this example self-contained
\begin{filecontents}{xyz.bib}
@article{aa,
   author = "Anne Author",
   title  = "Thoughts",
   journal= "Circularity Today",
   year   = 5678,
   volume = 1,
   number = 2,
   pages  = "3-4",
}
\end{filecontents}
\documentclass[12pt,a4paper,twoside,]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[authoryear,round]{natbib}
%\bibliographystyle{plainnat}
\bibliographystyle{natdin}

\begin{document}
\cite{aa}
\bibliography{xyz}
\end{document}