💾 Archived View for republic.circumlunar.space › users › johngodlee › posts › 2020-09-15-latex_thesi… captured on 2023-09-08 at 16:20:23. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-04-19)

-=-=-=-=-=-=-

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[1].

1: 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:

<hr>

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:

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:

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:

2: https://git.ecdf.ed.ac.uk/uoe-gits/edthesis

3: https://jojomio.wordpress.com/2014/02/14/writing-a-phd-thesis-in-latex/

4: https://github.com/ryklith/ue-phd-thesis

5: https://github.com/maxbiostat/PhD_Thesis