TITLE: Making a LaTeX thesis template
DATE: 2020-09-15
AUTHOR: John L. Godlee
====================================================================


Note, I updated this post on 2021-07-31, as my LaTeX template has 
developed.

Terrifyingly, it's not too long before I have to start writing my 
PhD thesis. To save myself some headaches down the line I put 
together a LaTeX thesis template system for myself. The template 
itself can be found on Github.

  [on Github]: https://github.com/johngodlee/phd_thesis

The template hinges on compile.sh, which contains a shell script 
which can compile the thesis, or individual chapters separately.

The directory structure is paramount to make sure all the parts 
work together, and as a result the template isn't that flexible, 
but it works for my needs.

Below is a copy of the README.md found in the template, which 
details how it works:

This directory contains a directory structure and associated 
styling files for a University of Edinburgh PhD thesis, created by 
the author, for a PhD in the School of GeoSciences.

Directory structure

compile.sh is a shell script to generate the thesis and chapters. 
The script requires bash and latexmk. It takes 1:5 arguments:

-   -c - clean intermediate LaTeX files before and after compilation
-   -t - compile thesis
-   -p - compile all individual chapters
-   -s - compile a named chapter by referencing its directory. e.g. 
./compile.sh -s chapters/introduction
-   -f - sets the format argument, either 0 for submission 
(default), or 1 for a "nicer" layout with smaller margins, a 
serif'ed font, and single spaced lines.

main.tex contains the top-level .tex skeleton file which calls all 
other files. Can be altered to include new chapters, or to change 
the order of chapters.

frontmatter/ contains various .tex snippets used in the frontmatter 
of the main thesis: title page (ttl.tex), acknowledgements 
(ack.tex), etc.

img/ contains common images used in the thesis.

chapters/ contains subdirectories each referring to a thesis 
chapter or an appendix. The directory name of each chapter should 
match the name of the main .tex file for that chapter. Each chapter 
directory should have a *_defin.tex where the asterisk expands to 
the directory name, which defines the \chaptertitle{} variable for 
that chapter. Chapters can have their own img/ (images) and inc/ 
(included .tex files, e.g. tables) directories which will be 
incorporated into the thesis and standalone chapters. Chapter .tex 
content should be wrapped in the following boilerplate, to ensure 
that references come at the end of the chapter, rather than the end 
of the thesis:

    \begin{refsection}

    \input{chaptername_defin.tex}
    \chapter[\chaptertitle]{\chaptertitle}
    \chaptermark{Introduction}
    \label{ch:chaptername}

    % CONTENT HERE

    \newpage{}
    \begingroup
    \setstretch{1.0}
    \printbibliography[heading=subbibintoc]
    \endgroup

    \end{refsection}

out/ contains all compiled .pdf files.

snippets/ contains bits of code used to compile the thesis:

-   preamble.tex contains all the preamble material used for the 
thesis. It is also called by chapter.tex.
-   pagefmt_submission.tex defines page layout which adheres to 
thesis submission guidelines
-   pagefmt_nice.tex defines page layout for a "nicer" layout
-   chapter.tex contains a skeleton to create individually 
formatted chapters.
-   definitions.tex contains thesis-level LaTeX variables: thesis 
title, author name, thesis date, etc.

Packages

Various packages are used to create this template:

import to make nested linking of .tex files per chapter easier. 
Uses import when sourcing chapters in main.tex

inputenc, babel and csquotes set English language rules.

geometry sets page margins.

pdflscape allows landscape pages with \begin{landscape}.

setspace sets line spacing.

fancyhdr sets page headers and footers.

graphicx for including images.

float for managing floats with [H].

caption for custom caption formatting.

subcaption for compound figures:

    \begin{figure}[H]
        \begin{subfigure}[h]{0.45\linewidth}
            \includegraphics[width=\linewidth]{img_a}
            \caption{}
            \label{img_a}
        \end{subfigure}
        \hfill
        \begin{subfigure}[h]{0.45\linewidth}
            \includegraphics[width=\linewidth]{img_b}
            \caption{}
            \label{img_b}
        \end{subfigure}
        \caption{caption text}
        \label{img_a_b}
    \end{figure}

multirow and longtable allow for more flexible table formatting,

booktabs subtly improves table aesthetics.

biblatex handles referencing.

textcomp, siunitx, amsmath, and amssymb provide many symbols and 
extended text characters.

fmtcount converts numbers into text, useful for including variable 
output from R scripts.

appendix handles appendices better than the basic \appendix{}.

hyperref provides hyperlinks between sections, to references, to 
DOIs and URLs.

xcolor allows using colours to highlight text.

appendix improves handling of appendices per chapter.

enumitem for custom lists such as author affiliations at the start 
of chapters adapted from published articles.

microtype magically improves text justification.

Extras

I've added some commands to format information to be displayed at 
the start of chapters adapted from peer-reviewed articles. 
\paperauthors{} and \authorcontributions{} simply format author 
names and author contributions, prepending with "Author 
contributions" for example, and adding some aesthetic space around 
the block. \papercite{} wraps around \fullcite{} to provide a 
pretty bibliographic entry for published papers. \paperaffil{} 
defines a custom enumerated list to display author affiliations in 
a compact manner.

begin{supplement}...\end{supplement} defines an environment for 
supplementary materials at the end of a chapter. It resets the 
figure and table counters to zero and prepends "S" to each figure 
and table number.

The report class does a ridiculous thing where the page count is 
reset after every \begin{abstract}...\end{abstract}. This might be 
OK if every chapter has an abstract but not all of mine did. I 
patched the \abstract{} command to stop this happening, and also to 
display the abstract like an unnumbered section.

The basic \textasciitilde{} sits too high on the line. I defined 
\textapprox{} which produces a more aesthetically pleasing tilde.

Notable mentions

Inspiration for this template came from other projects:

-   uoe-gits / EdThesis LaTeX template · GitLab - Created by 
Magnus Hagdorn back in 2003.
-   Writing a PhD Thesis in LaTeX | Johannes Miocic - A more recent 
attempt, from 2015, also with links to other PhD thesis LaTeX 
projects.
-   ryklith/ue-phd-thesis: Template for a PhD thesis at the 
University of Edinburgh
-   maxbiostat/PhD_Thesis: My PhD Thesis - Institute of 
Evolutionary Biology, University of Edinburgh, 2018

  [uoe-gits / EdThesis LaTeX template · GitLab]: 
https://git.ecdf.ed.ac.uk/uoe-gits/edthesis
  [Writing a PhD Thesis in LaTeX | Johannes Miocic]: 
https://jojomio.wordpress.com/2014/02/14/writing-a-phd-thesis-in-lat
ex/
  [ryklith/ue-phd-thesis: Template for a PhD thesis at the 
University of Edinburgh]: https://github.com/ryklith/ue-phd-thesis
  [maxbiostat/PhD_Thesis: My PhD Thesis - Institute of Evolutionary 
Biology, University of Edinburgh, 2018]: 
https://github.com/maxbiostat/PhD_Thesis