Docsity

LaTeX Handbook, Notas de estudo de Cultura

Toggle sidebar
bg1
L
A
T
E
X Handbook
Jason Brozek
Hannah Goble
Peter Holm1
Department of Political Science
University of Wisconsin – Madison
September 22, 2007
1We would like to thank the former UW-Madison graduate students who contributed to this
guide: Rudy Espino, Erika Franklin Fowler, Mike Franz, Stacey Pelika, and Travis Ridout. In
addition, some of the material on figures and tables was drawn from “Doing Figures and Tables in
L
A
T
E
X” by Charles Franklin. Please do not copy or draw from this work without permission.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f

Pré-visualização parcial do texto

Baixe LaTeX Handbook e outras Notas de estudo em PDF para Cultura, somente na Docsity!

LATEX Handbook

Jason Brozek

Hannah Goble

Peter Holm^1

Department of Political Science

University of Wisconsin – Madison

September 22, 2007

(^1) We would like to thank the former UW-Madison graduate students who contributed to this guide: Rudy Espino, Erika Franklin Fowler, Mike Franz, Stacey Pelika, and Travis Ridout. In addition, some of the material on figures and tables was drawn from “Doing Figures and Tables in LATEX” by Charles Franklin. Please do not copy or draw from this work without permission.

  • 1 Program Basics
    • 1.1 What in the Heck Is LATEX?
    • 1.2 Getting LATEX
    • 1.3 Environments and Commands
    • 1.4 Important Features of WinEdt
      • 1.4.1 The Gather Button
      • 1.4.2 The Insert Menu
      • 1.4.3 The Σ Button
    • 1.5 How to TEX Your Document
    • 1.6 Further Assistance
  • 2 Formatting Your Document
    • 2.1 Sample Template
    • 2.2 Document Class
    • 2.3 Use Package
    • 2.4 Line Spacing
    • 2.5 Indenting and Un-indenting
    • 2.6 Aligning Left, Right, and Center
    • 2.7 Line Breaking, Page Breaking, and Leaving Blank Pages
    • 2.8 Adding Vertical Space
    • 2.9 Titles, Abstracts, and Table of Contents
      • 2.9.1 Document Titles
      • 2.9.2 Abstracts
      • 2.9.3 Table of Contents
    • 2.10 Chapters, Sections, Subsections, and Subsubsections
    • 2.11 Labels and Cross-References
    • 2.12 Hyperreferences
  • 3 Formatting Text
    • 3.1 Fonts and Sizes
    • 3.2 Bold, Italic, and Other Fanciness
    • 3.3 The Verbatim Environment
    • 3.4 Special Characters
      • 3.4.1 Quotation Marks
      • 3.4.2 Hyphens and Dashes
    • 3.5 Quotes
    • 3.6 Footnotes and Endnotes
    • 3.7 Lists
      • 3.7.1 Itemized Lists
      • 3.7.2 Embedded Lists
    • 3.8 Tracking Changes
  • 4 Writing Math
    • 4.1 Math Basics
    • 4.2 Symbols and Greek Letters
    • 4.3 Displaying Equations
    • 4.4 Referencing Equations
    • 4.5 Placing Spaces and Regular Text in Math Mode
    • 4.6 Subscripts and Superscripts
    • 4.7 Fractions
    • 4.8 Hats and Bars
  • 5 Figures and Tables
    • 5.1 Figures
      • 5.1.1 The graphicx Package
    • 5.2 Tables
      • 5.2.1 Aligning Decimal Points
      • 5.2.2 Creating LATEX Code From Stata
    • 5.3 Creating LATEXCode from R
  • 6 BibTEX
    • 6.1 Setting Up a .bib File
    • 6.2 Using BibTEX in Your Document
    • 6.3 Citation Types
    • 6.4 JabRef
      • 6.4.1 Auto-Generating Bibtexkeys
    • 6.5 Non-Standard Citations
    • 6.6 Non-Standard Names: Cox Arquettes, Jrs., IIIs, vons, and Companies
      • 6.6.1 Importing from JStor
      • 6.6.2 The Manage Button
      • 6.6.3 Linking to PDF Files
  • 7 WinEdt Projects
  • 8 Writing Dissertations in LATEX
  • 9 Beamer Presentations - 9.0.4 Getting Beamer - 9.0.5 Document Headers and Beginning Beamer - 9.0.6 Ending Beamer
    • 9.1 Frame Basics
      • 9.1.1 Title Frames
      • 9.1.2 Sections in Beamer
      • 9.1.3 Columns
      • 9.1.4 Graphics
      • 9.1.5 Overlays
      • 9.1.6 Hyperlinks
      • 9.1.7 Movies and Sounds
      • 9.1.8 Notes to Self
    • 9.2 Appearance
      • 9.2.1 Presentation Themes
      • 9.2.2 Colors
      • 9.2.3 Inner Themes
      • 9.2.4 Outer Themes
      • 9.2.5 Logos
  • 10 Formal Models
    • 10.1 Strategic Games
    • 10.2 Extended-Form Games
  • 11 Sweave
  • 12 Document Conversions between LATEX and Word

Chapter 1

Program Basics

1.1 What in the Heck Is LATEX?

LATEX (pronounced ‘la tech’ or ‘lay tech’) is a cultish typesetting program that is beloved by academics for the flexibility it offers in creating documents and the beautiful products that result. It is important to note that LATEX is not a word-processing program! Unlike Word, in which you enter content and format as you go, LATEX is more like a programming language. You enter your content and the LATEX commands into a text editor (such as WinEdt), then use LATEX to create a .dvi (for ‘device independent’) file. This .dvi file must then be translated by a device driver into output that is readable by humans. In general, folks in North Hall translate their files into the familiar .pdf format. The structure of the program means that as you’re working on your document, you will not, sadly, see what it will look like when it is finished. However, that despair will be erased when you see how pretty it is in the end! Also, LATEX feeds into the inner geek in all of us by allowing for endless expansion through ‘packages,’ or macros that tell LATEX to do use certain fonts, format text in particular ways, or include unique functions, such as printing in musical notation.

1.2 Getting LATEX

Installing LATEX can be a somewhat intimidating experience. The upside is that all of the programs are free! In general, you will want to install the following programs and package sets:

  • A text editor of some kind (we recommend WinEdt, available at www.winedt.com)^1
  • The MikTEX set of packages (available at www.miktex.org) – you can decide if you want the small, large, or total set, although it’s usually best to start small and add packages as you need them.^2 (^1) WinEdt is not available for Macs. Mac users typically use Emacs as their text editor. (^2) Again, Mac users will need to do something just a bit different and download MacTEX from the TEX Users Group (TUG).
  • Ghostscript and GSView (available at www.cs.wisc.edu/~ghost/). These aren’t nec- essary, but can come in handy if you’re using lots of graphs and figures.

1.3 Environments and Commands

Throughout this document we will refer to the use of environments and commands to format your document and text. In general, environments are used to format larger chunks of text – for example, making an enumerated list. Environments start with \begin{environmentname} and end with \end{environmentname}. In contrast, commands are used to format smaller pieces of text or to reference a citation or label. Commands look like this: \commandname[option]{}. Somewhat confusingly, there are some functions (such as the Verbatim environment) that can be invoked as either an environment or a command!

1.4 Important Features of WinEdt

Assuming you’re using WinEdt, there are a few important features that will make your life a lot easier!

1.4.1 The Gather Button

The Gather button is that cryptic-looking button that looks like a funnel with little red and blue things going into it. If you click the Gather button, a menu will pop up at the bottom of the screen that has a number of tabs:

  • TOC: Shows you how sections, subsections, and subsubsections will appear in your table of contents.
  • Label: Shows you all your labeled items (see Section 2.11 for more on labels).
  • Bib: Shows all of the citations in your .bib file.
  • Cite: Shows all of the citations inserted into your document.
  • Ref : Shows all of the references inserted into your document.
  • Env: Shows all of the environments used in your document.

If you click on any of the items in this menu, you will be taken to that cite, label, and so on, providing a handy way to navigate through your document. In addition, if you need to put an item into a reference or citation and you don’t or can’t use the ‘type {} and have the box pop up’ method, you can double-click on cites or labels in the Gather menu to place them into \ref{} or \cite{} commands.

  1. First, click the LATEX button in WinEdt.
  2. If all goes well, a bunch of commands will fly by and then the window will go away. If this happens, go on. If it does not, identify and fix the problem.
  3. If you’re using BibTEX click the Bib button.
  4. Click the LATEX button two more times..
  5. Click the dvi → pdf button. A screen will pop up that shows you the pages being created.
  6. To see your final document, click on the button with the Acrobat icon – this will pull up Adobe Reader with your document!

1.6 Further Assistance

Although working with LATEX is fairly easy once you get used to the syntax, problems will inevitably arise. When you need help, we recommend the following sites:

  • The LATEX Encyclopedia: tex.loria.fr/index.html
  • TEX User’s Group Homepage: www.tug.org
  • LATEX Project Homepage: www.latex-project.org
  • Gary King’s Introduction to LATEX: gking.harvard.edu/files/lshort.300.ps
  • The Google LATEX Users Group: http://groups.google.com/group/latexlovers. Googling questions, problems, and commands can also be very helpful.
  • WinEDT.org (Provides add-ons and macros for WinEDT): www.winedt.org

We will also place the handouts from today’s workshop and some other helpful guides in a LATEX folder on the public drive.

Chapter 2

Formatting Your Document

2.1 Sample Template

To write a document, you can utilize the document template that we have placed on the Public drive of the Political Science Server. This template loads important packages and sets the fonts, as well as adding a title and abstract to your document if you wish.

P:\latex\textemplate.tex

The Template file has the following, entered “as is” in your WinEdt file:

\documentclass [11pt]{article} \usepackage[margin=1in]{geometry}

\title{A New Theory of Post Office Committee Behavior\thanks{This paper was prepared for the 2002 Conference on the Post Office Committee, University of Alaska, Fairbanks, Alaska, July 19-21. Thanks to David Canon for his assistance.}} \date{July 19, 2002} \author{Your Name\University of Wisconsin-Madison\ [email protected]}

\begin{document}

\maketitle

\begin{abstract} The Post Office Committee has long been the most important committee in Congress. \end{abstract}

  1. Then, at the beginning of your document (but after \begin{document}, include the following: \doublespace.
  2. That’s the most basic way to get a double-spaced document. However, there are a variety of other commands available to help you fine-tune your spacing. More information can be found at: www.image.ufl.edu/help/latex/spacing.shtml.

To change line spacing in only a segment of a document:

  1. At the beginning of your document, call the ‘setspace’ package with: \usepackage{setspace}.
  2. Put a \begin{singlespace} (or \begin{doublespace} or whatever) at the begin- ning of the text you’d like to change the spacing for.
  3. Close the environment with an \end{singlespace} at the end of the text.

2.5 Indenting and Un-indenting

LATEX will automatically indent all paragraphs except for the first one in a segment of text (a section, chapter, etc.). To add an indent to a paragraph, use \indent at the beginning of the paragraph. To remove an indent, use \noindent at the beginning of the paragraph.

2.6 Aligning Left, Right, and Center

If you haven’t noticed already, LATEX attempts to make every line of text the same length — much like justified formatting in Microsoft Word. This is the default setting, but you can request that it format your page differently by using the flushleft, flushright, and center environments. To get your document to align left, you can request the flushleft environment using the following commands:

\begin{flushleft} This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. \end{flushleft}

In the document, you see that LATEX is no longer trying to make all lines the same length, and all lines are aligned left.

This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment.

The flushright and center environments work the same way!

2.7 Line Breaking, Page Breaking, and Leaving Blank Pages

To create a new paragraph in LATEX, all you need to do is hit return twice in WinEdt – in other words, you need to leave a full space between your paragraphs so LATEX knows it’s a new paragraph. You can also force a line break by typing ‘\’ or by typing \newline. To break to a new page, you can either use \newpage or \clearpage. The latter command makes sure to process all commands up to that point, so it’s often the better choice, or, alternately, you should use them in combination. However, if you’d like to leave a totally blank page, you can’t simply use \newpage or \clearpage twice in a row. Instead, you have to trick LATEX into thinking that there’s something in between the two commands to break a page. The easiest way to do this is by making an empty box with no border. The commands look like this:

\newpage \mbox{} \newpage

2.8 Adding Vertical Space

Sometimes you need to insert a bigger chunk of space than a line. LATEX can be finicky about this – you can’t simply use \ as many times as you’d like to get a lot of space. Instead, it’s much easier to use the \vspace{} command. In the brackets, you put the amount of space you’d like to leave, which can be in millimeters or inches (and probably picas or other measures as well). For example, if you wanted to leave an inch between paragraphs, you’d use \vspace{1in}. One caveat: LATEX will not allow you to add space at the very top of your first page with this command. To do that, you need to use \vspace{} – the * lets LATEX know you really mean it! To put 10 millimeters at the top of the page, for example, use: \vspace{10mm}.

2.9 Titles, Abstracts, and Table of Contents

This guide covers commands within the ‘Article’ document class since it is the most com- monly used. Most of the same commands apply to other document classes (Book, Re- port, etc), but this is not intended to be a complete guide. For more information, see http://tex.loria.fr/index.html.

2.9.1 Document Titles

Creating titles in LATEX is easy. Titles have three basic arguments:

  • Title
  • Author(s)
  • Date

2.9.3 Table of Contents

Creating a table of contents is a painless task. LATEX keeps track of all of your section headings and page numbers for you. All you have to do is insert a table of contents command after the title page. The \newpage commands below ensure that it appears on its own page, but they are not required. After your title and abstract insert:

\newpage \tableofcontents \newpage

One important note: In order for LATEX to compile all of the page numbers for the con- tents page correctly, you need to make sure you LATEX the document twice (or, sometimes, more than twice!).

2.10 Chapters, Sections, Subsections, and Subsubsections

To help organize your document, you can divide your work into chapters and sections by using the section commands: \chapter{} (for Report and Book classes), \section{}, \subsection{}, and \subsubsection{}. The heading for this section was created by using the following command:

\section{Sections, Subsections, and Subsubsections}

The \subsection{}, and \subsubsection{} commands work the exact same way.

2.11 Labels and Cross-References

One of the biggest advantages to LATEX is its automatic numbering and reference system. Much like the way it keeps track of section numbers, the program also keeps track of how many tables and figures you have in your document and automatically numbers them for you. As a result, you never have to worry about inserting new tables at the beginning of your paper and screwing up the numbering throughout the rest of the document. The trick to using references in your document is to label anything you think you may want to refer to later. For example, if I wanted to refer to this section, I would need to include a \label command directly after the section command. Labelling tip: make sure you label items with a descriptive title, so you can easily find which one you need. For this example, I have labeled the section ‘Reference Section.’ The code looks like this:

\section{Labels and Cross-References}\label{Reference Section}

If you wanted to refer to this section, you would type \ref{}. A selection box will automatically pop up in WinEdt when you type the closing bracket (}) with all of the labels currently in your document for you to select the appropriate one. When you highlight the reference you want and hit return, the program will fill in the label within the reference

command for you. In this case, it would fill in like this: \ref{Reference Section}. So, a reference to the current section in WinEdt would look like this:

‘‘in Section \ref{Reference Section} we discussed labels and cross-references."

The sentence will appear in the document as follows: “in Section 2.11 we discussed labels and cross-references.” LATEX also keeps track of the page numbers that correspond with each of your labels, so you can refer readers to the specific page if you like using the \pageref{} command:

‘‘in Section \ref{Reference Section} on page \pageref{Reference Section} we discussed labels and cross-references."

It will appear like this: “in Section 2.11 on page 10 we discussed labels and cross-references.”

2.12 Hyperreferences

Sometimes you’ll open a document generated in LATEX (such as this one) and realize that all of the references work like hyperlinks – in other words, you can click on the reference in Adobe Acrobat and you’ll be taken to that section. Doing this is remarkably easy. All you need to do is add \usepackage{hyperref} as the very last package call in your preamble. Once caveat: if you’ve already generated a table of contents for your document before inserting the call to hyperref, go into the directory your file is in and delete the .toc document for that file or else LATEX won’t compile your document.

Command Font Style \textbf{} Bold \textit{} Italics \texttt{} Typewriter \textsc{} Small Caps

3.3 The Verbatim Environment

Wondering how to get LATEX to print commands without executing them? How can you get the program to display exactly what you type? The answer is through the verbatim environment. In order to display the commands throughout this document, the following commands are used:

\begin{verbatim}

These commands will ask {\LaTeX} to print things exactly as you type them.

\end{verbatim}

To display commands lines within a paragraph, you can use the \verb++ command, where text placed in between the two plus signs (+) is printed in typewriter font, just as in the verbatim environment. For example, to type the previous sentence, you would need to type, “To display command lines within a paragraph, you can use the \verb++ command, where text in between the two plus signs (+) is printed in typewriter font, just as in the verbatim environment.”

3.4 Special Characters

There are 10 special characters. They are:

# $ % & { }˜`\

These characters are part of commands in LATEX, so if you would like to use one of these characters in your text (i.e., I have only $5 in my pocket), you must type this as:

I have only $5 in my pocket.

Note the backslash before the dollar sign. So, to produce these characters, instead of typing the character itself, you must type one of the following:

# $ % & _ {} $\tilde{}$ $\grave{}$ \verb++

3.4.1 Quotation Marks

You’ll notice that LATEX assumes that every single or double quote typed using the normal keys is a closing quote (’ or ”). So, for example, if you type "Cool!", you’ll get: ”Cool!” To get an opening quote, use the accent key (generally found on the same keyboard key as the˜) – one accent for a single quote, and two for a double quote. For example, ‘‘Great!" gives you: “Great!” and all the quotation marks are facing the proper direction just as they should be.

3.4.2 Hyphens and Dashes

LATEX offers a variety of hyphen and dash lengths. To get a regular hyphen, simply type a single hyphen. For a longer dash (–), type two hyphens (--). For a really long dash (—), use the bar (|).

3.5 Quotes

To set text as a quote, use the quote environment. For example,

\begin{quote} I have a dream that my four children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character.\end{quote}

will get you:

I have a dream that my four children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character.

Since inline quotes in a double-spaced document are generally single-spaced, you will want to combine the \begin{quote} and \end{quote} commands with \begin{singlespace} and \end{singlespace} commands. In a double-spaced document, the quote above would need to be inserted as:

\begin{quote} \begin{singlespace} I have a dream that my four children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character. \end{singlespace} \end{quote}

3.6 Footnotes and Endnotes

To enter footnotes, simply put

\footnote{}