LaTeX FAQ

Before asking ithelp@stats.ox.ac.uk for help with LaTeX problems please check this list of frequently asked questions to see if there is a solution.

Questions

How is a LaTeX document organised? Where is the preamble?
What format should my plot/picture/graph files be?
How can I include R graphs in a LaTeX document?
Help! Why can't I see my graphs, or print my LaTeX file? 
How can I get a University crest or Statistics logo in my document
How can I typeset a long or wide table?
Help! My bibliography isn't working.
How can I change the format of my citations?
How can I make an entry for the bibliography appear in my table of contents?
I need to find the markup for an unusual character! Where should I look?
How do I get a blank line between paragraphs?
I'm using TeXnicCenter and MiKTeX. How do I create a PDF file from a DVI file?
How can I find out more about LaTeX?
How can I count the words in a .tex file?
Can you provide an example title page for an MSc dissertation?
How can I install personal LaTeX packages?
This FAQ doesn't help! What information do ithelp need to help me with my problem?
How do I include Subversion version control information in a LaTeX file?

 

Answers

How is a LaTeX document organised? Where is the preamble?
Most LaTeX documents are organised like this:

   \documentclass[options]{class}

     Settings which affect the way the document appears. This part of the document is called the preamble.

   \begin{document}

      Your text, tables, pictures.

   \end{document}

What format should my plot/picture/graph files be?
The simple piece of information you need to know is that you can use either (encapsulated) PostScript (EPS) pictures or PDF/JPG/PNG pictures but not both in any one document. Depending on which format you choose there is a different compilation and viewing method.

- If your pictures are in EPS format then the latex file is compiled with latex which produces a .dvi file. The .dvi file is then compiled with dvips to produce a PostScript file for printing. The .dvi file can be previewed but a PostScript file is needed for printing.
- If your pictures are in PDF/PNG/JPG format then you need to compile with pdflatex which produces a .pdf file for both viewing and printing.

How can I include R graphs in a LaTeX document?
First, make sure you have read the page Graphs and plots in R. This gives important advice about how to create PDF files that display well in LaTeX documents. It can be difficult make figures appear in the place you want on the page. If you  have many figures and not much text then it is hard for LaTeX to typeset each page as you want. One way to  make more pictures appear on a single page is to include them in a single figure environment

      \begin{figure}[h]
      \begin{center}
      \includegraphics[height=2.5in]{Rplot1.pdf}
      \includegraphics[height=2.5in]{Rplot2.pdf}
      \end{center}
      \end{figure}

If necessary a caption can be included for each figure.

Help! Why can't I see my graphs, or print my LaTeX file? 
If you are using TeXWorks then you cannot print your LaTeX PDF file from the previewer. Furthermore not all graphs will display correctly using this previewer. To print the file or to check that the graphs are correct then you need to open the file with Adobe Reader and view and print from there.

How can I get a University crest or Statistics log in my document?
1. There are several versions of the University crest available from http://www.ox.ac.uk/restricted_access/branding_toolkit/downloads/index.html. You will need to unpack the downloaded zip file and choose the most suitable version.
2. Insert the following where you want the crest to appear:
      \begin{figure}[ht]
      \centering\includegraphics[scale=.25]{name of crest file}
      \end{figure}

3. The Statistics logo is available in several different formats on the Intranet.

How can I typeset a long or wide table?
Add
      \usepackage{lscape}
      \usepackage{longtable}
to the preamble. Then to typeset the tables use
      \begin{landscape}
      \begin{longtable}{|c|c|c|c|c|c|c|c|c|c|c|}
at the beginning of the table and
      \end{longtable}
      \end{landscape}
The number of fields and the alignment should be changed to suit your table. Captions can be included within the longtable environment. Two headers can be used, one for the first page, and one for all subsequent pages. They are ended by \endfirsthead and \endhead. \pagebreaks can be included to break the table at a convenient point. The two packages can be used separately, but also work well together.

Help! My bibliography isn't working.
The usual technique for creating bibliographies is as follows:
1. In the preamble include
      \usepackage{natbib}
or whatever bibliography package you have decided to use. natbib is a good place to start.
2. At the end of the file, just before \end{document}  add
   \bibliographystyle{plainnat}
      \bibliography{file}
where file is the prefix of the name of your .bib file. So if the file with the bibliography information is called thesis.bib then you need
      \bibliography{thesis}
3. Use \citet when citing references so that names rather than numbers are used as citations.
4. When compiling the .tex file you will need at least
      latex file
      bibtex file
      latex file
      latex file
Replace file by the name of your file. If your .bib file has citations in the citations, then a further run of bibtex and two more of latex are needed.

For more information about natbib have a look here.

How can I change the format of my citations?
To change citations and references from a numeric format like this to a name format like this do the following:
1. Save your .tex file with a new name.
2. In the new .tex file include \usepackage{natbib} in the preamble.
3. Use \bibliographystyle{plainnat} not \bibliographystyle{plain}.
4. Use \citet not \cite for all your citations.

If you see errors like this:

! Package natbib Error: Bibliography not compatible with author-year citations.

(natbib)      Press <return> to continue in numerical citation style.
See the natbib package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                             
                                        
l.9 ...mmand\NAT@force@numbers{}\NAT@force@numbers

then save the file with a new name and typeset it again.

Finally, if you would like to replace the square brackets in the citation by round brackets then the line \usepackage{natbib} should be replaced by \usepackage[round]{natbib}.

How can I make an entry for the bibliography appear in my table of contents?
If you are using the report documentclass then add the line
      \addcontentsline{toc}{chapter}{\numberline{}\bibname}
just before the line
      \bibliography{file}

If you are using the article class then add the line
      \addcontentsline{toc}{section}{\numberline{}\bibname}

I need to find the markup for an unusual character! Where should I look?
You can look here at a list of unusual characters and their markup. Alternatively try this very useful website which allows you to draw a symbol which if recognised will display the markup. If this doesn't help then searching for 'LaTeX markup name of character' will usually work.

How do I get a blank line between paragraphs?
Include
      \usepackage{parskip}
in the preamble.

I'm using TeXnicCenter and MiKTeX. How do I create a PDF file from a DVI file?
- In the Build Menu >> Define Output Profiles, copy the LaTeX => DVI profile.
- Rename it LaTeX => DVI => PDF.
- Click the Postprocessor tab.
- Click on the little box with a star and enter dvipdfm to name the processor.
- In the executable, specify the path to dvipdfm.exe (in the MiKTeX bin directory).
- In the arguments, specify: "%Bm.dvi"
- Click the viewer tab.
- Specify the path to Adobe Reader. [Check the LaTeX => PDF profile for this.]
- In View Project Output, specify the command: "%bm.pdf"

How can I find out more about LaTeX?
Searching for solutions to problems works surprisingly often. There are also specific places where you can go for help.
- The TeX Frequently Asked Questions page is excellent.
- The comp.text.tex newsgroup is helpful, but may be difficult for those unfamiliar with using newsgroups. Before sending a question to the newsgroup you are advised to read http://www.faqs.org/faqs/tex-faq/ and http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl which describes how to create a minimum example of a problem.

How can I count the words in a .tex file?
You will need a Command Prompt Window. Iif you are using a Windows 7 system this will be

Start -> All Programs -> Accessories -> Command Prompt

In the Command Prompt window you must move to the directory where your LaTeX file is stored. So if it is stored in a subfolder called LaTeX in your My Documents folder you would do this

P:

cd "My Documents\LaTeX"

Then enter

texcount small.tex

where small.tex is the name of the .tex file for which you want a word count. You should see output like this:
 
File: small.tex
Encoding: ascii
Words in text: 148
Words in headers: 6
Words in float captions: 0
Number of headers: 2
Number of floats: 0
Number of math inlines: 0
Number of math displayed: 0
Subcounts:
  text+headers+captions (#headers/#floats/#inlines/#displayed)
  78+2+0 (1/0/0/0) Section: Simple Text
  70+4+0 (1/0/0/0) Subsection: A Warning or Two
 
The word count is on the third line. Rather less output is shown if you use

texcount -total small.tex

Words in text: 148
Words in headers: 6
Words in float captions: 0
Number of headers: 2
Number of floats: 0
Number of math inlines: 0
Number of math displayed: 0

and even less if you use

texcount -brief small.tex

148+6+0 (2/0/0/0) File: small.tex

Can you provide an example title page for an MSc dissertation?
Have a look at this LaTeX file. This example does not contain a University crest; future versions may do.

How can I install my own packages?
For Linux and Mac users 
1. kpsewhich -var-value=TEXMFHOME to see if there's a texmf directory; create your own under ~/texmf just in case
2. Within texmf, create the directory tex/latex/local/
3. Copy sty files, cls, etc, into ~/texmf/tex/latex/local/
4. texhash ~/texmf

This FAQ doesn't help! What information do ithelp need to help me with my problem?
- Where are you running LaTeX? On your own laptop or in the Department?
- What editor are you using? (Emacs, TeXnicCenter, WinEdt, Winshell?)
- Are you able to compile your .tex file and look at the output?
- Is there a problem with a particular format - tables, maths, pictures?

 

 

Please include any error messages that appear when you are compiling your file and any other information which you think will help us solve your problem.