# Writing Your Thesis in LyX — A Setup Guide

$\newcommand{\lyxlock}{}$
I am just in the process of finishing writing my PhD, which I wrote entirely in LyX. The productivity advantages of using LyX over LaTeX are too large to ignore, which is why I went with LyX, and why you should too. In this post I will go over the process I went through to get LyX producing documents conforming with my university’s thesis formatting guidelines.
If your anything like me, you have a mixture of past papers you have written in LaTeX, as well as a bunch of notes and drafts in LyX. The university provides a thesis template in LaTeX which the recommend you use. Fortunately, it is actually not too difficult to convert such a template into a working LyX document. Likewise, the papers in LaTeX can also be imported into LyX.
My LyX thesis template is available for download here: template-thesis.zip. The source code is also on github at https://github.com/adefazio/lyx-thesis-template.

## Creating a preamble

We will get LyX to format our document correctly using the thesis style by overriding most things using a preamble file containing TeX commands. The advantage of this approach is we can pretty much copy and paste the LaTeX from the thesis template provided by the university.
I used two preamble files. The primary file contains the usual TeX package statements, includes and the like. It points to the ANU thesis style file as well:
​
\usepackage{svn-multi}
\svnid{$Id$}
\usepackage[hyperindex=true,
bookmarks=true,
pdfborder=0,
pagebackref=false,
citecolor=blue,
plainpages=false,
pdfpagelabels,
pagebackref=true,
hyperfootnotes=false]{hyperref}
\usepackage[all]{hypcap}
\usepackage[palatino]{anuthesis}
\usepackage{afterpage}
\usepackage{graphicx}
\usepackage{thesis}
\usepackage[normalem]{ulem}
\usepackage[table]{xcolor}
\usepackage{makeidx}
\usepackage{cleveref}
\usepackage[centerlast]{caption}
\usepackage{float}
\urlstyle{sf}
\renewcommand{\sfdefault}{uop}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\usepackage{pifont}
\usepackage{rotating}
\usepackage{algorithmic}
​
\usepackage{multirow}
​
%%%% Old macros file includes
\usepackage{booktabs}
\usepackage{relsize}
\usepackage{xspace}
\usepackage{subfig}
\usepackage{listings}
%%%%%%%%

This is not exactly the same as the preamble in the ANU provided style files. Several packages are already automatically imported by LyX, so they don’t need to be included here.
The default style uses the traditional American indenting of the first line of each paragraph. I think that looks old-fashioned, so I change it to just put a little but more padding between paragraphs instead:
\setlength{\parindent}{0cm}
\setlength{\parskip}{4mm plus2mm minus3mm}

The second file I use is main-preamble.tex, which contains the title and author information:
\makeatletter
\AtBeginDocument{
\hypersetup{
pdftitle = {\@title},
pdfauthor = {\@author}
}
}
\makeatother
​
\author{John Smith}
\date{\today}
​
\renewcommand{\thepage}{\roman{page}}


## Setting up chapters as child documents

You probably want to setup your thesis so that each chapter is in a separate document. In LaTeX you would have each chapter imported into your main TeX file using \input{}. In LyX, this is done using child documents. As an example, the main document for my thesis looks like the following:

### Setting up the main document

Create a new document, and go to Document->Settings->LaTeX Preamble, put in the preamble files we created above:
\input{general-preamble}
\input{main-preamble}

Each of the child documents is included via Insert->File->LyX Document ... The “include type” needs to be set to “include” for it to work correctly. The \mainmatter command signifies the switch over from page numbering using Roman numerals (for the introductory material) to Arabic numerals (for the thesis proper). It is inserted using the “TeX Code” insertion (Ctrl-L), which just directly inserts LaTeX commands into the document.
The Append is started with Document->Start Appendix Here, which should probably be in the insert menu of LyX instead. The bibliography is created with Insert->List/TOC->BibTex bibliography.., which lets you select a BibTex .bib file to use for your citations. LyX supports using multiple different bib files, which would appear useful if your combining multiple papers you have written into a thesis. A word of caution: if there are repeated entries between the bib files you will run into various hard to debug problems in LyX, especially if the entries only differ in capitalisation. I would suggest taking all the bib files and merging them using a command line tool into one file. I used the command:
bibtool -s -d *.bib > all.bib

LyX obeys most of the styling information specified by the preamble we created above. However, there are a few things that it overrides. Follow steps 3-7 from the next section to fix these up.

### Setting up the child documents

In my case I put each child document in it’s own folder. This is not necessary, but it seemed like a good idea to keep the child documents in a folder together with any figures used by that document. I will walk through the creation of a single child document here. I created all the chapters initially by just copying the first one I created, but you could do it in a more organised way using LyX templates. The steps for creating the chapter are:
1. Create a new empty LyX document and save it to a folder with the chapter within your thesis directory.
2. Add the document to your main document using the include procedure described above.
3. Open up the settings of the chapter document, and set the document class to Book, and in the master document field, point it at your main.lyx document
4. On the font section, change the default family base font size to what ever your university requires. This was different than the default for me.
5. Tick the Two-sided document check-box under Page Layout. This sets it so that the margin is wider on the outside-edge of each page, so it looks right when bound as a book.
6. On the Language section, change it to English (Australian) or English (UK) if your not in the ’ol US of A.
7. Your university almost certain specifies a particular citation style. Specify that in the Bibliography section. My university (ANU) recommends a Author-year style:
8. In the LaTeX Preamble, add the command \input{../general-preamble}, which just points to the previously created preamble file. The main-preamble file is not used by the child documents.
9. If your using sub-folders for each chapter, place a copy of the thesis.sty and (for ANU) the anuthesis.sty files in the subfolder as well.
The above setup will mean that you can view each chapter separately in LyX using the eye button in the toolbar. The chapter can be viewed within the whole-thesis PDF using the button. When viewing separately, the bibliography references will display as question marks (?), whereas they will be displayed correctly in the whole-thesis PDF. There are some suggested work-arounds for this issue on on the LyX Wiki, but I couldn’t get them to work.

## Other productivity enhancements

There is a few additional setup steps you should go through in LyX if you haven’t already. These are not required, but they will generally increase your productivity.
• Setup Forward and Reverse Search
• Setup groups of chapters as LyX branches to make sending subsets of your thesis easier
• Setup math macros
• Add keyboard shortcuts for citations and cross-references.

## 32 thoughts on “Writing Your Thesis in LyX — A Setup Guide”

1. Thanks for sharing this Aaron!
In our department we normally write our results chapters as publishable articles (i.e. with document class as Article and its own bibliography), while Introduction and Conclusion chapters can be “normal” book chapters. I get warnings currently, but pdf still outputs if I ignore them. How do I change my main Thesis layout file to allow chapters written as “Article” document classes to be included as child documents without getting these warnings?
In all document settings (Document->Settings ->Bibliography) for both the thesis and the child documents I have set it to Natbib with Natbib style Author-year. But I still get an error message saying: “The package natbib has already been loaded with options:
[numbers,sort&compress]
There has now been an attempt to load it with options
[authoryear]”
Why would this be?

2. Ashu says:

Hey Aaron, thank you very much for this template. I have one small problem. The page where the chapter begins is tilted towards right side more and the rest of the pages on tilted to left side. I am not very knowledgable in Latex. Can you please let me know how do i fix this?

1. The template uses book layout, where the margin width changes on alternate pages. You can change this I think by going to settings->document then page layout, and unticking “two-sided document”. If that doesn’t work you may need to modify the margins in the “sty” file directly, which is fairly complex unfortunately.

3. Nikoleta says:

Hello Aaron!

Hereby I wanted just to thank you for making your template available – I am going to use it for my PhD thesis template. Thank you for sharing the template.

4. Pedro Sánchez Terraf says:

Dear Aaron,

I’m working with a team (two of us on LaTeX, and the third with LyX) over Dropbox and your post helped me to find the way to make separate LyX files (almost a search top hit!)

Although this was only _tangential_, I’m grateful

5. Ashok says:

Hello Aaron

Thank you for the great template!

I have a question about adding a new chapter, when i include the way u say, it just shows the whole content of the chapter in the main file. can you please let me know how to include in a correct way.

Thanks

1. Sorry I’m not sure what the problem could be. It definitely works for me. Try updating LyX perhaps.

2. Alessio says:

Same problem here, the include is not dynamic. LyX Version 2.1.4 (24 July 2015).
How do you set the include type to include?
Cheers

6. Ashok says:

Hey Aaron,

Thanks for the template, helped me alot. How do i added a new child document? whenever i go to insert->file->lyx document. it just adds the whole document’s content in the main file.
Can you please tell how to do it correctly.

1. It’s a little unintuitive in Lyx. You need to instead go insert->file->child document instead. Make sure “include” is set in the dropdown as well. If it doesn’t appear you may be using an old version of Lyx.

7. nina says:

hi Aaron, thanks a lot for this great post and sharing your files 🙂 I’ve been using it and managed to fiddle around with quite a few things (margins, etc), but this one still bugs me:

How do I make the file (main?anuthesis.sty?) recognize that the chapters without numbers (\chapter*{}) are just as cool as those with numbers? I have a summary in three languages, and , even though they show up in the document outline while I am working in Lyx, in the PDF they are not recognized. This causes that: (1) the headings of summary pages still bear the title of the previous chapter, and (2) they do not appear in the TOC.
I have tried including somewhere the solution I found by googling the problem, but that didn’t really work as I don’t know where exactly to include. Thanks in advance! 🙂 nina

1. Hm.. I’m not really sure how to fix that. One thing to try is export the lyx document as latex, and see if the suggested fix works there. It might be that lyx is overriding something. You can remove any commands that lyx inserts that look related.

1. nina says:

hm, ok, so after some more searching, it seems that the un-numbered sections (or chapters) NOT being included in the TOC is standard. I went around that by adding in latex-mode
etc for each unnumbered chapter, right below the title of the chapter.

Setting the correct name to appear in the header of each page of the section is a whole different matter. Header names are defined either in anuthesis.sty or in cleverref , and I have tried some versions of
\chapter*{Summary{\@mkboth{Summary}{Summary}}
to copy that for contents, references etc. in the anuthesis.sty, but this did not work neither when inserted in anuthesis.sty, nor in LaTeX preamble of the chapter, nor in the beginning of the chapter itself as a line in the Latex-environment .

If you have any other idea, please let me know.
Otherwise, it seems my Summaries (in 3 languages) will all have a “References” header.. But they will a least be listed in the TOC.

8. Zhiyue says:

Hey, Aaron!
Hello from Singapore. Thank you so much for the template.

I notice that the linespace setting can be changed in the file anuthesis.sty, line 150-152. However, this change applies to the global text. Could you please guide how to make the change only to the main chapters?
Thank you very much for the help.

1. I’m not sure what the best way is. Perhaps try the setspace package, it lets use change the spacing with \begin{spacing}{} and \end{spacing}, which you could wrap the main chapters with.

9. Thanh says:

Hi man,

Thank you for your template! Very useful.
I have a question regarding the margin. How can I change the margin of the whole document?
I try to add the tex commands in the general-preample.tex:
\usepackage[a4paper]{geometry}
\geometry{left=2cm,right=2cm,top=1.5cm,bottom=2cm}

But it does not seem to work.

Thanh

1. The anuthesis style file defines the margins. Try changing the commands in anuthesis.sty around line 150-160.

10. John Karkas says:

Hey man,

great post. I’m considering using your template for my thesis.

Running it through lyx and trying to preview the main file without touching anything at first, though, I get this error:

Description
{thesis}
You may only use one \LoadClass in a class file]

LaTeX Error: Missing \begin{document}.
Description
hesis}
You’re in trouble here. Try typing to proceed.
If that doesn’t work, type X to quit.]

I’m using the latest as of now version of LyX and latest miktex upgrades. I am not knowledgeable with workarounds of LateX errors, I have however used LyX in other projects of mine extensively. Any light shed is welcome!

1. Interesting error. It could be because you’re on windows, I’ll try compiling on my windows machine with fresh Lyx & miktex and see how it goes.

2. Looks like I found the problem. You can fix it by renaming the thesis.sty file in the unzipped files to another name, then change the \usepackage{thesis} line in general-preamble.tex to refer to the changed name.

11. Mark Hague says:

Hi Aaron,

I’ve been using your template and find it very useful, so thanks!
I have 2 issues though, perhaps you could help?

For some reason numbers in all titles are smaller and lower down (kind of like a subscript?). I really don’t like this styling, is there a way to change it so that numbers are the same size as letters?

I’m also having trouble with referencing. All the references for each chapter (child doc) appear in the main document (as opposed to just 1 list at the end) even if they are in a branch which not activated in the main document. Any ideas?

Thanks,
Mark

1. The numbers in the titles are typeset in “oldstyle” as it’s the default for the font I’m using. Some digits like 3 hang below the font baseline.
You may be able disable this, some googling suggested this might work. Switching to a different font, like Computer Modern, would also work.

For the reference issue, I believe that’s a known issue in Lyx. I’m not sure if it can easily be fixed. Perhaps export to pdflatex then compile on the command line?

1. Mark Hague says:

Thanks Aaron, the referencing issues seems to have sorted itself out. I should maybe have mentioned that the section titles with this issue have capitalised words. The problem seems to be that numbers are made smaller than words, which is especially strange looking with capital letters.

How would I go about changing to Computer Modern font? Is this setting in the .sty files you provided or can it be done through document settings?

1. You should be able to change the line “\usepackage[palatino]{anuthesis}” in the preamble file from “palatino” to “cm” to switch to computer modern.

12. M A says:

Thanks for everthing. I have a problem,” Open up the settings of the chapter document, and set the document class to Book, and in the master document field, point it at your main.lyx document”
in this part all doucments are not variable to me, i dont know why>>>I need the help!

13. ming says:

Thank you very much, this is very helpful! i am gonna use this template.

14. Anna says:

Dear Aaron,

I am writing my PhD thesis with Lyx but I have a problem. Some chapters are numbered, some are not but I’ve already found out how to put them in the index. However, not-numbered chapters still report the title of the previous chapter in the pdf! 🙁 What can I do?
Thank you very much.
Best regards,
Anna

15. You should be able to extract them anywhere, as nothing needs to be installed or configured. Just start editing the provided files, as a starting point for your thesis,

1. Leon says:

OK, cool, cheers Aaron.

16. Leon says:

Hi Aaron,

Good concise post. I have a question though…the files that are contained within your .zip, once extracted, where do I place them to enable me to use them within LyX?

Cheers,

Leon

1. Dawn Miller-McTaggart says:

Hello Aaron

Thank you for the great template!

I have a question regarding the references. My university does not require page numbers after each reference are as I am using in-text citation. How would you suggest removing the numbers? By amending the style package or creating a different bibliography command in the master document? Or both?