[Tex/LaTex] Citations in separate tex file from bibliography

bibliographiescitingnatbib

I'm compiling a thesis where the main TeX file contains all my preamble declarations before including the thesis chapters as individual TeX files. I'd prefer, however, to have a single bibliography at the end of the thesis but before any appendices. However, when I try to do this none of my citations appear correctly in the chapters, i.e. they are replaced with "?", even though they all appear in the bibliography.

I discovered the xcite package, which I've attempted to use to solve this problem but haven't got it working correctly. Probably a simple misunderstanding on my part of how to implement it.

The main file creates the main thesis from several chapters and the bibliography:

\documentclass{report}
\usepackage[authoryear,comma,nonamebreak,round,sort&compress]{natbib}
\usepackage{xcite}

\bibliographystyle{plainnat}
\externalcitedocument{Chapter1}
\externalcitedocument{Chapter2}
...
\externalcitedocument{Chaptern}
\externalcitedocument{Appendix}

\begin{document}
    \include{Chapter1}
    \include{Chapter2}
    ....
    \include{Chaptern}

    \bibliography{Bibliography}

    \appendix
    \include{Appendix}
\end{document}

And the each chapter or appendix only contains text content, i.e. no preamble or \begin{document} and \end{document} commands. Citations within the text are made in the format:

...as found in \citet{Smith2013}...

I've tried moving \externalcitedocument{Chapteri} to the ith. chapter TeX file but it made no difference. I'm using WinEdt7 PDFTeXify to compile my document and JabRef to create the bibliography.

It seems like such a straightforward action that I can only assume I've not used xcite correctly.

Best Answer

Just to show you that xcite is not necceccary and how to build an MWE for your problem please check the following MWE (with commented xcite). It includes with package filecontents three chapter files and a bib file. If you copied this MWE into file mwe.tex then \jobname becomes mwe.

\RequirePackage{filecontents}
\begin{filecontents*}{testxcite1.tex}
\chapter{Chapter One}
Text \cite{adams} 
\end{filecontents*}
\begin{filecontents*}{testxcite2.tex}
\chapter{Chapter Two}
Text \cite{companion}
\end{filecontents*}
\begin{filecontents*}{testxcite3.tex}
\chapter{Chapter Three}
Text \cite{adams} \cite{companion}
\end{filecontents*}
\begin{filecontents*}{\jobname.bib}
@Book{companion,
  author    = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
  title     = {The LaTeX Companion},
  edition   = {1},
  publisher = {Addison-Wesley},
  location  = {Reading, Mass.},
  year       = {1994}
}
@Book{adams,
  title     = {The Restaurant at the End of the Universe},
  author    = {Douglas Adams},
  series    = {The Hitchhiker's Guide to the Galaxy},
  publisher = {Pan Macmillan},
  year      = {1980}
}
\end{filecontents*}

\listfiles   % to show used packages and versions
\documentclass{report}
\usepackage[authoryear,comma,nonamebreak,round,sort&compress]{natbib}
%\usepackage{xcite}

\bibliographystyle{plainnat}
%\externalcitedocument{testxcite1}
%\externalcitedocument{testxcite2}
%\externalcitedocument{testxcite3}

\begin{document}
\include{testxcite1}
\include{testxcite2}
\include{testxcite3}
\bibliography{\jobname}
\end{document}

Compile this MWE with latex, bibtex, latex, latex and you will get a pdf file and four warnings, coming from package filecontents (they are okay and can be ignored). If you have still ? instead of a correct citation there is something other wrong with your system or way to build the pdf file.

Related Question