1

I am writing my PhD thesis in Overleaf and having issues with bibliography while using subfiles command. Ideally I would like one bibliography right at the end of the thesis instead of different bibliographies for each chapter. What command should I put in the main file to have one bibliography? If that is not viable, then how should I modify the command for each separate bibliography such that when I compile main.tex, a bibliography is printed after each chapter. Currently, bibiliographies are not being read in the main file but read only in subfiles.

The file path is as follows:

main.tex

papers/preamble.tex

papers/paper1.tex

papers/paper1refs.bib

papers/paper2.tex

papers/paper2refs.bib

Each file is structured as follows:

main.tex

\documentclass[12pt]{report}
\input{papers/preamble.tex}
\begin{document}
\chapter{Chapter1}
\clearpage \newpage
\subfile{papers/paper1.tex}
\chapter{Chapter2}
\clearpage \newpage
\subfile{papers/paper2.tex}
\end{document}

preamble.tex

\usepackage{apacite}
\usepackage{subfiles}

paper1.tex

\documentclass[../main.tex]{subfiles}
\begin{document}
This is the cite I want \cite{cite1}.
\clearpage \newpage
\bibliographystyle{apacite}
\phantomsection
\bibliography{paper1refs}
\end{document}

paper1refs.bib

@article{cite1,
  title = {Citation1},
  shorttitle = {Citation1},
  author = {Author1, Author1},
  year = {2022},
  journal = {Journal1},
  langid = {english}
}

paper2.tex

\documentclass[../main.tex]{subfiles}
\begin{document}
This is the cite I want \cite{cite2}.
\clearpage \newpage
\bibliographystyle{apacite}
\phantomsection
\bibliography{paper2refs}
\end{document}

paper2refs.bib

@article{cite2,
  title = {Citation2},
  shorttitle = {Citation2},
  author = {Author2, Author2},
  year = {2021},
  journal = {Journal2},
  langid = {english}
}

1 Answer 1

1
  • Add a \bibliography command to the main section, referring to the two bib files.

  • In the subfiles, use \ifSubfilesClassLoaded to generate the bibliography only if the papers are generated separately.

  • As an aside, it is sufficient to add \bibliographystyle{apacite} only once, in the preamble.

% main.tex
\documentclass[12pt]{report}
\input{papers/preamble}
\begin{document}
\chapter{Chapter1}
\clearpage \newpage
\subfile{papers/paper1}
\chapter{Chapter2}
\clearpage \newpage
\subfile{papers/paper2}
\bibliography{papers/paper1refs,papers/paper2refs}% <<<<<<<<<<<<<<<<<
\end{document}

% papers/preamble.tex
\usepackage{apacite}
\bibliographystyle{apacite}% <<<<<<<<<<<<<<<<<<<
\usepackage{subfiles}

% papers/paper1.tex
\documentclass[../main]{subfiles}
\begin{document}
This is the cite I want \cite{cite1}.
\clearpage \newpage
\ifSubfilesClassLoaded{% <<<<<<<<<<<<<<<
  \bibliography{paper1refs}% <<<<<<<<<<<<<<
}{}% <<<<<<<<<<<<<<<<<<<<
\end{document}

% papers/paper2.tex
\documentclass[../main]{subfiles}
\begin{document}
This is the cite I want \cite{cite2}.
\clearpage \newpage
\ifSubfilesClassLoaded{% <<<<<<<<<<<<<<<<<
  \bibliography{paper2refs}% <<<<<<<<<<<<<<<
}{}% <<<<<<<<<<<<<<<<<<<<
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .