 
\documentclass[11pt, a4paper, twoside, titlepage]{book}
\usepackage[latin1]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm,mathtools} % Most people will need these for mathematics

%Figures
\usepackage{graphicx}	%Graphics package
\usepackage[center]{caption}
\usepackage{subcaption}
\usepackage{wrapfig}  % Wrap text around figures	
\usepackage{float} % To place figures correctly

\usepackage{makeidx} % Probably important.
\usepackage{listings} % To include code-snippets
\usepackage{color}
\usepackage{hyperref} % Clickable links to urls, internal and external references etc.


\lstset{
    basicstyle=\footnotesize\ttfamily,
  identifierstyle=\bfseries\color{green!40!black},
  commentstyle=\itshape\color{purple!40!black},
  keywordstyle=\color{blue},
  stringstyle=\color{orange},
}


\usepackage{pdfpages}	% Packages to handle certain issues with the pdf conversion and landscape figures/tables
\usepackage{lscape} 

\usepackage[authoryear,square]{natbib} % References/bibliography package
\usepackage{footnote}
\usepackage[titletoc]{appendix} % Appendix + add to table of contents
\usepackage{sidecap}

\usepackage{lipsum}  % Make dummy text


% Table packages
\usepackage{tabularx}
\makesavenoteenv{tabular}
\makesavenoteenv{table}
\usepackage{array}
\usepackage{booktabs}
\newcommand*\rot{\rotatebox{90}}

\usepackage{changepage}
\usepackage{verbatim}
\usepackage{cprotect}
\usepackage{cancel}


%Special in-document vector graphics:
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc,positioning,3d,intersections,arrows}
\usetikzlibrary{decorations.markings}
\usepackage{pgfplots}


% Custom characters
\newcommand{\slfrac}[2]{\left.#1\middle/#2\right.} % Long on-line fraction-slash: \slfrac
\newcommand{\degree}{\ensuremath{^\circ}} % The 'degree' character : \degree
\DeclareRobustCommand{\orderof}{\ensuremath{\mathcal{O}}} % The 'Order of' character: \orderof




%Epigraph / quote
\usepackage{epigraph}
\setlength\epigraphwidth{.8\textwidth}
\setlength\epigraphrule{0pt}



\title{Typesetting your Master's Thesis with \LaTeX -- A pragmatic approach.}
		
\author{%
	\large
	\textsc{Tarjei Antonsen}\\[2mm]
	\normalsize	University of Troms{\o} \\
	\normalsize	\href{mailto:tarjei.antonsen@uit.no}{tarjei.antonsen@uit.no}
	\vspace{-5mm}
	}
\date{October 2014}

\begin{document}

\maketitle
\frontmatter

\chapter*{\centering \begin{normalsize}Abstract\end{normalsize}}
\addcontentsline{toc}{chapter}{Abstract}
\noindent This work is a short introduction to \LaTeX\ and how to typeset and format a Master's thesis in it. The document itself also functions as a most basic template for a Master's thesis. This allows for students to write their own thesis directly in to the template without any extensive additional formatting, in addition to being flexible for personalization and further tweaking. In either scenario, the student should end up with a Master's thesis of high quality; superior to any commercial text editor, without mentioning specific softwares (yes, it is indeed MS Word and OpenOffice).

You are currently reading the abstract which is the summary of the following work. Often the reader will benefit from a short introduction to the subject of which the thesis concerns itself and where the current work contributes to this. The methods used should be introduced, with emphasis on the improving aspects of your method. Important or never before used parameter values can be mentioned -- such as $\rho_s=3000$ kgm$^{-3}$. The most important results and discussions should also be mentioned accordingly to the conclusions. If you have concluded with something which renders the findings of e.g. \citet{tomsic1,havnes07} redundant, you may also mention this as an additional selling point.
\clearpage

\chapter{Acknowledgments}
Above all, I wish to express my sincerest gratitude to my supervisor Prof. Bob Saget.\\ 
\\
I also love my girlfriend. LOL, JK, don't have one. I am sad.
\\
\\
\qquad \emph{Barack Obama},\\
\qquad \emph{October 2014}

\newpage

\thispagestyle{empty}
\vspace*{\fill}
\epigraph{\itshape Begin at the beginning, the King said gravely, ``I like big butts and I cannot lie''}{---Lewis Carroll, \textit{Sir Mix-A-Lot in Wonderland}}




\tableofcontents
\mainmatter


\chapter{Introduction}
\TeX\  and \LaTeX\ are a typesetting system and document preparation language, respectively, which have become the \emph{de facto} standard in academia. Due to its versatility and the fact that it is highly customizable, \LaTeX\ is also the most common tool to use when typesetting a Master's thesis. In this text we introduce this tool with a pragmatic approach, i.e. we skip the name-dropping of esoteric commands and low level 'programming' in \TeX. Indeed, if I were to comment on every command and macro used in this document, the course would become long and tedious. A certain amount of self study should accompany the understanding of this text.

The first chapter will introduce the work area, i.e. the TeX-file, in which you write your thesis. A standard disposition for a typical Maser's thesis is also presented. Chapter~\ref{chp:refer} introduces the topic of referencing; internally and to literature. The topics are introduced in such a manner that a novice should be able to utilize the basic function of bibliography handling in \LaTeX. For the curious student, hints to the further investigation of built-in functions are given. In chapter~\ref{chp:figtab} we introduce the formatting of figures and tables. The most common types are shown by examples, and the more sophisticated TikZ-package for making in-document vector graphics is also introduced. This last point will not be interesting for the average reader, but it is an option worth looking in to if one wants to include figures of professional quality. A good alternative to this -- importing \LaTeX-figures in vector format from MatLab -- will also be introduced. General typesetting of equations and text will also be discussed.

Note that the very document you are currently reading is in a format that will fit very well with a Master's thesis. The document contains several hints and quick-fixes to common problems with \LaTeX which the average user is very likely to encounter. The pragmatic user can merely use the source code for this introduction as the template for their own thesis. There are currently no definitive rules (or templates) for the appearance of a Master's thesis at UiT. Many students therefore modify their thesis according to personal preferences. This is allowed and can yield a nice result, but my advice is that you keep the thesis to a classical formal looking document -- Less is more (it really isn't, though). 




\section{The preamble}
The preamble is basically everything which is specified before the command \verb|\maketitle| in your main document. It mainly consists of a list of \emph{packages} which you want to include to typeset your thesis. The command \verb|\usepackage[Preference]{Name}| will add a certain package with the preference you want. E.g. \verb|\usepackage[center]{caption}| will center your figure captions in floating environments. Do not worry to much about what packages to include. The source code to this text probably contains all the packages you will need (almost too many), and the addition of other packages is done by writing the presented command into the preamble. Most \LaTeX-distributions already have all the normal packages downloaded, so the issue with manually downloading packages can normally be avoided. 

The specification of custom commands can also be done in the preamble. For instance, the 'degree' character is not built in, and we can manually make the character by specifying:
\begin{verbatim}
\newcommand{\degree}{\ensuremath{^\circ}} 
\end{verbatim}
So that I can say: '$71\degree$ Nord' is a bag of horse manure. However, you will most likely not need to specify many custom commands, and macros, and Google will help you if you absolutely must.

A last, rather important, command is the very first one of the entire document: \verb|\documentclass[11pt, a4paper, twoside, titlepage]{book}|. This command specifies the main style of your entire document. I must comment on two of the specified preferences. The first option '\textbf{11pt}' specifies the font size. I strongly recommend to use 11 pt instead of 12 pt for two reasons: 1) It looks better, 2) Using 12 pt does \emph{not} make your document particularly longer; try it. The option '\textbf{twoside}' is the recommended option to use for documents which are to be \emph{printed} physically on both sides of the sheets. You may have noticed that in this document, the even and odd pages have different margins to overcome the loss of margins towards the middle of the printed book when it is opened.


\section{The main TeX-document}

There isn't really much too you main document. It is just a plain text file in the .tex-format, and if you really wanted to, you could write your entire thesis in any notepad. The biggest advantage with using \LaTeX\ editors and specialized software, is that the code is color coded and usually well-presented. Apart from that, with the ''few'' commands you need when writing a thesis, I always prefer using the most basic programs without 'too many options' (e.g. TeXShop). If you are bombarded with opportunities, the probability of using some unnecessary option will be significant. Many users, however, may save some time by using the built-in macros and shortcuts which many distributions have, and this is of course recommended.

\subsection{Sectional hierarchy of the 'book' format}
A thesis is normally structured into chapters which contain sections and subsections. The primary commands to make a new object of one of these classes are:

\begin{verbatim}
\chapter{...}
\section{...}
\subsection{...}
\subsubsection{...}
\end{verbatim}

\noindent These commands will also add the object to the table of contents. It is of course possible to add an object which is \emph{not} numbered and which is emitted from the table of contents. This is done by simply adding an asterisk before the object name, e.g.:

\begin{verbatim}
\subsection*{Example 1}
\end{verbatim}

\subsection{An alternative main TeX-file -- Modular \LaTeX}
So far we have presented the main TeX document in such a way that it should be written in one large file. Some \LaTeX-users, especially programmers and computer scientists, will insist to treat the thesis main file as exactly this: a \emph{main} file which simply gathers the chapters and where no substance is provided. This is certainly a neat method, but it does offer a problem in that it is by far less searchable than the normal fused file. A Master's thesis usually consists of relatively few and possibly long chapters. It is clear that the benefits of separating chapters will vanish when the chapters in their own sense are long and 'messy'. A problem I often encountered when using external chapters was that when searching for a certain reference, phrase or whatever, which I \emph{knew} was in the thesis somewhere, it often ended up being in a different chapter than in the first or second chapter I searched in. If you still want to include chapters via external files, these two commands will do the task:

\begin{verbatim}
\include{/path/folder/file}
\input{/path/folder/file}
\end{verbatim}



\section{Disposition of a Master's thesis}
The disposition of a thesis is, of course, completely dependent on the type of study and to some degree personal preferences. Many students, including me, have a hard time starting to shape their thesis without a rough outline or plan. I therefore present below a very general setup of a thesis in which each of the points will normally be so important that they deserve an entire chapter:

\begin{description}
  \item[I] \hfill \\
  \textbf{Introduction}. Breifly describe the history and current state of knowledge of your field. Motivate your study and describe your angle of attack. Mention important results. Finally, give a summary of the outline of the thesis. 
  \item[II] \hfill \\
  \textbf{Background}. Extensively describe the components involved in your thesis; both general and on a more basic level. This must be well referenced and backed up by the literature. Try to include as many new studies as possible, as it shows that you are on par with the current knowledge.
  \item[III] \hfill \\
  \textbf{Methods}. Your approach to the problem. You may describe how your methods differ from other approaches here.
  \item[IV] \hfill \\
  \textbf{Theoretical model}. If you have developed or you are using a theoretical model, e.g. in simulations or other considerations, discuss them here. For purely theoretical studies, this is your most important chapter and it will normally overlap with the methodology description. Derivations may be presented here.
  \item[V] \hfill \\
  \textbf{Results}. Present and thoroughly describe your findings.
  \item[VI] \hfill \\
   \textbf{Discussion}. Discuss your findings. Assess the successfulness of your approach. Discuss how your work contributes to the current literature.
  \item[VII] \hfill \\
  \textbf{Conclusions} 
\end{description}

\noindent Depending on the type of study, some of these points may be skipped or fused together with others. In most cases, a thesis will not benefit from having many additional chapters than the ones proposed here. To describe the connections between topics which may seem natural to separate between in a single chapter, is certainly an art which is appreciated in the assessment of a thesis as it can show that a candidate has a deep understanding of his field.


\section{A general note on customization of the thesis layout}
As this text is merely a short introduction to thesis writing in \LaTeX, only a handful of commands will be presented, and we offer only the most classic and simple template for a Master's thesis. This will offer students who consult this guide and its corresponding resources many degrees of freedom when it comes to personal styling. This is allowed and encouraged, as long as the graphical expression does not steal attention from the content. As mentioned, UiT has no definite constraints on the thesis layout, but it is recommended that the candidate follow the official graphical profile of the university. The official front page  for a Master's thesis and other graphical details may be found at \url{http://uit.no/ansatte/grafiskprofil/artikkel?p_document_id=349513}.


\chapter{Referencing}\label{chp:refer}
\epigraph{\itshape I always wanted to place a lame quote in the start of a chapter. Get to the chapter!}{---Arnold Schwarzenegger, \textit{Mein Kopf}}


\section{Internal references}
By internal references we mean references to chapters, sections, figures, tables, equations etc. which is in your thesis. Two simple commands will get you a long way. First you will need to create a label for the object you want to refer to. In the first line of this chapter I have included the command \verb|\label{chp:refer}|. To cite the chapter, we simply use :
\begin{verbatim}
~\ref{chp:refer}
\end{verbatim}
which produces this:~\ref{chp:refer}. The \verb|\ref| command should be used for all internal references except when you are referring to equations. The command

\begin{verbatim}
\eqref{very_short_equation}
\end{verbatim}

\noindent can be used to refer to e.g. eq.~\eqref{very_short_equation} below, which is the shortest and most comprehendible equation in the world.

\begin{align}\label{very_short_equation}
\vec{F}_{drag} &= \pi r_d^2 m_g n_g v_{th,g}(\vec{v}_g-\vec{v}_d)\frac{1}{u}\Biggl\{\frac{1}{\sqrt{\pi}}\left(u + \frac{1}{2u}\right)\text{exp}(-u^2)\nonumber \\
&+ \left(1+u^2-\frac{1}{4u^2}\right) \text{erf}(u)\Biggr\}
\end{align}

\section{A proper bibliography}
The standard \LaTeX\ bibliography support has its main limitations in its few formatting options and that the implementation tends to become 'messy' when dealing with several citations. We introduce here how to combine the \textbf{natbib}-package with BibTeX for handling the bibliography, as it offers complete control over the style of both the citations and  the bibliography itself.

The main advantage of this method is that all citations are separated from your main document in a database file from which references are imported. This saves your work file hundreds of lines of code. It should also be mentioned that most scientific journals will let you export the citation (online) of almost all their published material in the BibTeX-format -- you will rarely need to physically write down a reference to an article. In addition to this, BibTeX/natbib offers full control over the style in which citations are presented. However, it must be stressed that the classical styles (Harvard Number-Year, Numeric etc.) are recommended for use in a Master's thesis. A few options are discussed below.

\subsection{The bibliography database}
Bibliography management with the tools mentioned above allows us to use multiple database files, however one single file is in most cases preferable. The bibliography database is essentially just a text file -- in the \textbf{.bib} format. An entry in the database consists of fields such as the mandatory author, journal name, volume, year etc. but can also be extended to contain e.g. digital object identifier (DOI). This latter data field is not required but recommended as it makes the lookup of an article much easier. It should be noted that different publication types require different data fields, and BibTeX will automatically format the bibliography entry according to the specified type.

\subsection*{Example}
In this example we show the input and output of one database entry of the type 'article', which is the type you will be referring to the most. As mentioned, other publication types such as 'book', 'phdthesis', 'inproceedings', etc. require a different data field setup. I refer to the WikiBook on this topic -- \url{http://en.wikibooks.org/wiki/LaTeX/Bibliography_Management} -- if you need to manually write in such references. The following input will produce the output seen in figure~\ref{bibentry}:


\begin{verbatim}
@article {havnes96,
author = {Havnes, O. and Tr{\o}im, J. and Blix, T. and 
         Mortensen, W. and N{\ae}sheim, L. I. and Thrane, E. and 
         T{\o}nnesen, T.},
title = {First detection of charged dust particles 
         in the {E}arth's mesosphere},
journal = {Journal of Geophysical Research: Space Physics},
volume = {101},
number = {A5},
issn = {2156-2202},
doi = {10.1029/96JA00003},
pages = {10839--10847},
year = {1996},
}
\end{verbatim}

\begin{figure}[H]
 \centering
	\includegraphics[width=0.9\textwidth]{Figures/bibentry_example}
		\cprotect \caption{An example of a bibliography entry. Note that the first entry, 'havnes96', is the citation key. This is unique and specified by the user.}
			\label{bibentry}
 \end{figure}
\noindent The only data field here which is not required is the 'doi'-field, but this is strongly recommended. Abstracts and url's (because of their messy presentations -- use DOI) for articles should not be included.


\subsection{How to create and include a database}
The first thing you need is a database file in the .bib-format. Included in the resources of this introduction is an example file named '\verb|database_template.bib|' -- use this. 

The next step to conquer \xcancel{the world} bibliography management, is to include your references. This is ridiculously easy  with BibTeX. The fastest way to do this is to google the article you are looking for and visit its page at the publisher (normally the top hit). Somewhere on the article home page there should exist a button which says something like 'Export citation' (to BibTeX) -- et voila! Sometimes you must download an entire .bib-file just for the one reference, but remember: Copy/Paste is your friend.

There are a number of other options. The online databases of Google Scholar, Harvard ADSABS, WebOfKnowledge and UiT's own Munin are other portals which offer a fast way to export citations directly. 

If you do need to  write in a bibliography entry manually, it is often preferable to just write the reference directly into your main .bib-file. Software such as BibDesk and EndNote are bibliography management programs which have GUIs for entering items. In any case, it is good practice to include the reference to a work the second you use it. Never write a reference directly in your text (!) The method described below in section~\ref{citation_style} is the safest way to avoid redundant citations.


\subsection{Citation style and use}\label{citation_style}

The format of a citation is mainly a concern of the \textbf{natbib}-package. The possibilities are endless, and the citation style is frequently a discussion topic among \LaTeX\-users. There are no definite requirements to bibliography style at UiT, but we present here a style inspired by one of the most common formats; The Harvard  style with a so-called Author-Year format. If you intend to customize your own thesis' citations and bibliography, my best tip is: do not get too fancy with the references. In any case, the most common styles are listed in \url{http://en.wikibooks.org/wiki/LaTeX/Bibliography_Management#Natbib}.

An important note to students who intend to use the standard style bibliography, is that there might be problems with the format of the bibliography it self. In the standard bibliography styles of natbib, the surnames does not come first even though the list is alphabetical after the surnames. This is fixed in the appended bibliography style \verb|'Template_LastNameFirst_Alphabetical.bst'|. To use this style, just include the file in the same folder as your tex-file.\\
\\
In the preamble the following should be specified:
\begin{verbatim}
\usepackage[authoryear,square]{natbib}
\end{verbatim}
The 'square' denotes the shape of the parenthesis or brackets used. My favorite is square, but 'round' is the most common choice. To include the bibliography style file and the database file, the following should be specified at the end of the document, right before the command \verb|\end{document}|:

\begin{verbatim}
\bibliographystyle{Template_LastNameFirst_Alphabetical}
\bibliography{database_template}
\end{verbatim}

\noindent When citing there are mainly two commands one will need:

\begin{verbatim}
\citet{something00}
\end{verbatim}

\noindent which will produce the standard citation, e.g. Something et al. $\left[2000\right]$, and:

\begin{verbatim}
\citep{havnes96}
\end{verbatim}

\noindent which will produce the citation \citep{havnes96}, i.e. in parenthesis. You may also add comments, such as: 

\begin{verbatim}
\citep[see][eq. 6]{havnes96}
\end{verbatim}

\noindent which will produces the citation \citep[see][eq. 6]{havnes96}. For further options, check the WikiBook.





\chapter{Figures and tables}\label{chp:figtab}
The traditional thesis contains a large number of figures, tables and miscellaneous graphical objects. How these are presented and how they look is from a graphical point of view the most important aspect of your thesis -- more important than 'blinging' up your document with all sorts of fancy headers and other details. Now, if you present data from experiments in your figures, the data will speak for itself and the assessment of your work should in principle not include the graphics itself. That being said, a thesis with $\orderof(10)$ well presented figures is a delight to read and will only give plus points in the overall assessment.

In section~\ref{figures} we present different types of figures and give a short tutorial on how to produce different figure styles. Section~\ref{formats} gives a brief introduction to figure formats, general presentation and how to produce \LaTeX\ style figures with MatLab. We also present, in section~\ref{tikz}, a package called TikZ for making vector graphics and plots directly in your TeX document. This option can be time consuming and require a little more than a basic understanding of \LaTeX, but will produce professional looking outputs fitting even for the most well-known scientific journals.

The end of the chapter introduces shortly how to format tables and lists with a few different options.



\section{Figures}\label{figures}
Figure handling with \LaTeX\ usually offers few problems one takes certain precautions. Including the two packages 'float' and 'graphicx' in the preamble;

\begin{verbatim}
\usepackage{graphicx}
\usepackage{float}
\end{verbatim}

\noindent will provide a versatile framework to handle figures, with few issues.

The following lines will import and typeset figure~\ref{reldiff}:  

\begin{verbatim}
\begin{figure}[h]
\centering
	\includegraphics[width=0.75\textwidth]{Figures/relative_difference_v0450pdf}
\caption{Example figure created with MatLab.}
\label{reldiff}
\end{figure}
\end{verbatim}

\noindent This is a standard setup for importing, typesetting and centering any figure. The width of the figure should be specified by the author, and the specifier \verb|[h]| is the option of placement of the figure/float. This is discussed in more depth below.

 \begin{figure}[h]
 \centering
	\includegraphics[width=0.75\textwidth]{Figures/relative_difference_v0450pdf}
		\caption{Example figure created with MatLab.}
		\label{reldiff}
\end{figure}

Even though the figure environment will function well with the \verb|[h]| specifier, during the course of the typesetting of your thesis you are likely to encounter a few problems. I'll thus discuss some common issues.

The mentioned specifier \emph{h} means 'approximately here', and \LaTeX\ will look for a way to place the figure as close as possible to where you have specified in the document. This rarely happens -- and it should certainly not. \LaTeX\ will place the figures (or 'floats' as we may call them) according to the most correct syntax per definition. However, for various reasons, the typesetter may not find obvious spots to put the figures, and one might get en error such as \emph{'Too many unprocessed floats'}. The following command:

\begin{verbatim}
\clearpage
\end{verbatim}

\noindent will then force all floats (i.e. figures and tables etc.) to be typeset. This can be smart to do by default in the end of each chapter or long sections to prevent that figures from a certain section gets printed in the next.

Another possible issue is that the choices the typesetter does for you will not always be perfect. On rare occasions you'll possibly need to force the figure to stay exactly where you put it in the text. This kind of tweaking is very common to perform in the finishing stages of the typesetting when no new floats are to be placed or text is to be added. In this case, simply swap the specifier \verb|[h]| with \verb|[H]|, but be careful not to use this option too much. Section~\ref{formats} elaborates on the float specifiers.


\subsection*{Wrapped figures}
\begin{wrapfigure}{r}{0.55\textwidth}
  \vspace{-25pt}
\begin{center}
	\centering
	 \includegraphics[width=0.53\textwidth]{Figures/figure_wrapped.pdf}
	\end{center}
	 \vspace{-20pt}
	\caption{A wrapped figure often requires 
		fiddling with parameters.}
	\label{wrap}
	\vspace{-10pt}
\end{wrapfigure}

This figure type can in certain circumstances be the best way to present a figure, but it can be notoriously tricky to place correctly. If you plan to use this type, you will most probably need to mess around with a few parameters. The few times I have utilized this option I have used the following code which I realize now is total rubbish. It does however work, but can imagine a few other ways to solve this. Google at your own (last) will.\\

{\footnotesize
\noindent \begin{minipage}{\textwidth}
\begin{lstlisting}[language={[LATEX]TeX},frame=single]

\subsection*{Wrapped figures}
\begin{wrapfigure}{r}{0.55\textwidth}
  \vspace{-25pt}
 \begin{center}
   \centering
   \includegraphics[width=0.53\textwidth]{Figures/figure_wrapped.pdf}
  \end{center}
  \vspace{-20pt}

\caption{A wrapped figure often requires 
	fiddling with parameters.}
\label{wrap}
\vspace{-10pt}
\end{wrapfigure}
\end{lstlisting}
\end{minipage}
}

\subsection{Formats and general presentation}\label{formats}
The format, i.e. the file type, of your imported figure should be such that it has a resolution which is higher than the printed thesis which is normally 300 dpi. Said more pragmatically: stay away from jpegs and other compressed formats and use formats with a high resolution, preferably vector graphics. You do not need to save space for your Master's thesis, it deserves only the best quality figures. The best formats are EPS, PDF and TIFF, and if you ask me they are equally good. A minor benefit of the first two formats is that they can be exported from for instance MatLab in a vector format which only saves the graphical objects them selves, which in practice means that plots with only lines and primitive shapes take up almost no space. To directly make \LaTeX\ labels in MatLab use the following syntax:
 
\begin{verbatim}
ylabel('Some parameter, $\frac{P\cdot m^2}{N}$ ',...
       'FontSize',11,'interpreter','latex')
\end{verbatim}

Now for the issue with where and how to place the figures. We have earlier encountered the standard placement specifier \verb|[h]| which will most often place normal size figures correctly according to good typesetting. A few notes should be made. Tables and figures which span over the entire width of a page look best at the top. The specifier for this is \verb|[t]|. You may also place an object at the bottom of a page by using \verb|[b]|. I refer to the WikiBook on the subject of float handling for further options. An option which will not be discussed here is the \emph{subfigure} environment which allows for placing figures into columns or rows, this is however a common feature to use in many works. The Wiki also covers this. \\
\\
\noindent \textbf{Wiki:}\\
\url{http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions}



\section{TikZ -- Superb looking vector graphics.}\label{tikz}
This section will not include any code (which may be found in the  document TeX-file), and will only present a few neat examples of what TikZ can be used to create. Together with the package \textbf{pgfplots}, TikZ is great tool for producing vector graphics directly in a TeX-file. I won't lie, if you choose to pursue this option, you must invest a little time in the figure preparation. Importing your own data series into TikZ is possible and straightforward. The novice way to use TikZ/pgfplots is to browse the large online gallery of pgfplots and find a figure which resembles what you want to produce and modify the given code. Libraries can be found at:\\
\\
\url{http://pgfplots.sourceforge.net/gallery.html} and \\ 
\url{http://www.texample.net/tikz/}.

\subsection*{A few examples}

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.8, baseline]
\begin{axis}[
	axis x line=bottom,
	axis y line=left,
	axis y discontinuity=crunch,
	axis x discontinuity=crunch,
	grid=major,
	%ymin=0.4e-9,
	%xmin=0.008, 
	xlabel=Height (km),ylabel=Negative current ($\cdot10^{-10}$A), 
	xticklabels={81,81.05,81.1},xtick={2,7,12},
	yticklabels={-3,-5,-8},ytick={1,1.4,1.8},
]
\addplot[blue,mark=none,
	 domain=2:4,samples=501]
	{ln(x)}node [pos=0.3,pin={-10:$V_{BP}=10V$},inner sep=1pt] {};	
   \addplot[dashed,blue] plot coordinates {
          (4,1.38629)
          (4,1.18629)
        };       
\addplot[blue,mark=none,
	 domain=4:6,samples=501]
	{ln(x)-0.2}node [pos=0.4,pin={-40:$0V$},inner sep=1pt] {};	
   \addplot[dashed,blue] plot coordinates {
          (6,1.5917594)
          (6,1.2917594)
        };        
\addplot[blue,mark=none,
	 domain=6:8,samples=501]
	{ln(x)-0.5}node [pos=0.5,pin={-80:$-10V$},inner sep=1pt] {};	
   \addplot[dashed,blue] plot coordinates {
          (8,1.87944)
          (8,1.57944)
        };
 \addplot[blue,mark=none,
	 domain=8:10,samples=501]
	{ln(x)-0.2}node [pos=0.3,pin={-86:$0V$},inner sep=1pt] {};
   \addplot[dashed,blue] plot coordinates {
          (10,2.30258)
          (10,2.10258)
        };	

 \addplot[blue,mark=none,
	 domain=10:12,samples=501]
	{ln(x)}node [pos=0.3,pin={-86:$10V$},inner sep=1pt] {};
	
	 \addplot[blue, dotted,
	 domain=2:12,samples=501]
	{ln(x)};
		
\end{axis}
\end{tikzpicture}
\caption{Crunched axes and in-figure text.}
\label{detectionoffrags}
\end{figure}


 
 \begin{figure}[h]
 \label{fig:lard}
 \begin{subfigure}[t]{0.48\textwidth}
	\centering
\begin{tikzpicture}[scale=0.8, baseline]
\begin{axis}[
	axis x line=bottom,
	axis y line=left,
	axis y discontinuity=crunch,
	axis x discontinuity=crunch,
	grid=major,
	ymin=0.7e-2,
	%xmin=0.008, 
	xlabel=Fragment radius (m),ylabel=Braking length (m)
]
\addplot[blue,mark=none,
	 domain=0.2e-9:0.8e-9,samples=501]
	{33037373*x};
\end{axis}
\end{tikzpicture}
\end{subfigure}
	~\qquad\qquad
\begin{subfigure}[b]{0.44\textwidth}
\centering
 \begin{tikzpicture}[scale=0.4]
\node [draw, cylinder, shape aspect=4, rotate=90, minimum height=5cm,minimum width=3cm] (c) {};
\node[anchor=west] at (5.1,5) {$n_g$};
\node[anchor=west] at (5.1,0) {$m_g$};
\coordinate(htop) at ($(c.before top)!-1*.1!(c.after top)$);
\coordinate(hbot) at ($(c.after bottom)!-1*.1!(c.before bottom)$);
\coordinate(hlab) at ($(htop)!.5!(hbot)+(c.north)!.9!(c.center)$);
\draw[<->] (hbot)--(htop);
\path (hlab) node {$L$}; %Modify height label here
\coordinate (center) at ($(c.before top)!0.5!(c.after top)$);
\coordinate (rlab) at ($(center) !0.5!(c.after top)$);
\coordinate (rtop) at ($(center)!-1*.1!(c.after top)$);
\draw[<->] (rtop) -- (c.after top);
\path (rlab) node[above] {$r_d$}; %Modify radius label here
\draw[fill] (0,0.5) circle [radius=0.20];
\draw[->](0,0.5)--(0,-1.5);
\draw[->,>=stealth](3,3) to [out=60,in=180] (5,5);
\draw[->,>=stealth](3,-2) to [out=60,in=180] (5,0);

 \draw (-3.5,0.5) arc (180:360:3.5cm and 1cm);
  \draw[dashed] (3.5,0.5) arc (0:180:3.5cm and 1cm);
    \draw (0,0.5) circle (3.5cm);
    \shade[ball color=blue!10!white,opacity=0.20] (0,0.5) circle (3.5cm);
\end{tikzpicture} 
	\end{subfigure}
	\caption{Graph and schematic.}
	\label{fig:lard}
 \end{figure}



\begin{figure}[h]
 \centering
\begin{tikzpicture}
\begin{axis}[
scale only axis,
	grid=both,
	xmin=0.05,
	xmax = 2.15, 
	ymin=-13,
	ymax=12,
	ylabel=$V_{BP}$ (V),xlabel=Radius (nm),
	axis y line=left,
     axis x line*=bottom,
	]
\addplot[black, mark=square,line width=1.5pt] coordinates {(0.9,9) (1.2,9)};
\addplot[black, mark=square,line width=1.5pt] coordinates {(1.05,8) (1.4,8)};
\addplot[black, mark=square,line width=1.5pt] coordinates {(1.3,5) (1.6,5)};
\addplot[black,dashed,mark options=solid, mark=square,line width=1.5pt] coordinates {(1.5,0) (1.8,0)};
\addplot[black, dashed, mark=square,mark options=solid,line width=1.5pt] coordinates {(1.8,-10) (2.1,-10)};
\addplot[black, mark=square,mark options=solid,line width=1.5pt] coordinates {(0.4,11) (0.7,11)};

\end{axis}
\begin{semilogyaxis}[blue,
     scale only axis,
     ymin=5,ymax=145000,
   axis y line=right,
     axis x line=none,
     xmin=0.05,
     xmax = 2.15, 
     enlargelimits=false,axis on top=true,
     ylabel=MSP concentration (cm$^{-3}$nm$^{-1}$),ylabel near ticks]
     \addplot[blue, mark=triangle*, mark size = 4pt,line width=1pt] coordinates {(0.15, 100000) (0.4,10000) (0.9,1000) (1.4,100) (2.1,10)};
   \end{semilogyaxis}
\end{tikzpicture}
	\caption{Double y-axes tells the reader that he is probably looking at something important.}
			\label{ranges_concentration}
 \end{figure}

\begin{figure}[h]
\qquad \quad
\begin{tikzpicture}
\begin{axis}[cycle multi list={
	  black\nextlist
	  solid,{dashed,mark options={solid}}\nextlist
	  mark=none,mark=*,mark=x,mark=o,mark=square,
	},
legend entries={$V_{BP}=10$V,$V_{BP}=0$V,$V_{BP}=-10$V,$V_{BP}=5$V,$V_{BP}=8$V,$V_{BP}=9$V},
legend pos=outer north east,
grid=major,
axis x line=bottom,
	axis y line=left,
	ymax =1.05,
	xlabel=initial fragment radius (m) ,ylabel= Relative current ($I_{xV}/I_{ref}$)]
	\addplot[dotted] coordinates {(1.0e-9,1) (1.1e-9,1) (1.2e-9,1) (1.3e-9,1) (1.4e-9,1) (1.5e-9,1) (1.6e-9,1) (1.7e-9,1) (1.8e-9,1) (1.9e-9,1) (2.0e-9,1) (2.1e-9,1)};
	\addplot coordinates {(1.3e-9,0) (1.4e-9,0.06) (1.5e-9,0.3) (1.6e-9,0.54) (1.7e-9,0.78) (1.8e-9,1)};
	\addplot coordinates {(1.6e-9,0) (1.7e-9,0.08) (1.8e-9,0.32) (1.9e-9,0.56) (2.0e-9,0.82) (2.1e-9,1)};
	\addplot coordinates {(1.1e-9,0) (1.2e-9,0.12) (1.3e-9,0.36) (1.4e-9,0.6) (1.5e-9,0.84) (1.6e-9,1)};
	\addplot coordinates {(1.0e-9,0.2) (1.1e-9,0.42) (1.2e-9,0.66) (1.3e-9,0.88) (1.4e-9,1)};
	\addplot[dashed] coordinates {(1.0e-9,0.48) (1.1e-9,0.70) (1.2e-9,1)};
\end{axis}
\end{tikzpicture}
\caption{With legend. A tip: when publishing in scientific journals, figures with color can cost quite a lot to get printed. A workaround is then to make your figures with black lines and different line styles/markers only.}
\label{fig:smallgaps}
\end{figure}


\clearpage



\section{Tables}
The normal tabular environment, which is the environment in which you actually make the table, have  many limitations. The best tip I can give is that you should make a standard table which looks decent, and include the packages you need for making that table and subsequently add packages as you go along modifying your template. The following lines added to the preamble will add formatting options for tables sufficient for most applications. 

\begin{verbatim}
\usepackage{tabularx}
\makesavenoteenv{tabular}
\makesavenoteenv{table}
\usepackage{array}
\usepackage{booktabs}
\newcommand*\rot{\rotatebox{90}}
\end{verbatim}

\subsection*{A standard table}
The following lines of code will produce the table shown in table~\ref{tab1}. Note that the placement specifier \verb|[ht]| is used here; a better choice for broad tables. In \verb|\begin{tabular}|, the limiter '$|$' denotes a column which is separated by a line; \textbf{c} denotes that each entry should be centered in its cell; the character \verb|&| separates between column, and \verb|\\| starts a new line (while \verb|\hline| typesets the line).\\

{\small
\noindent \begin{minipage}{\textwidth}
\begin{lstlisting}[language={[LATEX]TeX},frame=single]
\begin{table}[ht]
 \caption{Captions for tables should 
 be placed above the table!}
\begin{tabular}{c|cc|cc|cc}
 &\multicolumn{2}{c}{$v_0 = 350 m/s$}
 &\multicolumn{2}{|c}{$v_0 = 450 m/s$} 
 & \multicolumn{2}{|c}{$v_0 = 550m/s$}\\
 \hline
$r_0 [nm]$ & $E_f [eV]$& Hits [\%]&$E_f [eV]$  & Hits [\%]& $E_f [eV]$ 
& Hits [\%]\\ \hline
1.5 & --- & 0.0 & 0.0 -- 4.3 & 30.0 & 0.0 -- 12.4 & 86.0 \\
1.6 & --- & 0.0 & 0.0 -- 7.6 & 54.0 & 2.6 -- 17.9 & 100.0 \\
1.7 & 0.0--2.1 &12.0 &0.0--11.6 & 78.0 & 6.2--24.3 &100.0\\
1.8 & 0.0--4.5 & 32.0&1.3--16.2 &100.0 & 10.5--31.8&100.0\\
\end{tabular}
\label{tab1}
\end{table}
\end{lstlisting}
\end{minipage}
}



\begin{table}[ht]
 \caption{Captions for tables should be placed above the table!}
\begin{tabular}{c|cc|cc|cc}
 &\multicolumn{2}{c}{$v_0 = 350 m/s$}&\multicolumn{2}{|c}{$v_0 = 450 m/s$} &\multicolumn{2}{|c}{$v_0 = 550m/s$}\\
 \hline
$r_0 [nm]$ & $E_f [eV]$& Hits [\%]     & $E_f [eV]$  & Hits [\%]   & $E_f [eV]$ & Hits [\%]   \\ \hline
1.5 & --- & 0.0 & 0.0 -- 4.3 & 30.0 & 0.0 -- 12.4 & 86.0 \\
1.6 & --- & 0.0 & 0.0 -- 7.6 & 54.0 & 2.6 -- 17.9 & 100.0 \\
1.7 & 0.0 -- 2.1 & 12.0 & 0.0 -- 11.6 & 78.0 & 6.2 -- 24.3 & 100.0 \\
1.8 & 0.0 -- 4.5 & 32.0 & 1.3 -- 16.2 & 100.0 & 10.5 -- 31.8 & 100.0 \\
\end{tabular}
\label{tab1}
\end{table}
 

\subsection*{Tables with figures}
A table with embedded figures is often a nice way to represent concepts which are abstract. In the presented example in table~\ref{tab:chi}, the dynamic shape factors for different shapes are given. This is an abstract topic, and the confusion which may arise if just the name of the shape is presented is hopefully avoided. An important note: footnotes in tables are not straight forward. From my personal experiences, it is easier to simply hard code the footnotes in the table such as in the current example, but you can however still use the \textbf{cite}-commands. The following code produces the output.\\

{\footnotesize
\noindent \begin{minipage}{\textwidth}
\begin{lstlisting}[language={[LATEX]TeX},frame=single]
\begin{table}[t]
\caption{Example of table with figures.}
\begin{tabular}{lp{1.5cm}cc}
\hline
Particle type&&Diameter relations&Dynamic shape factor,$\chi$\\ 
\hline
\hline
\rule{0pt}{8ex}   
\parbox[c]{1em}{\includegraphics[width=2cm]{Figures/chi1}} 
&Sphere& $d_m=d_{ve}$& $\chi =1$\\

\hspace{1pt} \parbox[c]{1em}{\includegraphics[width=2cm]{Figures/chi2}}
&Sphere w/voids& $d_m=d_{ve}$& $\chi =1$\\
\hspace{1pt} \parbox[c]{1em}{\includegraphics[width=2cm]{Figures/chi3} }
&Agglomerates & $d_m>d_{ve}$& $\chi =1.5-1.6^{~(1}$\\
\hspace{1pt} \parbox[c]{1em}{\includegraphics[width=2cm]{Figures/chi4} }
&Dublet& $d_m>d_{ve}$& $\chi =1.12^{~(2}$

\end{tabular}
\noindent\rule{5cm}{0.4pt}\\
$^1$ \footnotesize Values from some guys et al. (2010) used for
 nano-scale chondritic products
 (Fe$_2$O$_3$, SiO$_2$ and MgO).\\
 
$^2$ From That Guy (1997).
\normalsize
\label{tab:chi}
\end{table}
\end{lstlisting}
\end{minipage}
}


\begin{table}[t]
\caption{Example of table with figures.}
\begin{tabular}{lp{1.5cm}cc}
\hline
Particle type & &Diameter relations & Dynamic shape factor, $\chi$ \\ 
\hline
\hline
\rule{0pt}{8ex}   
\parbox[c]{1em}{\includegraphics[width=2cm]{Figures/chi1}} &Sphere 		& $d_m=d_{ve}$	& $\chi =1$\\
\hspace{1pt} \parbox[c]{1em}{\includegraphics[width=2cm]{Figures/chi2}}&Sphere w/voids		& $d_m=d_{ve}$	& $\chi =1$\\
\hspace{1pt} \parbox[c]{1em}{\includegraphics[width=2cm]{Figures/chi3} }&Agglomerates 		& $d_m>d_{ve}$	& $\chi =1.5-1.6^{~(1}$\\
\hspace{1pt} \parbox[c]{1em}{\includegraphics[width=2cm]{Figures/chi4} }&Dublet 		& $d_m>d_{ve}$	& $\chi =1.12^{~(2}$
\end{tabular}
\noindent\rule{5cm}{0.4pt}\\
$^1$ \footnotesize Values from some guys et al. (2010) used for
 nano-scale chondritic products (Fe$_2$O$_3$, SiO$_2$ and MgO).\\
$^2$ From That Guy (1997).
\normalsize
\label{tab:chi}
\end{table}

\subsection*{Tables with rotated text}
Flipping text a certain angle is a feature which is often required. For this purpose we construct a very simple macro in the preamble, here named '\textbf{rot}',  which simply rotates the entire object a specified angle (here $90\degree$):

\begin{verbatim}
\newcommand*\rot{\rotatebox{90}}
\end{verbatim}

\noindent To use this, as shown in table~\ref{tab:rot} below, we have used e.g. \verb|\rot{\rlap{MSP}}| to fix in-cell alignment issues.


\begin{table}[h]
\centering
\caption{Rotating text in tables requires the use of exotic macros.}
\begin{tabular}{ccccc}
& $V_{BP}$ & Mean [nm] & $EB^-$ [L,U]& $EB^+$ [L,U] \\
 \cmidrule[1pt]{2-5}
\rule{0pt}{4ex}    
&0 V & 1.5--1.8 & [1.4, 1.8] & [1.6, 2.2] \\
\rot{\rlap{MSP}}
&-10 V & 1.8--2.1 & [1.6, 2.2]& [1.8, 2.5] \\ 
 \cmidrule[1pt]{2-5}
 \rule{0pt}{4ex}    
 &0 V& 2.9--N/A& [3, 2.5] & [3.4, N/A] \\
 \rot{\rlap{ICE}}
 &-10 V& 3.3--N/A& [3.0, $>3.5$] & N/A
\end{tabular}
\label{tab:rot}
\end{table}

\clearpage

\section{Lists}
There are a number of different ways to present lists of text or objects in \LaTeX. I simply mention the most common ones below. Note that lists can be nested in \LaTeX.

\subsection*{Bulleted list}
Use \textbf{itemize}.\\

\begin{minipage}{\linewidth}
      \centering
      \begin{minipage}{0.45\linewidth}
          \begin{verbatim}
\begin{itemize}
  \item Earth
  \item Wind
  \item Fire
\end{itemize}
\end{verbatim}
      \end{minipage}
      \hspace{0.05\linewidth}
      \begin{minipage}{0.45\linewidth}
          \begin{itemize}
  \item Earth
  \item Wind
  \item Fire
\end{itemize}      
\end{minipage}
  \end{minipage}
\\
\subsection*{Numbered list}
Use \textbf{enumerate}.\\

\begin{minipage}{\linewidth}
      \centering
      \begin{minipage}{0.45\linewidth}
\begin{verbatim}
\begin{enumerate}
  \item Six
  \item Six
  \item Six, the
   number of the beast
\end{enumerate}
\end{verbatim}
      \end{minipage}
      \hspace{0.05\linewidth}
      \begin{minipage}{0.45\linewidth}
   \begin{enumerate}
  \item Six
  \item Six
  \item Six, the number of the beast
\end{enumerate}   
\end{minipage}
  \end{minipage}\\

\subsection*{Custom description}
Use \textbf{description}. Note that \verb|\hfill| adds a horizontal gap.\\

\begin{minipage}{\linewidth}
      \centering
      \begin{minipage}{0.45\linewidth}
\begin{verbatim}
\begin{description}
  \item[Un] \hfill \\
  Bon
  \item[Deaux] \hfill \\
  Hiver
  \item[Trois] \hfill \\
  F\'{e}vrier
\end{description}
\end{verbatim}
      \end{minipage}
      \hspace{0.05\linewidth}
      \begin{minipage}{0.45\linewidth}
 \begin{description}
  \item[Un] \hfill \\
  Bon
  \item[Deaux] \hfill \\
  Hiver
  \item[Trois] \hfill \\
  F\'{e}vrier
\end{description}
  
\end{minipage}
  \end{minipage}










\chapter{Typesetting plain text and equations}
Text is the most space consuming part of most theses. Accordingly, when writing such a work, much attention should be paid to how the text is typeset. This is indeed the main concern of \LaTeX; to make sure text is formatted correctly. This chapter will shortly discuss how to treat normal text and what one can do with it. We also treat the typesetting of equations, and the use of special characters.

\section{Plain text}
There is no mystery to the topic of text and paragraph formatting in \LaTeX. Again, there is really not any point in an introduction to name-drop all formatting commands out there. Text can be \textbf{bold}, \emph{emphasized}, \underline{underlined}, {\LARGE large} or {\tiny tiny} and in a number of other customized styles. The online documentation of these options is vast and can be easily accessed.

When it comes to paragraphing, the typesetter will do this for you if you a line between paragraphs in your main document. The command '\verb|\\|' will force a line shift. If one wishes to omit the indent of a new paragraph, the command \verb|\noindent| before the first line will do the job.


\section{Equations and special characters}
In theoretical studies, the typesetting of equations and derivations can become a significant time sink. There exists a whole range of equation environments and packages which support special features which prevent need of custom macros (Protip: why implement something if it has already been done for you). I present here the most common environments and will also give an example of an extended derivation which incorporates many of the functions introduced.

\url{http://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics}


\subsection{Equations in general}
The standard equation environment syntax is as follows:\\

 \noindent \begin{minipage}{\linewidth}
      \centering
      \begin{minipage}{0.45\linewidth}
\begin{verbatim}
\begin{equation}
\lim_{x\rightarrow0} f(x) 
= \text{Dog}
\end{equation}
\end{verbatim}
      \end{minipage}
      \hspace{0.05\linewidth}
      \begin{minipage}{0.45\linewidth}
\begin{equation}
\lim_{x\rightarrow0} f(x) = \text{Dog}
\end{equation}
\end{minipage}
  \end{minipage}
\\
\\
\noindent Note that the equation is automatically numbered. If you want to remove the equation number, add an asterisk (or add \verb|\nonumber| in the normal environment):\\
\\
\noindent \begin{minipage}{\linewidth}
      \centering
      \begin{minipage}{0.45\linewidth}
\begin{verbatim}
\begin{equation*}
\lim_{x\rightarrow0} f(x) 
= \infty^{Moose}
\end{equation*}
\end{verbatim}
      \end{minipage}
      \hspace{0.05\linewidth}
      \begin{minipage}{0.45\linewidth}
\begin{equation*}
\lim_{x\rightarrow0} f(x) = \infty^{Moose}
\end{equation*}
\end{minipage}
  \end{minipage}



\subsection{Math mode: in-line equations}
For in-line equations or parameter specification it is not practical to use the unnumbered equation environment. The \emph{math mode} solves this issue. To use this mode, type your expression between dollar signs: \verb|$...$|. Protip: do not write multiple row expressions such as common fractions in-line. As an example, an in-line substitute for $\frac{\text{mbar}\times \ell}{s}$ can be $\text{mbar}\cdot \ell s^{-1}$. The math mode can also be used for longer expressions, which will be an equivalent for the unnumbered equation environment. To use this, use the square brackets, \verb|\[ ... \]|, and end up with something like:\\
\\
\begin{minipage}{\linewidth}
      \centering
      \begin{minipage}{0.45\linewidth}
\begin{verbatim}
\[
\int_\mathbb{R}  \mathrm{d}
\xi e^{\xi^2} = 42
\] 
\end{verbatim}
      \end{minipage}
      \hspace{0.05\linewidth}
      \begin{minipage}{0.45\linewidth}
\[
\int_\mathbb{R}  \mathrm{d}
\xi e^{\xi^2} = 42
\] 
\end{minipage}
  \end{minipage}




\subsection{Special equation environments}
There are a couple of other alternatives which are worthwhile mentioning. In small derivations or sets of coupled equations we often want to typeset lines of equations directly underneath each other. For a good presentation of such systems, the subsequent lines of equations should have some common anchor from which they can be aligned. In the environment \verb|align|, simply use the \verb|&|-character to place the alignment anchor. In the example below, note that this is placed such that all equal signs are aligned. Also note that \verb|\\| specifies a new line, and that \verb|\nonumber| removes the equation number for respective lines.



{\small
\noindent \begin{minipage}{\textwidth}
\begin{lstlisting}[language={[LATEX]TeX},frame=single]
\begin{align}
\frac{\mathrm{d}N}{\mathrm{d}t} &= n_0A_pv_{in} \nonumber \\

\frac{\mathrm{d}P_k}{\mathrm{d}t} &= \frac{k_B T}{V_k}
\frac{\mathrm{d}N(t)}{\mathrm{d}t} \nonumber \\

\Rightarrow v_{in}  &=  \frac{V_k}{n_0A_pT}\cdot \left(
		\frac{\mathrm{d}P_k}{\mathrm{d}t}\right)
\end{align}
\end{lstlisting}
\end{minipage}
}


\noindent will produce:

\begin{align}
\frac{\mathrm{d}N}{\mathrm{d}t} &= n_0A_pv_{in} \nonumber \\
\frac{\mathrm{d}P_k}{\mathrm{d}t} &= \frac{k_B T}{V_k} \frac{\mathrm{d}N(t)}{\mathrm{d}t} \nonumber \\
\Rightarrow v_{in} &= \frac{V_k}{n_0A_pT}\cdot \left(\frac{\mathrm{d}P_k}{\mathrm{d}t}\right)
\end{align}

\noindent For piecewise defined functions the \textbf{cases} environment will automatically bracket the definition correctly.\\ 

{\small
\noindent \begin{minipage}{\textwidth}
\begin{lstlisting}[language={[LATEX]TeX},frame=single]
\[
f(n) = 
\begin{cases} n/2 &\mbox{if } n \equiv 0 \\ 
(3n +1)/2 & \mbox{if } n \equiv 1. 
\end{cases} \pmod{2}
\]
\end{lstlisting}
\end{minipage}
}

\noindent Produces (note the math mode):
     
\[
f(n) = 
\begin{cases} n/2 &\mbox{if } n \equiv 0 \\ 
(3n +1)/2 & \mbox{if } n \equiv 1. 
\end{cases} \pmod{2}
\]

\section*{An extended example of a derivation}

\ldots We make two assumptions: (I) The dust particle mass is much larger than that of a gas molecule, i.e. $m_D>>m_g$, where $m_D$ and $m_g$ are the masses of single dust and neutral molecules, respectively. (II) The neutral gas molecules have velocities distributed after the Maxwell-Boltzmann distribution, thus in one dimension we obtain:

\begin{equation}\label{cucky}
f(v_g) = \left(\frac{m_g}{2\pi k_BT_g}\right)^\frac{1}{2}\text{exp}\left(-\frac{m_g v_g^2}{2k_BT_g}\right)
\end{equation}
where $f$ is the probability density described in appendix $\infty$.

We consider a small flat surface element of a dust particle which moves through a gas with velocity $\vec{v_d}$. Let the geometry be defined spherically, such that the polar axis is defined as the normal of the surface element. If the dust moves at an angle $\theta$ to this normal, as shown in figure~\ref{fig:collision}, the transfer of momentum to the dust grain in the polar direction becomes: 

\begin{equation}\label{mefisto}
\Delta p = 2 m_g(v_g + v_d\cos \theta)
\end{equation}
where we have used the assumption that $m_D>>m_g$.

\begin{figure}[t]
\centering
\begin{tikzpicture}[>=latex,scale=1.3]
  \shade[ball color=gray!20!] (0,0) coordinate(O) circle (1.5) ;
 \filldraw [draw=black,fill=blue,opacity=0.8] 
         (0.95,-0.65)--(1.75,-0.35)--(1.65,-1.1)--(0.85,-1.4)--(0.95,-0.65)--cycle ;?\draw[->](1.35,-0.95)--(2,-1.4);
\draw[dashed]
(1.35,-0.95) -- (2.325,-1.3) ; 
\draw[dashed]
(1.35,-0.95) -- (2.325,-1.6225) ;       
           \shade[ball color=gray!40!,opacity=0.9] (1.5,-1) coordinate(Hm) circle (.4) ;
 % \draw (4,.2) node[right]{H$^-$} ;
\draw (2.3,-1.3) arc (355:340:1) ;
    \node[] at (330:2.85)  {$\theta$};
\end{tikzpicture}
\caption{Schematic of geometry in collision between large dust particle and gas molecule. The respective sizes are not in scale.}
\label{fig:collision}
\end{figure}

We take into account the maxwellian nature of the neutral gas molecules, by using eg.~\eqref{cucky}. The probability of a gas molecule having a speed between $v_g$ and $v_g+\mathrm{d}v_g$ in one (the polar) direction is then:

\begin{equation}
f(v_g\rightarrow v_g+\mathrm{d}v_g)=\frac{1}{(\pi)^\frac{1}{2}v_{th,g}}\text{exp}\left(-\frac{1}{2}\frac{v_g^2}{v_{th,g}^2}\right)\mathrm{d}v_g
\end{equation}
where $v_{th,g}=(2k_BT_g/m_g)^\frac{1}{2}$ is the thermal velocity of the neutrals.

A small surface area of the surface of the dust grain is in spherical coordinates given as $\mathrm{d}A= r_d^2\sin \theta \mathrm{d}\theta \mathrm{d}\phi$, where $r_d$ is the dust grain radius, and $\phi$ is the azimuthal coordinate. The collision frequency of neutral molecules on the surface element can be obtained as:

\begin{equation}
\nu_{g,d}=n_g(v_g+v_d\cos \theta)\frac{1}{(\pi)^\frac{1}{2}v_{th,g}}\text{exp}\left(-\frac{1}{2}\frac{v_g^2}{v_{th,g}^2}\right)\mathrm{d}v_g\mathrm{d}A
\end{equation}
where $n_g$ is the neutral gas density. The momentum transfer per unit time along the polar axis is subsequently yielded by multiplying with the term from eq.~\eqref{mefisto}:

\begin{equation}
\frac{\Delta p}{\Delta t} = 2m_gn_g(v_g+v_d\cos \theta)^2\frac{1}{(\pi)^\frac{1}{2}v_{th,g}}\text{exp}\left(-\frac{1}{2}\frac{v_g^2}{v_{th,g}^2}\right)\mathrm{d}v_g\mathrm{d}A
\end{equation}
The component of this force perpendicular to the grain velocity direction will be cancelled through integration over the entire grain surface, thus the drag can be stated as:

\begin{equation}
2m_gn_gr_d^2(v_g+v_d\cos \theta)^2\frac{1}{(\pi)^\frac{1}{2}v_{th,g}}\text{exp}\left(-\frac{1}{2}\frac{v_g^2}{v_{th,g}^2}\right)\mathrm{d}v_g\sin \theta \cos \theta \mathrm{d}\theta \mathrm{d}\phi
\end{equation}

We obtain the total drag  by integrating over all neutral velocities. If $v_g>v_d$, collisions will happen for all collision angles $\theta$, however if $v_g\leq v_d$, collisions will only happen if $\cos \theta > -v_g/v_d$. By using this, we may combine the supersonic and subsonic terms, and we state the total drag as:

\begin{equation}
2m_gn_gr_d^2\frac{1}{(\pi)^\frac{1}{2}v_{th,g}}(I_1 + I_2)
\end{equation}
where the integrals $I_1$ and $I_2$ are valid for the different velocity regimes:

\begin{align*}
I_1 &= \int_0^{2\pi}\int_{v_d}^\infty\int_0^\pi\mathrm{d}\phi\mathrm{d}v_g\mathrm{d}\theta (v_g+v_d\cos \theta)^2\text{exp}\left(-\frac{1}{2}\frac{v_g^2}{v_{th,g}^2}\right)\sin \theta \cos \theta \\
I_2 &= \int_0^{2\pi}\int_{-v_d}^{+v_d}\int_0^{cos^{-1}(-\frac{v_g}{v_d})}\mathrm{d}\phi\mathrm{d}v_g\mathrm{d}\theta (v_g+v_d\cos \theta)^2\text{exp}\left(-\frac{1}{2}\frac{v_g^2}{v_{th,g}^2}\right)\sin \theta \cos \theta 
\end{align*}

These integrals can be calculated in terms of the relative flow of the background neutrals to the dust grain. The final result for the drag term, after inserting for the integrals, then becomes:

\begin{align}
\vec{F}_{drag} &= \pi r_d^2 m_g n_g v_{th,g}(\vec{v}_g-\vec{v}_d)\frac{1}{u}\Biggl\{\frac{1}{\sqrt{\pi}}\left(u + \frac{1}{2u}\right)\text{exp}(-u^2)\nonumber \\
&+ \left(1+u^2-\frac{1}{4u^2}\right) \text{erf}(u)\Biggr\}
\end{align}
where $u=|\vec{v}_d-\vec{v}_g|/v_{th,g}$ is the normalized relative atom flow speed.


\clearpage








\begin{appendices}
\noappendicestocpagenum
\addappheadtotoc

\chapter{How to pronounce \LaTeX}\label{pron}
Who the balls cares?

\end{appendices}

\bibliographystyle{Bibliography/Template_LastNameFirst_Alphabetical}
\bibliography{Bibliography/database_template}
\end{document}





