How to Write a Thesis in LaTeX: Templates, Structure and Fixes
It’s the night before a supervisor meeting. You fix one typo in chapter 4, hit compile, wait a full minute, and get Undefined control sequence somewhere in a 9,000-line file. Most LaTeX thesis pain looks like this, and almost all of it comes from setup, not from LaTeX itself.
To write a thesis in LaTeX, start from your university’s official template if one exists, keep a short main file for the preamble and front matter, and put each chapter in its own file pulled in with \include. Manage references in a .bib file with biblatex and biber, keep figures in a figures/ folder as PDF or PNG, and compile with latexmk so citations and cross-references resolve in one command. Overleaf and a local TeX Live install both work.
Still deciding whether LaTeX is right for you at all? Read LaTeX vs Word for a thesis first. If you’ve decided, here’s the setup that holds up at 200 pages.
Find your university’s LaTeX thesis template
Thesis rules are fussy: margins, line spacing, the order of the declaration and abstract, exactly what the title page says. A good template handles all that so you can just write.
Look in three places, in this order. First, your graduate school or library website; search for “LaTeX template” next to “thesis formatting”. Second, the Overleaf template gallery, searching your university’s name. Be a little suspicious here, because many of those were uploaded by students years ago, so check the date against the current written rules. Third, and often best, ask the most recent graduate in your lab. Their template has already survived a format check.
If nothing exists, use the standard report class (chapters, one-sided by default) or book (two-sided by default), and set the rules yourself with geometry for margins and setspace for line spacing. CTAN has general thesis classes such as classicthesis too, but your university’s rules beat any design.
Whatever you start from, compile it untouched before you add a word. If the blank template fails, fix that first. Debugging a broken template with 40 pages of your own text inside it is miserable.
Project structure for a LaTeX thesis
A thesis is far too long for one file. This layout works for most people:
thesis/
main.tex
preamble.tex
references.bib
frontmatter/
titlepage.tex
abstract.tex
acknowledgements.tex
chapters/
ch1-introduction.tex
ch2-literature.tex
ch3-methods.tex
ch4-results.tex
ch5-discussion.tex
appendices/
appA-derivations.tex
figures/
ch3/
ch4/
And main.tex stays short:
\documentclass[12pt,a4paper,oneside]{report}
\input{preamble}
\includeonly{chapters/ch4-results} % comment out for full builds
\begin{document}
\input{frontmatter/titlepage}
\pagenumbering{roman}
\input{frontmatter/abstract}
\tableofcontents
\listoffigures
\listoftables
\cleardoublepage
\pagenumbering{arabic}
\include{chapters/ch1-introduction}
\include{chapters/ch2-literature}
\include{chapters/ch3-methods}
\include{chapters/ch4-results}
\include{chapters/ch5-discussion}
\printbibliography[heading=bibintoc]
\appendix
\include{appendices/appA-derivations}
\end{document}
Why \include rather than \input for chapters? Each included file gets its own .aux file, and \includeonly lets you compile just the chapter you’re working on while page numbers, figure numbers and cross-references to the other chapters stay correct. When the full build takes a minute, getting one chapter back in a few seconds changes how you work. Keep \input for small pieces like a long table, since \include always starts a new page.
A few habits that pay for themselves within a month:
- Prefix every label:
\label{fig:membrane-sem},\label{tab:ozone-doses},\label{sec:fouling-model}. Loadcleverefand write\cref{fig:membrane-sem}, and LaTeX adds the word “Figure” for you. - Load
hyperrefnear the end of the preamble, withcleverefafter it. A surprising share of package conflicts in theses come down to this order. - One sentence per line in the source. Diffs in git and Overleaf’s history become readable.
- Use
booktabsfor tables andsiunitxfor numbers with units.
Back the whole folder up somewhere off your laptop from day one; how to organize PhD files and backups covers a backup routine that would survive a stolen laptop.
Overleaf vs local TeX Live
Both are good. It comes down to convenience, collaboration and how long your builds take.
| Overleaf | Local (TeX Live, MacTeX, MiKTeX) | |
|---|---|---|
| Setup | None, runs in the browser | Install a few GB, pick an editor |
| Sharing with a supervisor | Send a link; comments and track changes | Share PDFs, or use git |
| Offline work | No | Yes |
| Long builds | Free plan has a compile time limit | Limited only by your computer |
| Version history | Built in | Use git |
Overleaf is the easiest start, and the obvious choice if your supervisor likes commenting directly in the source. Git and GitHub integration are paid features, so check what your institution’s licence covers; many universities provide premium accounts.
Going local means installing TeX Live (Windows and Linux), MacTeX (TeX Live packaged for the Mac) or MiKTeX (Windows), plus an editor: VS Code with the LaTeX Workshop extension, TeXstudio, or TeXShop on macOS. Put the project under git and push to a private repository, and you get history and an off-site backup in one go.
A path a lot of people end up on: draft the first chapters on Overleaf, then download the project and go local once the thesis is long and you’re compiling every few minutes.
Bibliography in a LaTeX thesis
For a new thesis, biblatex with the biber backend is the more flexible option:
\usepackage[backend=biber, style=authoryear, maxcitenames=2]{biblatex}
\addbibresource{references.bib}
Swap style=authoryear for numeric, ieee or apa (the last two need the biblatex-ieee and biblatex-apa packages, which TeX Live includes). Cite with \textcite{nguyen2021ceramic} to get “Nguyen et al. (2021)” in the sentence, and \parencite{...} for a parenthetical citation. If your template is built around a .bst file or a journal style you must match exactly, use natbib with BibTeX instead.
The .bib file is where theses quietly rot. Duplicate keys. Missing DOIs. “DFT” printed as “dft” because the title lost its capitals. Protect capitals with braces, title = {{DFT} study of ...}, and export entries from a reference manager instead of copying them from Google Scholar by hand. How to manage a BibTeX library covers key naming, cleaning, and keeping one .bib in sync with Zotero.
Figures in a LaTeX thesis
\begin{figure}[tbp]
\centering
\includegraphics[width=0.8\linewidth]{figures/ch3/flux-decline.pdf}
\caption{Normalised flux over 30 days at three ozone doses.}
\label{fig:flux-decline}
\end{figure}
Export plots from Python, R or MATLAB as PDF, so they stay sharp at any zoom and the text stays searchable; use PNG for photos and micrographs. Size figures with \linewidth rather than centimetres, so they adjust if the margins change. Use subcaption for panels (a), (b), (c), and add \graphicspath{{figures/}} to the preamble if you like shorter paths.
Then let the figures float. [tbp] lets LaTeX place them at the top, the bottom or on a float page. Forcing [h!] everywhere is exactly how you get those half-empty pages your examiner will notice. For making the figures themselves look good, see how to make figures for research papers.
Common LaTeX compile errors and how to fix them
Read the first error in the log, not the last. The later ones are usually fallout.
| Error | Usual cause | Fix |
|---|---|---|
Undefined control sequence |
Typo in a command, or a package not loaded | Check the line number; add the \usepackage |
Missing $ inserted |
_ or ^ outside math mode |
Escape as \_, or wrap in $...$ |
File 'x.pdf' not found |
Wrong path or case of the file name | Match case exactly; Linux and Overleaf are case-sensitive |
| Citations show as [?] or bold keys | Bibliography not processed | Run biber (or BibTeX), then LaTeX again; latexmk does this |
| References show as ?? | Needs another pass | Compile again |
Too many unprocessed floats |
Many figures with no text between | Add \clearpage, or loosen placement options |
Overfull \hbox warning |
A line sticks into the margin | Rephrase, or allow a break in long URLs with the xurl package |
When nothing makes sense, delete the auxiliary files (.aux, .bbl, .bcf, .toc) and recompile. On Overleaf, that’s “Clear cached files” under the logs. And if a baffling error shows up right after a big paste, comment out half the new text and compile, then a quarter, until you’ve cornered the line. It’s dull, but it always works.
LaTeX only handles how the thesis looks. For what goes in each chapter, and in what order to write them, the main guide on how to write a PhD thesis covers planning, drafting and working with your supervisor.
Where Mitra fits
Mitra is a free desktop app for macOS, Windows and Linux with a LaTeX editor built in. It builds your thesis with TeX Live on your own computer and keeps the .bib file in step with your library: cite a paper and its entry is added, so you’re not hand-editing BibTeX or chasing a missing key at midnight. It supports hundreds of citation styles, and the co-writer can draft or rewrite a paragraph using only papers from your library, citing each one.
Your papers stay on your computer. Mitra finds the PDFs you already have, reads titles, authors and DOIs, catches duplicates, and imports an existing Zotero, BibTeX or RIS library with collections kept as folders. You can ask questions of a single paper or a whole folder and get answers that cite the page, which is handy when you’re checking a number before it goes into a results chapter. You can download Mitra free and try the LaTeX editor on one chapter.
Questions people ask
Where can I find a LaTeX thesis template for my university?
Start with your graduate school website, then search the Overleaf template gallery for your university name, then ask your department or lab, since many groups pass a template down. If nothing official exists, use the standard report or book class and set margins, spacing and front matter to match the written formatting rules.
What is the difference between \include and \input in LaTeX?
\input pastes a file in exactly where it appears. \include starts a new page, writes a separate .aux file for that chapter, and works with \includeonly, which lets you compile just the chapter you are editing while keeping page and figure numbers from the others. Use \include for chapters and \input for smaller pieces like tables.
Should I write my thesis on Overleaf or locally?
Overleaf is easiest to start with and makes sharing with a supervisor simple, but large theses can hit the free plan compile time limit. A local TeX Live or MacTeX install with an editor such as VS Code or TeXstudio compiles faster and works offline. Many people draft on Overleaf and move to a local setup, under git, for the final months.
Should I use BibTeX or biblatex for a thesis?
For a new thesis, biblatex with biber is usually the more flexible choice: it handles Unicode, many citation styles and per-chapter bibliographies. Use natbib and BibTeX if your template or a journal requires a .bst style. Both read the same .bib file.