Latex Tips and Tricks for Writing a Thesis or Dissertation

The best tip I can give for thesis writing is to use Latex.  For large documents it will be far easier to use and look much better in the end.  However, there is a bit of a learning curve with Latex and it does so much that it can sometimes be difficult to even know all the cool things it can do.  This posts will cover some of the Latex tips and tricks I’ve learned while writing my thesis over the past month year way too long.  I’m not going to include all the stuff you usually see like how to include a figure or how to make things bold.  I assume that you know how to use google and there are thousands of pages of tutorials for those common items.  I’m just going to be discussing the lesser known tips that I found helpful for long documents like a thesis or dissertation.

1.  Non line breaking spaces

Latex uses its own algorithms to decide on the amount of space between words and where line breaks should occur.  It usually does a great job, but there are some cases where you really want a space but don’t want the second part to go to the next line.  This happens for me most often when I am putting units after a number such as: 750 MHz.  In latex there is an easy way to do this; just use a ~ (tilde) character instead of a space, such as: 750~MHz.

2.  Break up your tex file

When you start getting into large documents, it can take forever to find your place in a long tex file.  So I like to break it up by chapters with each chapter having a separate folder than contains its own tex file and images that is inside the main folder.  The main tex and bib files should be located in the main folder.  Then the question is how to put those individual files together.  There are two commands for this: \input and \include.  You can google both of those to find out more but I usually use \include since it works faster on larger files.  To include the file intro.tex that is in the folder 1-Intro use the command:
\include{1-Intro/intro}

3.  Images inside folders

If you are using the layout I described in item 2 then you will have the images for each chapter inside of a folder rather than in the main folder.  Because of this you would normally have to include the filepath in the name of the image when using \includegraphics rather than just the filename.  For a couple of images this is fine; but if you have a lot, it gets annoying very quickly. And if you decide to rename a folder, you’ve got to change all those file paths.  Instead, you can tell Latex to look inside those folders whenever you include an image.  With this method, you need to make sure you don’t have any images with the same name, even if they are in different folders.

For example, lets say we have a folder called 1-Intro that has a photo called mypic.jpg. Normally you would have to use:
\includegraphics{/1-Intro/mypic.jpg}
Instead, you use this command in the preamble of the main tex file, paying extra attention to the slash at the end:
\graphicspath{{1-Intro/}}
And then include your image as if it were in the current folder like:
\includegraphics{mypic.jpg}

4.  Use a “missing image” image

As you’re working, you’ll often need to insert an image that you don’t have yet.  Either because you’re waiting on somebody else or you don’t want to stop the writing process to go take a picture.  I find that sometimes I will forget that I need to insert a picture there if I don’t do it at the beginning.  Also, not having the picture there can throw off your page lengths or spacing.  So, at the beginning of a project, I create an image that says missing image and include that to take space and serve as a reminder.  You can put this image in any chapter folder but I usually just put it in the main folder.  You can use the width and height attributes of \includegraphics to make the image taller or shorter depending on the aspect ratio of the final image.

missing

5.  Demo mode for images

If you don’t want to put a missing image in for every image you don’t have or if you want to just compile your document without inputing all of the images, you can use the demo mode.  Demo mode tells Latex to ignore the images and instead fills that space with a black square.  It can make compilation much much much faster, especially when you have a lot of images.  To enable demo mode, just use the demo tag before the graphicsx package like this:
\usepackage[demo]{graphicsx}

6.  Labels for figures and sections

This is another one that is really important the longer your thesis is.  It is often necessary to reference a figure, section, or chapter.  If you have a short paper, you can just type the figure number.  But when the number of figures is constantly changing or being reordered, having to retype them every time is annoying.  Instead you can use a \label{} and give it a unique name to reference later.  Here is an example of using labels for a chapter and figure.

\chapter{My Chapter}
\label{ch:my_chapter}

\begin{figure}[h]
\includegraphics{mypic.jpg}
\caption{This is a caption}
\label{fig:mypic}
\end{figure}

And here is the code to make the sentence “As you can see in figure 1.1 that is in Chapter 1 on page 1…”:

As you can see in figure \ref{fig:mypic} that is in Chapter \ref{ch:my_chapter} on page \pageref{mypic}.

7.  List of figures, list of tables, and table of contents

I thought this one was pretty well known but a labmate told me yesterday that he didn’t include a list of figures because he didn’t want to type it all out.  Turns out, it’s super easy.  Just include these commands in your document:

\tableofcontents
\listoffigures
\listoftables

8.  Leaving something out of the Table of Contents

This is another one that I thought would be easy but took me hours to find online.  Normally, when you start a new chapter, section, or subsection you do it with a command like:
\chapter{Super Cool Chapter}
If you insert an asterisks after chapter, it will leave it off of the table of contents:
\chapter*{Super Cool Chapter}

9.  Adjusting the Table of Contents depth

The automatic table of contents is nice but by default it shows everything: chapters, sections, sub sections, sub sub sections, etc.  You can change this by using:
\setcounter{tocdepth}{1}
0 means only chapters, 1 includes sections, 2 includes subsections, etc.

10.  PDF links

This final tip is one I only found out about last night.  You can use the hyperref package to make all of the links in your thesis clickable.  This means of course that any urls can be clicked and it will take you to that webpage.  But even better is that it makes all of the names in the Table of Contents clickable and will take you to that chapter/section/etc.  This also works for any of the references we talked about in tip number 6.  Enable this by:
\usepackage{hyperref}
This can sometimes cause problems if you use labels for figures.  This can be fixed by putting this line in the preamble:
\AtBeginDocument{\let\textlabel\label}

11.  Textwidth

There are several times where you might need to specify the width of something relative to the width of the page.  I use this the most when I want an image to take up the full width of a page or when I have columns and I want two of them to each be half of the page width.  Since you know the width, you can hardcode this in, but anytime you change the width, you have to change every figure you’re using.  Instead you can use \textwidth which will evaluate to the width of the text on the page (usually it’s the width of the page minus the margins). You can also put a decimal in front of it if you want to specify half width or 75% width, etc..  Below is an example using this with a figure.

\includegraphics[width=\textwidth]{sample.jpg}
\includegraphics[width=.5\textwidth]{sample.jpg}
\includegraphics[width=.75\textwidth]{sample.jpg}

12.  Float Barrier

One of the best things about LaTEX is that you don’t have to worry about where you put floating objects (images and tables); latex will automatically place them at a location that makes things look best.  One of the most frustrating things about LaTEX is when in puts floats pages away from where you wanted them.  It won’t let them images appear after a chapter break, but it will let them appear after a new section or subsection.  What I finally found was \FloatBarrier (capitalization important) that basically says, any floats that were included above this point in the code cannot appear after this line.  Whenever I’m dealing with multiple sections in a chapter, I put the \FloatBarrier command right before I start a new section.  This is easily one of the best tips I’ve found since I’ve started using LaTEX.

13. Multiple Captions

Earlier I mentioned that you can use \listoffigures to generate a list of all the figures with page numbers.  What appears on this page is the caption that you have put under the figure.  This works great if you’ve got a nice short caption, but if you have several lines, that can make a messy and uninformative list of figures.  What I do in these cases is put two captions on the image using the following command under the \includgraphics command.
\caption[This appears in the list of figures]{This appears under the figure.}

14.  Add to Table of Contents

Sometimes you want to add something to the table of contents because it didn’t automatically get added.  This happens most often for me with the bibliography.  You can add it using the following command.  The second item in the command tells it what level to use in the table of contents.  The third item tells it what you want the table of contents line to say.
\addcontentsline{toc}{chapter}{Bibliography}

 

Well I hope you found these helpful.  If you have any other tips or tricks, feel free to share them in the comments below.

Advertisements

One thought on “Latex Tips and Tricks for Writing a Thesis or Dissertation

  1. Hi I need some help with a mega48 running the avr448 code from Doxygen. hall input pins are pulled low except for the C hall its OK. I’m using codevision to compile it and codevision found an error in the code error found was PCINT1 as no defined. PCINT 0,1,2 are commented out in bits.def file something about a conflict. email and I can send the files. I have tried changing the PCINT1 to PC_INT1 and did get it to download to the mega48

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s