Comprehensive LaTeX Guide
Comprehensive LaTeX Guide
Jason Brozek Hannah Goble Peter Holm1 Department of Political Science University of Wisconsin Madison September 22, 2007
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 gures and tables was drawn from Doing Figures and Tables in A L TEX by Charles Franklin. Please do not copy or draw from this work without permission.
Contents
1 Program Basics A 1.1 What in the Heck Is L TEX? . . A 1.2 Getting L TEX . . . . . . . . . . 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 . . . . . . . 1 1 1 2 2 2 3 3 3 4 5 5 6 6 6 7 7 8 8 8 8 9 10 10 10 11 12 12 12 13 13
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
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.8
3.4.1 Quotation Marks . . 3.4.2 Hyphens and Dashes Quotes . . . . . . . . . . . . Footnotes and Endnotes . . Lists . . . . . . . . . . . . . 3.7.1 Itemized Lists . . . . 3.7.2 Embedded Lists . . Tracking Changes . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
14 14 14 14 15 15 16 16 18 18 18 18 19 20 20 20 21 22 22 23 23 26 27 30 31 31 32 32 33 33 33 34 34 35 35 36 37
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 . . . . . A 5.2.2 Creating L TEX Code From Stata A XCode from R . . . . . . . 5.3 Creating L TE
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
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 6.6.1 Importing from JStor . . . . . . . . . . . . . . . . 6.6.2 The Manage Button . . . . . . . . . . . . . . . . . 6.6.3 Linking to PDF Files . . . . . . . . . . . . . . . . 7 WinEdt Projects
A 8 Writing Dissertations in L TEX
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Companies . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
ii
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 . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
38 38 38 39 40 40 41 41 42 42 44 45 46 46 46 47 48 48 49 50 50 52 55 57
iii
iv
Chapter 1
Program Basics
1.1
A What in the Heck Is L TEX?
A L TEX (pronounced la tech or lay tech) is a cultish typesetting program that is beloved by academics for the exibility it oers in creating documents and the beautiful products A that result. It is important to note that L TEX is not a word-processing program! Unlike A Word, in which you enter content and format as you go, L TEX is more like a programming A language. You enter your content and the L TEX commands into a text editor (such as A WinEdt), then use L TEX to create a .dvi (for device independent) le. This .dvi le must then be translated by a device driver into output that is readable by humans. In general, folks in North Hall translate their les into the familiar .pdf format. The structure of the program means that as youre working on your document, you will not, sadly, see what it will look like when it is nished. However, that despair will be erased A when you see how pretty it is in the end! Also, L TEX feeds into the inner geek in all of us A by allowing for endless expansion through packages, or macros that tell L TEX to do use certain fonts, format text in particular ways, or include unique functions, such as printing in musical notation.
1.2
A Getting LTEX
A Installing L TEX 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 its usually best to start small and add packages as you need them.2
WinEdt is not available for Macs. Mac users typically use Emacs as their text editor. Again, Mac users will need to do something just a bit dierent and download MacTEX from the TEX Users Group (TUG).
2 1
Ghostscript and GSView (available at www.cs.wisc.edu/~ghost/). These arent necessary, but can come in handy if youre using lots of graphs and gures.
1.3
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
Assuming youre using WinEdt, there are a few important features that will make your life a lot easier!
1.4.1
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 le. 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 dont or cant 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.4.2
The Insert menu is your friend when you cant remember how to do something, and you dont have this Handbook handy. On the Insert menu, youll see many of the most-used functions, such as bolding text and creating an itemized list. However, use these functions with caution sometimes youll nd that using the WinEdt commands and environments will result in your not being able to TEX your document. In general, its much better to learn the commands yourself.
1.4.3
The Button
The button is helpful when you need to insert a Greek letter, arrow, or other symbol and you dont know the command for it o the top of your head. Simply click on the , and a bunch of tabbed menus will appear click on the symbol youd like to insert it in your text. To get rid of the menus, click on the in the main menu again. Note that many of these symbols are mathematical see Section 4.1 on page 18 for information on how to insert mathematical notation in regular text.
1.5
Most of this document describes the details of how to write up your document in WinEdt. However, what do you do when youre done and ready to get output? There are several ways to get you from ugly commands and writing to pretty, pretty text. The one that you will probably want to use is the PDF TEXify buttonthe bear head with Acrobat A behind it. For PDF TEXify, go through the following steps: 1. Click the PDF TEXify button. 2. A black window will appear and commands will rapidly y by. If the window goes away by itself, Acrobat should open and your document is right there. Yay!
A 3. Often, L TEX will nd a problem with your code. Usually this is due to something small, such as a missing closing bracket or \end{environmentname}. To gure out where the problem is, you should look at the output that comes up on the screen typically you can decipher where (and sometimes even what) the problem is by the text that is shown at the breaking point or by the line number (you can see what line youre on in WinEdt by looking at the second box from the left at the bottom of the screen).
4. If you have references in your document or a table of contents, you may notice that they are missing from your document. This is normal. In that case, click the PDF A TEXify button again: L TEX will need two go-throughs (or, sometimes, more) to get them all correct. However, you may nd that PDF TEXify does not work for you, particularly if you are using gures in the .ps or .eps format. Never fear! The steps to deal with this are somewhat longer, but the outcome is just as pleasing. 3
2. If all goes well, a bunch of commands will y by and then the window will go away. If this happens, go on. If it does not, identify and x the problem. 3. If youre using BibTEX click the Bib button.
A 4. Click the L TEX 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 nal document, click on the button with the Acrobat icon this will pull up Adobe Reader with your document!
1.6
Further Assistance
A Although working with L TEX is fairly easy once you get used to the syntax, problems will inevitably arise. When you need help, we recommend the following sites: A The L TEX Encyclopedia: tex.loria.fr/index.html
WinEDT.org (Provides add-ons and macros for WinEDT): www.winedt.org We will also place the handouts from todays workshop and some other helpful guides A in a L TEX folder on the public drive.
Chapter 2
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 le has the following, entered as is in your WinEdt le:
\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\\ yourname@polisci.wisc.edu} \begin{document} \maketitle \begin{abstract} The Post Office Committee has long been the most important committee in Congress. \end{abstract}
\section{First Section} Your first section. \subsection{First Subsection} Your first subsection. \end{document}
A This is all you need to write and run a L TEX le. Simply edit the text in the title, abstract, section headings to accommodate your paper. Everything before the \begin{document} command is referred to as the preamble (just like in the Constitution!).
2.2
Document Class
In general youll want to use the Article document class. However, there are a number of other document classes (e.g. Book, Report) available, each with its own preset format. For example, in the Report class (which this document is written in), you can designate chapters in addition to sections and subsections (see page 10 for more on creating sections, etc.). Youll notice in the above example that [11pt] is included before the name of the document class each document class has its own set of options. For further details, visit one of the resources listed in Section 1.6.
2.3
Use Package
A The \usepackage{} command is used to call any of the hundreds of L TEX packages available. For example, in this document, the palatino and graphicx packages are used to change the font to Palatino and to allow us to insert gures into our document. MikTEX should include most of the packages you need, but if you need a dierent package, visit the TEX Catalogue at: http://www.ctan.org/tex-archive/help/Catalogue/catalogue.html. Instructions for installing packages can be found at: ftp://tug.ctan.org/pub/tex-archive/info/beginlatex/html/chapter5.html. Depending on the versions of WinEdt and MikTEX youre using, you may also be able to go to Accessories/MikTEX Options/Packages/Start Package Manager to easily download packages.
2.4
Line Spacing
A L TEX users tend to be snobby about line spacing. In general, they prefer that everything be single-spaced. However, this being the real world, sometimes you have a good reason to make your document double-spaced. To change your line spacing throughout the entire document, do the following:
1. At the beginning of your document, call the setspace package with: \usepackage{setspace} 6
2. Then, at the beginning of your document (but after \begin{document}, include the following: \doublespace. 3. Thats the most basic way to get a double-spaced document. However, there are a variety of other commands available to help you ne-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 beginning of the text youd like to change the spacing for. 3. Close the environment with an \end{singlespace} at the end of the text.
2.5
A L TEX will automatically indent all paragraphs except for the rst 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
A If you havent noticed already, L TEX attempts to make every line of text the same length much like justied formatting in Microsoft Word. This is the default setting, but you can request that it format your page dierently by using the ushleft, ushright, and center environments. To get your document to align left, you can request the ushleft 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}
A In the document, you see that L TEX is no longer trying to make all lines the same length, and all lines are aligned left.
This is a test of the ushleft environment. This is a test of the ushleft environment. This is a test of the ushleft environment. This is a test of the ushleft environment. This is a test of the ushleft environment. The flushright and center environments work the same way! 7
2.7
A To create a new paragraph in L TEX, all you need to do is hit return twice in WinEdt in A other words, you need to leave a full space between your paragraphs so L TEX knows its 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 its often the better choice, or, alternately, you should use them in combination. However, if youd like to leave a totally blank page, you cant simply use \newpage or \clearpage twice in a row. Instead, A you have to trick L TEX into thinking that theres 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:
2.8
A Sometimes you need to insert a bigger chunk of space than a line. L TEX can be nicky about this you cant simply use \\ as many times as youd like to get a lot of space. Instead, its much easier to use the \vspace{} command. In the brackets, you put the amount of space youd 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, youd A use \vspace{1in}. One caveat: L TEX will not allow you to add space at the very top of your rst page with this command. To do that, you need to use \vspace*{} the * lets A L TEX know you really mean it! To put 10 millimeters at the top of the page, for example, use: \vspace*{10mm}.
2.9
This guide covers commands within the Article document class since it is the most commonly used. Most of the same commands apply to other document classes (Book, Report, 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
At the beginning of your document, just after the \begin{document} command, you can specify the three arguments as follows: \title{My Title Goes Here} \author{My Name Goes Here} \date{If I want a specific date, type it here} \maketitle The \maketitle command inserts the title with the above arguments into the document. A L TEX will wrap the title onto a as many lines as necessary. If you want to specify where you want a new line to start you can separate the text with a \\: \title{First Line of My Title\\Second Line of My Title} Multiple authors can be included in two ways: \author{First Author\\Second Author} \author{First Author \and Second Author} The rst method will include authors names in a vertical column. The second option will include authors names on the same horizontal line separated by a tabbed space. To specify a date, simply include the date you would like printed. Dates for titles are optional, but if you leave out the command completely, it will insert todays date instead of leaving o the date. To leave o the date, include the date command without anything within it as follows: \date{} If you use \maketitle in an Article, it will appear on the same page as the abstract and the beginning of the text. To create a separate title page, you may either want to manually create a title (using \vspace{} and \newpage) or look into using Report or another document class.
2.9.2
Abstracts
To create an abstract for your document (much like the one on the rst page), insert the following text after the title of your document: \begin{abstract} Insert the text for your abstract here. \end{abstract}
A L TEX will automatically title and format the abstract for you. No additional commands are necessary.
2.9.3
Table of Contents
A Creating a table of contents is a painless task. L TEX 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:
2.10
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
A One of the biggest advantages to L TEX 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 gures 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 nd 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 ll in the label within the reference 10
command for you. In this case, it would ll 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. A L TEX also keeps track of the page numbers that correspond with each of your labels, so you can refer readers to the specic 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
A Sometimes youll open a document generated in L TEX (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 youll 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 youve already generated a table of contents for your document before inserting the call to hyperref, go into the directory your le is in and delete the .toc A document for that le or else L TEX wont compile your document.
11
Chapter 3
Formatting Text
3.1 Fonts and Sizes
Fonts are changed by calling dierent font packages. For example, you could call \usepackage{palatino}. Changing the size of your font can be done in two ways: To change the size of your font in the entire document, include an option command in your \documentclass{} command; for example, [11pt] to get 11-point text. To change the size of a medium-sized chunk of text, you can create an environment. To illustrate the second option, heres an example: \begin{tiny} I want my text tiny \end{tiny} \begin{Huge} -- wait, no - I want it Huge! \end{Huge} This gives you:
I want my text tiny
A The ten L TEX size options, from smallest to largest, are: tiny, scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge, and Huge, and HUGE. Using these terms instead of font sizes in pts prevents you from having to hunt down every small font-sizechange if you decide to change your entire document from 12-pt to 11-pt font.
3.2
WinEdt makes bolding, italicizing, and underlining easy. You could simply highlight the relevant text, and hit the buttons at the top of the WinEdt. Or, you can use the Tex code below simply include your text in the brackets: 12
3.3
A Wondering how to get L TEX 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
A These characters are part of commands in L TEX, 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:
13
3.4.1
Quotation Marks
A Youll notice that L TEX assumes that every single or double quote typed using the normal keys is a closing quote ( or ). So, for example, if you type "Cool!", youll 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
A L TEX oers 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
14
wherever you want the footnote, and enter the text in between the brackets. Footnotes are just like any other text, so once you read the chapter on writing math, you can incorporate fractions, Greek symbols, and equations into your footnotes as you see t.1 If youd like to use endnotes instead of footnotes, you need to do the following: 1. Call \usepackage{endnotes} at the beginning of your document. 2. Before \begin{document}, make sure you have the following code: \let\footnote=\endnote. 3. At the end of your document, where you want the footnotes, include the following text: \begingroup \parindent 0pt \parskip 2ex \def\enotesize{\small} \theendnotes \endgroup This should give you endnotes! A You may discover that L TEX doesnt like long footnotes, and will automatically break a footnote onto the next page if the single footnote exceeds about twenty lines. Even more frustratingly, the footnote will not automatically continue on the next page, but rather, on the next page that has a footnote! If you have long footnotes that you would like to keep together, inserting the command \interfootnotelinepenalty=10000 into the preamble A should force L TEX to honor your footnote-related wishes.
3.7
Lists
The itemize environment creates simple lists with bullets, and the enumerate environment handles numbered lists. Each environment follows the same basic formula: they use the beginning and ending commands discussed above and each item in the list is preceded by the command \item.
3.7.1
Itemized Lists
Commands for an itemized list are as follows: \begin{itemize} \item This is the first item in the list \item This is the second item in the list \item This is the third item in the list \end{itemize} It appears in the document this way:
1
Like this:ei + 1 = 0
15
This is the rst item in the list This is the second item in the list This is the third item in the list The enumerate environment works the same way, only your list will be numbered rather than bulleted.
3.7.2
Embedded Lists
You can embed list environments within one another by repeating the beginning and ending commands, but be careful to ensure that you have closed each command in the proper order. For example: \begin{itemize} \item This is the first item in the list \begin{itemize} \item This is the first point under the first item \item This is the second point under the first item \end{itemize} \item This is the second item in the list \item This is the third item in the list \end{itemize} This code displays the following: This is the rst item in the list This is the rst point under the rst item This is the second point under the rst item This is the second item in the list This is the third item in the list You can also mix enumerated and bulletted lists for extra fun!
3.8
Tracking Changes
To track changes and note text in ways similar to the capability of Word, use the trackchanges package, available online from SourceForge.net. The package denes ve commands for editing: \note[initials]{note text} \annote[initials]{annoted text}{note text} 16
\add[initials]{additional text} \remove[initials]{removed text} \change[initials]{original text}{note text} In addition, the package can support up to ve users, assigning a dierent color for each. To use this feature, specify the initials for each in the preamble of your document: \renewcommand{\initialsOne}{VOK} \renewcommand{\initialsTwo}{PEC} Thus, you can produce something like the following text: The American public is unable to fulll its democratic obligation c1c2 . But, you may be thinking, what do I do when it is time to produce the nal document? I dont want to go through and remove all this stu! The solution is easy; for your nal version, simply add the nal option to the package command in the preamble, like so: \usepackage[final]trackchanges
c1 c2
17
Chapter 4
Writing Math
4.1 Math Basics
A One of the biggest advantages to L TEX is the mathematical typesetting it oers. Math symbols can be inserted into text through a couple of dierent methods. Just like the other environments, you can employ the math environment by using the \begin{math} and the \end{math} commands. For a shortcut (particularly within paragraphs of text), you can use dollar signs $ to indicate the beginning and end of math mode.
For example, if you wanted to discuss the $\beta$ coefficients for a particular model, you would need to use math mode to display the $\beta$s and any other equations like $y=X\beta$ or $$\hat{\beta}=XX^{-1}Xy$$. The document will print: For example, if you wanted to discuss the coecients for a particular model, you would need to use math mode to display the s and any other equations like y = X or = X X 1 X y.
4.2
While the most-used Greek letters, like and are part of the default package youre using, incorporating more obscure symbols and letters requires a new style package. To access the widest array of mathematical symbols and Greek letters, the American Mathematical Societys amssymb package cant be beat. To write less-common (but immensely useful, Im sure) symbols and letters like , , , , , or , you simply need the amssymb style package and the American Mathematical Society Math Guide (available at http://www.ams.org/tex/short-math-guide.html).
4.3
Displaying Equations
If you need to display larger equations or prefer to separate the mathematics from your text, there are a couple of dierent environments you can employ: displaymath or equation. 18
An example of the displaymath commands: \begin{displaymath} y = \alpha + \beta_{1}x_{1} + \beta_{2}x_{2} \end{displaymath} The displaymath environment centers the equation on the page but does not number it. Like a single $ is a shortcut for inline math, a double $ enclosing an equation ($$equation$$) is also a useful shortcut to put equations on their own line (and, like displaymath, this shortcut does not insert them as part of your system of numbered equations). If double dollar-signs are too capitalist for you, another shortcut to displaymath is the \[math\] command. y = + 1 x1 + 2 x2 This equation could also be created with $$y = \alpha + \beta_{1}x_{1} + \beta_{2}x_{2}$$ and/or \[y = \alpha + \beta_{1}x_{1} + \beta_{2}x_{2}\] Alternatively, you could use the equation environment: \begin{equation} y = \alpha + \beta_{1}x_{1} + \beta_{2}x_{2} \end{equation} The equation environment also centers the equation on the page, but unlike the displayA math environment, it numbers the equation. L TEX keeps track of the number of times you have used the equation environment, and will number the equations appropriately. If you decide to enter another numbered equation on page two of your document, for example, your equations on pages fteen through eighty-seven will all shift accordingly. y = + 1 x1 + 2 x2 (4.1)
4.4
Referencing Equations
If you include a label command after the \begin{equation} command, you can refer to the equation by using a cross-reference:1 \begin{equation}\label{Eqn2} y = X\beta \end{equation} In equation \ref{Eqn2} on page \pageref{Eqn2}, we learned that... y = X In equation 4.2 on page 19, we learned that...
1
(4.2)
19
4.5
Math mode diers from regular text mode in a few important ways: 1. Spaces within math mode will not appear in the document. If you need to create space within the equation, use \quad for a small space or \qquad for a larger, more tab-like space. 2. All characters entered into math mode are assumed to be variable names and will display in italic form. If you want to have normal text font within a math mode environment, use the \textrm{} command. For example, notice the dierence between these two commands: \begin{displaymath} E[\epsilon_{i}]=0 for all i=1,2,...,n \end{displaymath} \begin{displaymath} E[\epsilon_{i}]=0\qquad\textrm{for all }i=1,2,...,n \end{displaymath} The rst one is not quite what we want... E[ i ] = 0f oralli = 1, 2, ..., n By including \qquad and \textrm{}, we get... E[ i ] = 0 for all i = 1, 2, ..., n
4.6
In math mode, you will often want to create formulas with subscripts, superscripts, and fractions. These commands are very easy. To subscript anything, you just need to include a _{} after the item you want to subscript. Anything within the brackets will appear as part of the subscript. For example, if you wanted to write x with a subscript of t 1, you would type $x_{t-1}$, which would display as xt1 . Superscripts are similar except now you use ^{}. So for e to the z, you would type $e^{-z\gamma}$, which would display as ez .
4.7
Fractions
Fractions are also easy to do. You can simply use the /, to display fractions, but often this can clutter the page. For example if we wanted $(x-\bar{x})$ divided by $\sigma/\sqrt{n}$, it will be hard to read if we just use /s in the equation: (x x)// n. So instead, we utilize the fraction command: 20
\frac{}{} Anything in the rst {} will appear in the numerator, and anything in the second {} will appear in the denominator. So for example:
You can also embed fraction commands within each other to produce more complicated fractions. For example:
4.8
Finally, to create hats or bars above any text, you can use the \hat{} or \bar{} commands where anything within the brackets will appear with the symbol over it. So $\hat{\beta}$ will appear as , and $\bar{y}$ will appear as y.
21
Chapter 5
Including gures in your document requires you to use some kind of package that supports graphics. The most up-to-date package in this regard is graphicx, which we cover in detail here. You may also come across graphics (a simpler version of graphicx), psg, or epsg. The graphicx package essentially supersedes the others. The graphicx package will allow you to insert graphic les in several dierent formats, most commonly .jpg, .png, or .pdf les (for use with pdfLaTeX) or .ps or .eps les (for use with dvips). Typically, youll produce these graphics using some statistical package. In Stata, you can save your graphs in .png format by using the saving option in your graph command: graph twoway scatter y x, saving(prettygraph.png, replace) You can also save Stata graphs in .eps or .ps format by replacing .png with the appropriate letype sux. To create a .pdf of your graph, save it in .ps format and then double-click on the .ps le icon you created; Acrobat Distiller should open up and create a .pdf version of the .ps le. In R, you create graphics les in three steps. To create a .pdf le, for example: pdf("c:/filepath/graphname.pdf") (Opens a le in which to save the graph). <The commands to plot your graph.> dev.off{} (Closes the le.) You can create .ps, .png, or other les in a similar fashion. For a .ps or .eps le, the command changes to postscript(...), and for a .png it changes to png(...). You can also specify multiple other options like the height, width, and font of these graphics see the documentation in R for additional information. Note: It is a good idea to save any graphics les you create in the same directory as A your L TEX document, because they will need to be there for you to insert them in your paper.
22
5.1.1
To use the graphicx package, simply include \usepackage{graphicx} in your preamble. Then, when you reach the point where youd like to include a graphic, use syntax similar to the following: \begin{center} \begin{figure}[htbp] \includegraphics[width=4in]{filename} \caption{A Pretty Graph!}\label{trialgraph} \end{figure} \end{center} The option [htbp] after the begin gure command species where you want to place the gure. Here, it requests that the program try to place your gure right here where youve typed the command rst, then at the top of the page, then at the bottom, and nally on A its own page. L TEX will t the gure in where it works best! If its not where youd like it, try changing the ordering of your placement preferences, removing the ones you denitely dont want, or inserting a ! before the rst letter. A The reason that you have to specify where you want L TEX to place the gure is because gures and tables are typically treated as oating objects in order to make the document A as beautiful as possible. Basically, L TEX creates an invisible box containing your graph, and that box oats around until it can be placed in a good spot in the document. Your text will ow around the box uninterrupted. Youve also given the gure a caption and a label. The caption is actually what will show up on the page (along with Figure 1: or whatever number it is), while the label allows you to refer to this particular gure in your text without having to remember what number it is. This is helpful when you have multiple gures and tables in a document that you may move around, delete, or replace as you edit; you can always refer to this gure A by typing Figure~\ref{trialgraph}, and L TEX will insert the text Figure 1 in your document. If you decide later that you want another gure before this one in your A document, L TEX will automatically start calling this one Figure 2 in the text and will provide the correct numerical caption accordingly. Figure 5.1 will appear in your document as it does on page 24. Note that here, the caption is above the graph because the caption command comes before the graphics commands. You can also use the commands for centering, ushleft, or ushright to change the placement of your graph, and change the size of your graph by changing the height and width parameters in the includegraphics command.
5.2
Tables
A Tables in L TEX are fairly easy as well once you have the basic commands down. Here are some handy tips for using table and tabular commands:
\begin{table} The table environment gives you options within it that allow you to number and title your tables (see caption for more details). 23
Figure 5.1: Probability of Voting for an Incumbent Republican, by Partisanship and Sociotropic Assessment of the Economy
Strong Republican
.5
[h] Just like gures, the [h] command just after the \begin{table} command requests that the program place the table about here in your document. Alternatively, you can request [htbp], rst tries here, then the top of the page, then the bottom of the page, then, nally, its own page. You can change the ordering of the location preferences to whatever youd like. \label{} The label command works exactly like any other cross-reference and allows you to refer to your table within the text of your document. \caption{} The caption command goes within the table environment (either above or below the actual entries of the tabular environment depending on where you would like the caption to appear) and allows you to add a title to your table. Example: \caption{My Table Title}. \begin{tabular} The tabular environment is where you actually place the contents of your table (in fact, if you dont need a caption, etc., you can simply use a tabular environment without a surrounding table environment). Directly after the \begin{tabular} command, you specify how you want the columns within your table to align. You must specify each columns format individually where l means left align, r means right align, and c means center. For example, if you had a three column table, and you wanted the rst column to align left, the second column to center, and the third column to align right, you would specify that in the following way: \begin{tabular}{lcr}. Within the tabular environment, you use &s and \\s to specify column and line breaks (see &s and \\s for details). &s Ampersands are used to separate cell entries in the table. Therefore, if you 24
wanted a two column table with Coef in the rst column and SE in the second column, you would specify that by typing: Coef & SE. To leave a cell blank, just do not type anything in between the ampersands. \\s Double slashes designate line breaks in a table. So after the last entry in each row, type \\ to go to the next line. \toprule, \midrule, and \bottomrule insert horizontal rules across the width of the table. These commands require the booktabs package, which you can call by including the \usepackage{booktabs} command in your preamble. You can also specify the width of each rule as an option to the command. If you wanted a heavy line at the top of your table, you would type: \toprule[1.5pt]. If you wanted a thinner line below your variable titles of Coef and SE, you would type: Coef & SE \\ \midrule. \cline{i-j} cline inserts a horizontal line across columns i through j. You place the cline command in the same place you would put the midrule command above. | Vertical lines can be inserted in your table by specifying where you would like them within the alignment part of your tabular specication. For example, if you wanted vertical lines on the outsides of your three column table (as specied above), you would type: \begin{tabular}{|lcr|}. Alternatively, if you wanted vertical lines separating all columns, you would type: \begin{tabular}{|l|c|r|}. \multicolumn The multicolumn command allows you to create a cell within a row that spans more than one column. It requires three specications: the number of columns you want the cell to span, the alignment of the text within the cell, and the actual text that goes within the cell. To create a cell in a table of ve columns that spans three columns (starting in the third column) and is centered, you would type: &&\multicolumn{3}{c}{Cell Text}. Okay, now for an example, so you can see how all of these things work together... (Note: You do not have to include as much space in between the ampersands and the table text, although it does help in seeing the columns better.) \begin{table}[htp]\label{Tab Test} \caption{This is My Caption} \begin{center} \begin{tabular}{lccc} \toprule[1.5pt] & \multicolumn{2}{c}{Party} & \\\cline{2-3} & Democrat & Republican & Total \\ \midrule Female & 323 & 280 & 603 \\ Male & 260 & 310 & 570 \\ \bottomrule[1.5pt] \end{tabular} \end{center} \end{table} 25
Now you can see what all of those commands produce: Table 5.1: This is My Caption Party Democrat Republican Female Male 323 260 280 310
5.2.1
A L TEX will not automatically align your columns on the decimal points, but there is a handy package available called dcolumn (included as part of the tools package that comes with A most L TEX installations) that will allow you to do this. In order to use it, you must call the package by including \usepackage{dcolumn} in your preamble. The dcolumn syntax is based on a modication to the column designations you place after your \begin{tabular} command. For each column youd like to align, you use the following in lieu of the usual l, c, or r:
{inputsep}{outputsep}{decimalplaces} Where inputsep and outputsep will generally be a decimal point, unless youre using another separator, such as a comma. The third argument sets the number of spaces to the right of the decimal point that should be included in the width of the column. You may want this to be greater than the number of decimal places your cell entries use, if you dont necessarily want the decimal point to be at the exact center of the column. For entries with three decimal places, for example, D{.}{.}{5} or D{.}{.}{6} will often produce the most attractive alignment. If decimalplaces is set to -1, the column will center on the decimal point no matter how many decimal places each cell uses. Heres an example: \begin{tabular}{l D{.}{.}{5} D{.}{.}{5}} Variable & Estimate & SE\\ \midrule Intercept & 2.753 & 1.036\\ Education & 0.245 & 0.023\\ \midrule $R^2$ & 0.24 &\\ N & 1287 &\\ \end{tabular} You can also, if youd like to be really fancy and save time, include a command in your preamble that allows you to avoid typing the full dcolumn command for every table: \newcolumntype{.}{D{.}{.}{5}}
26
This allows you to type the above table like so, where the . calls your custom column type: \begin{tabular}{l..} Variable & \multicolumn{1}{c}{Estimate} & \multicolumn{1}{c}{Std. Error}\\ \midrule Intercept & 2.753 & 1.036\\ Education & 0.245 & 0.023\\ \midrule $R^2$ & \multicolumn{1}{c}{0.24} &\\ N & \multicolumn{1}{c}{1287} &\\ \end{tabular} Note that weve also changed how the table headers are formatted by using multicolumn you avoid having your headers printed in math format (standard for dcolumn) and having any periods used in your header (such as in Std. Error) treated as decimal points! Doing the same thing for the R2 and N lines is also typical to center them in the middle of the column rather than on the decimal point. (Try it without the multicolumn command to see what happens.)
5.2.2
A You mean Stata can help me write L TEX tables?? Yes! You just need to know how to do A it. Turning regression output into L TEX code for tables can actually be relatively painless. A There are two Stata packages that handle exporting results to L TEX: outtex and estout.
outtex After youve installed the outtex package in Stata, all you need to do in Stata is to estimate a model, and after it displays your output, type outtex. The outtex command will convert A your regression output into L TEX code for a table with coecients and standard errors (Note again that you can be more specic about how you want things to display by exploring the options within outtex there are ways to automatically add stars, 2 values for MLE models and R2 for OLS models, etc.). It is probably easiest if you are running a log le and can A copy and paste the code from there, but you can just copy the L TEX code from the screen itself. Here is an example of what you would type and see in Stata (the commands given are preceded by a . character):1
. logit hou repterr06 repid demid iraqwar bush4 attend income05 white age65 female Logistic regression 5427 Number of obs LR chi2(10) Prob > chi2
1
= = = 4253.46 0.0000
None of my variables here have labels in Stata, but if you have set variable labels, the outtex command will put the variable label in place of the variable name.
27
Pseudo R2
-----------------------------------------------------------------------------hou | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------repterr06 | 1.148196 .1300711 8.83 0.000 .893261 1.403131 repid | 1.564615 .1141213 13.71 0.000 1.340942 1.788289 demid | -1.582502 .1186638 -13.34 0.000 -1.815079 -1.349925 iraqwar | .2340725 .0624136 3.75 0.000 .1117442 .3564009 bush4 | .7929573 .0663963 11.94 0.000 .6628229 .9230918 attend | .0169693 .0363984 0.47 0.641 -.0543702 .0883088 income05 | .0683549 .0271322 2.52 0.012 .0151768 .121533 white | .6174791 .1338325 4.61 0.000 .3551722 .879786 age65 | .0746663 .0348658 2.14 0.032 .0063306 .1430021 female | .1572805 .0949941 1.66 0.098 -.0289045 .3434656 _cons | -4.201644 .2697507 -15.58 0.000 -4.730346 -3.672943 ------------------------------------------------------------------------------
. outtex %------- Begin LaTeX code -------% { \begin{table}[htbp]\centering \caption{Estimation results : logit \label{tabresult logit}} \begin{tabular}{l c c }\hline\hline \multicolumn{1}{c} {\textbf{Variable}} & {\textbf{Coefficient}} & \textbf{(Std. Err.)} \\ \hline repterr06 & 1.148 & (0.130)\\ repid & 1.565 & (0.114)\\ demid & -1.583 & (0.119)\\ iraqwar & 0.234 & (0.062)\\ bush4 & 0.793 & (0.066)\\ attend & 0.017 & (0.036)\\ income05 & 0.068 & (0.027)\\ white & 0.617 & (0.134)\\ age65 & 0.075 & (0.035)\\ female & 0.157 & (0.095)\\ Intercept & -4.202 & (0.270)\\ \hline \end{tabular} \end{table} } %------- End LaTeX code -------%
Notice that the outtex command did not reprint everything from the regression table in Stata, but it will provide you with a handy template for your own table. If you just copy and paste the output displayed between the Begin LaTeX code and End LaTeX code into WinEdt, you will have a table that looks like this: There many be things you want to change about the table, which you can just edit manually, but this is the easiest way to get Stata to do most of the work for you, and it doesnt look half bad! There are multiple other options you can specify in the outtex command that will produce a fancier table automatically; see the documentation in Stata by typing help outtex. 28
Table 5.2: Estimation results : logit Variable Coecient (Std. Err.) repterr06 1.148 (0.130) repid 1.565 (0.114) demid -1.583 (0.119) iraqwar 0.234 (0.062) bush4 0.793 (0.066) attend 0.017 (0.036) income05 0.068 (0.027) white 0.617 (0.134) age65 0.075 (0.035) female 0.157 (0.095) Intercept -4.202 (0.270) estout
A An alternative that works for exporting Stata output to multiple platforms including L TEX A is estout. Estout is quite powerful and can produce publication quality tables in L TEX from a single (albeit long) line of Stata code, and it is particularly useful for making multicolumn tables that report multiple models at once. It works by drawing from sets of stored estimates, so the rst thing you have to do is store your estimates after you run a model by typing est store and then a name for that model. You can of course incorporate this easily into your do-le. For example, say you run the model above and store the estimates as mod1:
. logit hou repterr06 repid demid iraqwar bush4 attend income05 white age65 female . est store mod1 You then run a second model that adds an additional variable, ndterr06, and store the second model results as mod2: . logit hou ndterr06 repterr06 repid demid iraqwar bush4 attend income05 white age65 female . est store mod2 You can now generate a table with each models as a columns. Here, Im pulling out all the stops by instructing Stata to put stars on the betas; to put the standard errors in parentheses under the coecient estimates; to report all of the variables in a particular order, as well as the constant; to set the star levels to particular signicance levels; and A to do this in L TEX style. You can refer to the documentation in Stata about the estout command to get more details about the syntax and all the other options you can set.
29
. estout mod1 mod2, cells(b(star fmt(%9.3f)) se(par)) keep(ndterr06 repterr06 repid demid iraqwar bush4 attend income05 white age65 female _cons) starl($*$ .10 $**$ .05 $***$ .01) sty(tex)
A This produces the following, which you can cut and paste into your L TEX document. Note that estout does not produce the table and tabular environment delimiters or the other table headers that youll have to specify (e.g., number of columns, alignment, rules, etc.). Again, if your Stata dataset has variable labels specied, you can have estout output those labels instead of the raw variable names. It can also output N , R2 , and other model statistics. & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & 1.148$***$& (0.130) & 1.565$***$& (0.114) & -1.583$***$& (0.119) & 0.234$***$& (0.062) & 0.793$***$& (0.066) & 0.017 & (0.036) & 0.068$**$ & (0.027) & 0.617$***$& (0.134) & 0.075$**$ & (0.035) & 0.157$*$ & (0.095) & -4.202$***$& (0.270) & mod1 b/se mod2 \\ b/se \\ 1.171$***$\\ (0.176) \\ 2.234$***$\\ (0.209) \\ 1.569$***$\\ (0.115) \\ -1.393$***$\\ (0.121) \\ 0.215$***$\\ (0.064) \\ 0.748$***$\\ (0.068) \\ 0.022 \\ (0.037) \\ 0.059$**$ \\ (0.027) \\ 0.569$***$\\ (0.135) \\ 0.080$**$ \\ (0.035) \\ 0.145 \\ (0.096) \\ -5.073$***$\\ (0.308) \\
ndterr06 repterr06 repid demid iraqwar bush4 attend income05 white age65 female _cons
5.3
A Just like in Stata, you can create L TEXcode directly from R. You rst need to install the xtable package from CRAN, then call it using the library command; see the R documentation for more information on the package itself. The implementation is very simple. Run your model in R and store it as an objectas model1, for example. Then use the xtable command to output the model results as a table:
> xtable(model1) And thats it! R will print a formatted table with rounded coecients that you can then A paste into L TEXand modify as necessary. Of course, there are multiple options you can specify in the R command to do much of the customization for you. One that you may want to use is the file=[filename] option, which, if used, saves the output as a le rather than simply printing it in the R console.
30
Chapter 6
BibTEX
Using BibTEX is easy and, if youre into organization, fun! The process is divided into two steps: setting up a .bib le and using BibTEX in your document.
6.1
If youve had experience with a program such as Endnote, setting up a .bib le will be a somewhat familiar process. In general, all you do is set up a document that contains information about each of the documents youd like to cite. To do this, simply: 1. Open a new document in WinEDT. 2. Go to the Insertmenu, and go down to BibTEX Items. 3. A menu will pop up to the side. Select the type of document you would like to insert. 4. A new entry will appear in your document. There is a star at each point at which you can enter information. 5. The rst star is the place for you to enter a nickname for your document. For example, you could use Downs1957 or bookcitedineverything for An Economic Theory of Democracy by Anthony Downs its up to you! Typically, though, youll want to use the author-date combination, with no spaces. 6. Note that some elds are in all caps you should ll in these elds for correct citations. All other elds are optional. 7. Also note the placement of a bracket just before the nickname and another at the end of the entry. There are also brackets around the entry in each eld. You must have these brackets in place for BibTEX to work. 8. Once you have entered all of your documents, simply save your document with a .bib extension in the same folder as you plan to save your TEX le.
31
Alternatively, you can do this: 1. Download JabRef at: jabref.sourceforge.net. 2. Use JabRef! (See Section 6.4 for more information.)
6.2
Using BibTEX as you write is simple and results in a beautiful, correctly formatted bibliography with very little eort. The rst step is to call the natbib package and set up citation punctuation by including in your preamble the following commands: \usepackage{natbib} \bibpunct{(}{)}{;}{a}{}{,} When it comes time to include your rst citation in the text, simply type one of the cite commands (see below) and then, inside curly brackets, the nickname (e.g., Downs1957) of A the work you want to cite. L TEX will insert the citation and include that work in your bibliography. If you want to cite multiple works in the same citation, simply include each works nickname separated by commas and in the order you want them listed. A typical citation command looks like: ...and thats how a bill becomes a law \citep{Coleman2003}. The last step is to call the bibliography at the end of your document, just before the \end{document} command; otherwise, your citations will still show up in the text, but A L TEX will not produce the list of references. Dierent disciplines, journals, and publishers A use dierent bibliographic styles, so you need to tell L TEX which one you want to use. Happily, the American Political Science Review has its own style, and that is the one you will most likely want to follow. To create a bibliography of all the works you cited in the text using the APSR style, end your document with the following commands: \bibliographystyle{apsr} \bibliography{yourbibfilename} \end{document} You do not need to include the .bib sux when you type the name of the .bib le you created earlier. There is also an apsr2001 style that arguably improves a little bit upon the apsr style in aesthetic terms while still maintaining accordance with the APSR guidelines. It seems to be a little nicky, however; you may want to try calling apsr2001 instead of apsr as your bibliography style, and if it works, go with it. If not, apsr should work ne.
6.3
Citation Types
Natbib supports many dierent citation formats that you may need. These include:
32
Command \citep{Coleman2003} \citep[21]{Coleman2003} \citep[e.g.,][]{Coleman2003} \citet{Coleman2003} \citet[21]{Coleman2003} \citep{Coleman2003, Canon2005} \citep{Coleman2003, Coleman2006} \citealp{Coleman2003} \citeyearpar{Coleman2003} \nocite{Coleman2003}
Appearance (Coleman 2003) (Coleman 2003, 21) (e.g., Coleman 2003) Coleman (2003) Coleman (2003, 21) (Coleman 2003; Canon 2005) (Coleman 2003, 2006) Coleman 2003 (2003)
The nocite command does not print anything in your document at the point of citation but does include the work in your bibliography. All of these citation formats and more are documented on the Natbib Reference Sheet, which can be found at: http://gking.harvard.edu/files/natnotes.pdf.
6.4
JabRef
So what is this JabRef thing? Basically, its a free Endnote-like program that works with BibTEX and is available for both Windows and Mac. JabRef will create the .bib le for you just save it in the same folder as your .tex document. It is highly recommended that you use JabRef (or some similar program), as entering BibTEX references manually can get quite unwieldy, particularly as you take on bigger projects and your .bib les get larger. You can get it at: jabref.sourceforge.net. JabRef also has a number of useful functions not listed here, so we encourage you to explore the program!
6.4.1
Auto-Generating Bibtexkeys
In JabRef, whenever you see a magic wand, you can click it to automatically generate a bibtexkey (nickname) for a work you will cite. The standard format is LastnameYear (e.g., Downs1957).
6.5
Non-Standard Citations
Sometimes you need to cite something that doesnt t into an obvious category like Book or Article, such as a dataset, newspaper article, or television broadcast. In these situations, its generally easiest to use the Misc category and play around with the elds until you get the format youd like. For example, in citing newspaper articles, I use the following elds: Author: The author. Title: The title of the article. Howpublished: \emph{nameofpublication}. 33
6.6
BibTEX assumes that names are entered either as Firstname Initial. Lastname or Lastname, Firstname Initial. But sometimes an author will not t into this format and youll end up with a cite like this: (Jr. 2005). What do you do? Well, it depends on the issue. Here are some of the most common problems and what to do about them: Compound Last Name: Cox Arquette, Courteney Jrs.: Downey, Jr., Robert IIIs: Stewart, III, Charles vons: von Beethoven, Ludwig Companies: {ABC News} See this page for more info: http://nwalsh.com/tex/texhelp/bibtx-23.html.
6.6.1
Yes, you can directly import citations from JStor into JabRef! Heres how you do it: 1. Export your JStor citations using the tab-delimited format (note that you can also export a fully formed BibTEX citation, but you dont want to do that for JabRef). 2. In JabRef, go to File/Import and Append/JStor (tab delimited). (If youd like to import into a new .bib le rather than an existing one, select File/Import/JStor (tab delimited) instead. 3. Find and select your exported citations. 4. JabRef If youre only importing one cite and its not a duplicate of another item in your le, JabRef should simply import the new cite. Otherwise, a window will open listing your cites. You can check a box to automatically generate bibtexkeys, see which cites are potential duplicates of others in your le, and deselect cites you wouldnt like to import. Once youre done, select OK and your cites will import! 5. Note: Sometimes the JStor URL wont import correctly if your le doesnt BibTEX properly, you may want to go through and delete the URLs of recently imported cites.
34
6.6.2
When you see a button that says Manage on it, you can pre-enter a list of values that you use frequently, say the most popular journals you cite, and simply click through a list and select rather than typing American Political Science Review one bazillion times. Simply click on Manage and a window will appear in which you can enter new values, remove old ones, and so on.
6.6.3
If you nd yourself downloading a lot of .pdf les from JStor or other journal databases, it can be useful to automatically link the .pdf les to your JabRef entries. The most streamlined way to do so is to: 1. Put all of your .pdf les into a single folder. 2. Make sure your .pdfs all have names that parallel your bibtexkeys (LastnameYear). 3. In JabRef, go to Options/Preferences/External Programs. 4. In the box for Main PDF directory, browse to the location of your .pdf folder. 5. From this point forward, you can simply click on the Auto button next in the Pdf section of the General menu for a cite, and it will automatically link to your document. 6. Alternately, you can manually link to a .pdf le by clicking on Browse. 7. To open a .pdf, click on the Acrobat icon next to the document of interest.
35
Chapter 7
WinEdt Projects
Setting up a project in WinEdt allows you to easily open and close a set of related documents that share the same format (for example, the chapters of a dissertation). To create a project: 1. Go to Project/New Project 2. Open a blank .tex le to use as your main le (the le that calls and compiles the other les). 3. Tell WinEdt that your new le is the main le by going to Project/Set Main File. 4. Place all of your preamble commands (package calls, document type, etc.) in the main document. 5. For each le youd like to include in the end product, type \include{documentname}. One caveat: for .bib les, you will want to use \input{bibfilename.bib} this will include the .bib le in your project tree and allow you to gather .bib items, but will not compile the .bib le in the nal document! 6. Open the project tree by clicking on the tree icon (next to the binoculars or in the Project menu). 7. To create your tree, click on the tree icon within the tree window - this will collect all of the items in the main le and create a tree. From this window, you can click on any of sections of your document and go directly to them! 8. Save your project by going to Project/Save Project. When you open a project, all les that were open when you last closed the project will be reopened.
A 9. When you L TEXa project, WinEdt will call the main le and compile all documents with a valid \include{documentname} command. If you do not want to include a document, simply put an % before the \include{documentname} command.
36
37
Chapter 9
Beamer Presentations
A There are two primary classes for making PowerPoint-type presentations in L TEX: Prosper1 and Beamer. Although both are viable options, we will be be focusing on Beamer here. Beamer works in a similar manner to Prosper2 but has the advantage that it works together directly with pdatex, but also with dvips. Well, obviously! Beamer is quite exible; well be merely scratching the surface of what you can do in a presentation with it. For a full description of Beamer, and its features, you should check out the manual on the class, available from sourceforge.net and weighing in at over two hundred pages in the most recent version.
9.0.4
Getting Beamer
To use Beamer, youll need to download the class itself, along with the packages pgf and xcolor. All are available at the SourceForge Beamer homepage: http://latex-beamer.sourceforge.net. Alternatively, if you have set your options to automatically download missing packages, A WinEdt will download these components for you when you L TEX the document.
9.0.5
Beamer documents, since they rely on the Beamer class, use a slightly dierent set of commands from the articles you are probably used to. Instead of specifying article as the document class, youll specify Beamer. An example: \documentclass{beamer} \title{Beamer Rulez!} \author{The \LaTeX\ Master} \institute{University of Wisconsin-Madison} \date{\today}
1 A Prosper is written on top of the seminar class in L TEX; hence, youll need both if you want to do a presentation using prosper. 2 Commands in the two classes are slightly dierent, so be careful using this handout when using prosper.
38
\begin{document} The title, author, and date commands function in the way they do for writing articles, with the exception that youll need to put the title page into a slide. (Well get to that a bit later...) You may also call packages as you normally would, although Beamer will automatically call some, most notably graphicx. Practically, this means that the packages that you are used to (like epsg) will be troublesome to work with in Beamer. Well get to graphics a little bit later too... Class Options Beamer, like articles, uses a number of class options to change the format of the presentation; class options are placed in square brackets after the documentclass command.3 The options youll probably be most likely to use include font sizes, transparencies, and handouts. Font sizes operate here exactly as you are used to. The class option [trans] creates a transparency version of your presentation. Most of the time, this transparency version will likely be the same as the plain old presentation itself, with the exception that the slide numbering and navigational bar will be suppressed on the transparency version. However, you can get much fancier with the transparency version and change the way certain slides are displayed. To do that, youll want to use the only command and consult the ocial Beamer guide. In addition, the option [handout] creates a handout version of the presentation, which, as with the transparencies, you can change the appearance of as you wish. If you use the handout option, you can print multiple slides on a page by rst calling the pgfpages package and then specifying the number of slides you want on each page. For example, if I wanted to print two slides to a page, I would put the following commands at the beginning of my presentation: \documentclass[handout] {beamer} \usepackage{pgfpages} \pgfpagesuselayout{2 on 1}[letterpaper, landscape, border shrink=5mm]
9.0.6
Ending Beamer
A Beamer, like other classes in L TEX will produce a PDF document of your presentation. In order for Beamer to work correctly, youll want to use the PDF TeXify key (the one with the bear head and the Adobe A). A PDF of the presentation will be produced, which you can then display as you would a PowerPoint slide show using Acrobat.
3 Warning: as with articles, Beamer allows only one class option to be specied in a single document. This restriction may require some creative thinking on your part to overcome some problems, such as specifying font size on each slide.
39
9.1
Frame Basics
Beamer refers to slides as frames, and they will be the heart of your presentation. Within a frame, you can do the commands that you know and love from articles, including text formatting, itemizing, and environments. Beamer wants to give your frames titles along with the beginframe command, so you will either need to specify the title you want for each frame or risk having Beamer do it for you. If you do not specify a title, the rst letter of your frames content will become the title of the frame. Suppose I want to give my slide the title Cheese in Wisconsin with the subtitle An Exploration. The text for such a frame would look like this: \begin{frame} {Cheese in Wisconsin} {An Exploration} Heres my content. Cheese is very popular in Wisconsin. They like all sorts of cheese, not just gouda. \end{frame} The text of the content will automatically be ush left in the center of the slide. To make bullet points on the slide, use the itemize command: \begin{frame} {Cheese in Wisconsin} \begin{itemize} \item{Wisconsin is known as Americas Dairyland.} \item{Recently, advertisements have appeared on television suggesting that California cows are happier and hence make better cheese.} \item{Thats a load of manure!} \end{itemize} \end{frame} Without specifying an overlay (to be discussed later), all bullets will appear on the slide at once. If you want to include a verbatim environment in your frames, youll need specify at the beginning of the frame environment that the frame contains fragile textthat is, text that the program should not do anything with. This is down via the fragile frame option, like this: \begin{frame} [fragile=singleslide] {The Basics of Starting and Ending} You can then enter verbatim text in the usual way and to your hearts content!
9.1.1
Title Frames
Even though you include the title, author, and date information in the header of the document, Beamer will not automatically make a title frame for you. Instead, you will need to tell it to put that title information in a frame, likely the rst of the presentation. Doing so is as simple as putting the maketitle command in the content of a slide, like this: 40
\begin{frame} \maketitle \end{frame} The title and author information will be centered on the title slide. In addition, and depending on what them you select for your presentation, portions of the information may be repeated on slides throughout the presentation.
9.1.2
Sections in Beamer
Beamer does allow you to specify sections and subsections within a document just as you would for an article; however, these designations will not appear in the frame itself. Instead, if using a theme with a navigation bar, they will appear on that navigation bar and will be highlighted or somehow change colors to indicate where in the presentation the current slide is. Regardless of what theme you are using, sections and subsections will become bookmarks in the Adobe version of your presentation. For ease of navigation and clarication in present, Id recommend including sections. Put section and subsection commands within a frame, using the same commands you already know and love: \begin{frame}{Introduction: What is Beamer?} \section{Introduction} \end{frame}
9.1.3
Columns
You may want to split a frame into columns to put in a gure beside text, two gures side-by-side, or just to give yourself a challenge. Splitting the frame involves beginning the columns environment and then specifying what you want in each column. You can also specify the width of the columns as you would for a gure. It goes like this: \begin{frame} \begin{columns} \begin{column}{5cm} Cheddar is named after the village of Cheddar in England. \end{column} \begin{column}{5cm} Cheddar, England, is located in Somerset. \end{column} \end{columns} \end{frame}
41
9.1.4
Graphics
There are a number of packages you can use to include graphics in your presentation, including graphics, graphicx, and pgf. Here, Ill use graphicx, although all those packages should work with few problems in Beamer.4 Although these packages are included in the main Beamer download, its a good idea to call whichever one youre going to use at the beginning of your document. Including graphics in your presentation is quite simple. For any of the .pdf, .jpg, .jpeg, and .png le extensions, the generic command is this: \includegraphics[key=value,...] {file_name} You may or may not need to use the extension in the le name. Using .png gures (which both Stata and R can save graphs as), I havent needed to use the extension. The key options in square brackets size (i.e., width and height) and position (angle) A your gure. For example, to tell L TEX I want my gure to be two inches in height, I use the following code. \begin{figure} \caption{Democratic Opinion, 8/94} \includegraphics[height=2in] {D894pie} \end{figure} Finally, when including graphics, do not forget to begin and end the gure environment!
9.1.5
Overlays
Overlays refer to pauses or appearance displays for text in a frame. They are the equivalent of animation schemes in PowerPoint. There are several commands that will allow you to control the display of text. If you are using overlays, make sure that you are not using the transparency or handout class option, which cancel the eects of the overlay commands. In addition, when you use these commands, Beamer will actually create separate Adobe pages for each view of the slidethat is, for each pause command, youll create a new page. For example, if you have a two-item list and want to display them one-at-a-time, Beamer will actually create two slides (two pages in the PDF le) for that single frame. Pauses The most basic of these commands is the pause command. The pause command tells Beamer to do just thatpause at that point in the frame and remain paused until you tell it to advance by striking either the space bar or arrow keys. Pause is quite basic and no frills but will probably be appropriate for much of the revealing you want to do. An example:
The graphics and graphicx packages are related and have similar functionality. Graphicx is an extension of graphics and uses slightly dierent syntax.
4
42
\begin{frame}{Categories of Cheese} \begin{itemize} \item We can divide types of cheese by texture: \pause \item Soft cheeses like Brie \pause \item Hard cheeses like Parmesan \end{itemize} \end{frame} Overlays (For Real This Time) To do something a bit fancier than the pause command, there are a number of commands available for creating overlays, each of which does a slightly dierent type of overlay/reveal of the text. Im only going to address a few of them; more are available in the Beamer handbook. Regardless of which command you use, youll need to specify on which page you want the command to apply. The onslide command is the rst of the available commands for creating an overlay specication. When using this command, list immediately after it on which pages you want the text displayed. Also note that the eect of the most recently specied onslide command will last until another onslide or until you end the frame. \begin{frame} Here Im writing a slide with four points. This text will be shown at all times. \begin{itemize} \onslide<1> \item{This item is only shown on the first page.} \onslide<2-3> \item{This item is shown only on pages two and three.} \onslide<3-> \item{This item is shown from page three until the end of the frame.} \onslide<4> \item{This final item is all on page three until the end of the frame.} \end{itemize} \end{frame} Setting up a list of bullets in this way covers the items not displayedthey wont be visible at all. If youd like them to be visible, but only faintly so, include this command in your preamble: \setbeamercovered{transparent} You can also change how individual pieces of text appear on the slide, either in bold (the textbf command) or by their color (the color command). Both are demonstrated in the following slide. \begin{frame} \color<2-3>[red]{Barry Alvarez \textbf<3>{loves} eating at the Pasta Barn. \end{frame} 43
Transitions Transitions refer to the visual eects used to display a slide. There are a number of transitions available in Beamer, including transdissolve: the slide dissolves in transblindshorizontal: appears as if horizontal blinds opened transblindsvertical: appears as if vertical blinds opened (surprise!) transboxin: appears by moving to the center from the corners transboxout: appears by moving from the center to the corners transwipe: wipes out the text transglitter: glitter eect sweeps across screen This list is only a selection of the possibilities; see the Beamer handbook for a full list. Transition commands can be placed anywhere in the frame and are overlay specic, so that you may use dierent transitions for dierent parts of the slide, just as you can with overlays.
9.1.6
Hyperlinks
To create simple hyperlinks to another point in our presentation, you can use the hyperlink and hypertarget commands. Youll essentially be creating two slides together, the initial slide and the slide to which you want to jump. You may separate these slides so they are not back-to-back in the presentation by putting other frames in between them. Use the hyperlink command in the initial slide, putting both the label of the target and the text you want for the link in curly brackets. The clickable text will not be underlined in the presentation. In this example, the clickable text is click here. \begin{frame}{Starting slide} \hyperlink{mytarget}{Click here} to go to the target slide. \end{frame} \begin{frame}{Target slide} \hypertarget{mytarget}{} Yup, we are there! \end{frame} Alternatively, you can create a click-able button to take you to the target slide. To do this, youll need to label your target slide using the label option and use the beamergotobutton command to specify what you want the button to say. The same slides above can be done in this manner using this code:
44
\begin{frame}{Starting slide} Lets go to the target slide. \hyperlink{targetslide}{\beamergotobutton{To target!}} \end{frame} \begin{frame}[label=targetslide]{Target slide} Yup, we are there! \end{frame} Again, you can put the slides anywhere in the presentation.
9.1.7
To use animations, including movies and sounds, youll need to call the package multimedia at the beginning of your presentation. The command movie can be used for both movies and sounds. The command will call the movie, but the original le will not be embedded in the PDF le. In other words, Acrobat will have to open some sort of player and youll need to keep the le in the same folder as the nal PDF. The generic command is \movie[options]{poster_text}{movie_filename} The movie will use a rectangular area, the size of which is determined by the poster text or by the height and width specied in the options. The poster text can be any text, include a graphic, included in the normal way that graphics are included. Some other options available are autostart: starts the movie as soon as the page appears duration=(time)s: how long, in seconds, the movie should run external viewer: launches the movie in an external viewer loop: loops the movie so you can enjoy it over and over and over (the default is to only show once) poster: shows the rst frame of the movie when the movie is not playing start=(time)s: causes the rst x number of seconds of the movie to be skipped. To show a movie, use code similar to this: \movie[width=3cm,height=2cm,poster]{}{sample_movie.avi} Note that you may have a hard time with center types of les, particularly Windows Media Files, which appear to not be supported by Acrobat. The same commands will work with sounds. The downside of using the movie command with sounds is that you cannot play more than one movie at a time and that playing will stop when you leave the frame. If thats particularly troublesome, go to the sounds command. 45
9.1.8
Notes to Self
If you want to make a note to yourself to be witty, entertaining, informative, and concise, use the note command. You can put the note command either in a frame environment or outside of one. Either way, it looks like this: \note{Make fabulous joke here about cheese!}
9.2
Appearance
A One of the big advantages of Beamerand L TEX in generalis that it is relatively easy to create a pretty document. Beamer has attractive built-in templates and can also be customized to be more exible. The appearance of your document is alternated by using themes, of which there are ve general types:
Presentation Color Font5 Inner (inner refers to the inside elements of a frame, i.e., those not in the header, footer, or sidebar Outer (the remaining elements from Inner)
9.2.1
Presentation Themes
Presentation themes, which are essentially the equivalent of the design templates in PowerPoint, specify every detail of a presentation. You can leave presentation themes as they are, or change aspects of them as you desire. Either way, the rst step is to identify a presentation theme to use. There are numerous themes available; a Google search for beamer themes will bring up lists and galleries of themes from which to choose. Almost all presentation themes are named after cities which hosted computer science conferences, most of which are more exotic than the Chicago locale that we political scientists know and love. The themes vary in the elements they include; some have navigation bars, a table of contents on a side bar, your contact information somewhere on the page. Regardless of which one you pick, call the theme at the beginning of your presentation, like this: \usetheme{Dresden} You can build your own themes or pick in choose elements of themes using some of the other theme options.
5
I wont be addressing font themes; if you want to read up on them, consult the ocial Beamer guide.
46
9.2.2
Colors
Color themes allow you to specify the colors for all elements of your frames. You can do this either by creating the color yourself or using one of the preset color themes. Creating colors requires dening the colors in the options of the usecolortheme command, which you can do in several ways: rgb=rgb tuple, where the numbers are decimals between 0 and 1 and youre using the red-green-blue tuple RGB=RGB tuple, similar to the above option, expect that the numbers run between 0 and 255 cmyk=cmyk tuple, decimals between 0 and 1 using the cyan-magenta-yellow-black tuple cmy=cmy tuple, much like the one above, but without black hsb=hsb tuple, the hue-saturation-brightness tuple, numbers between 0 and 1 named=color name, for use if you have previously dened a color using the DeneNamedColor command All tuple specications should be within curly brackets and will be applied to the structurei.e., the structural elements of the presentation (the title text, the headers and footers, the bullets, etc.). For example, to create a dark bluish green, I used this command: \usecolortheme[rgb={0,.5,.5}]{structure} Alternatively, you can use built-in color themes, of which there are three main types: complete, inner, and outer. Complete Color Themes Complete color themes are those which completely specify all colors for all frame elements. Most complete themes are named after ying animals and include albatross, beetle, crane, dove, y, seagull, wolverine,6 and beaver (for MITs mascot). As will all color themes, youll use the usecolortheme command in the preamble of your document: \usecolortheme{seagull}
6
47
Inner Color Themes Inner color themes are used to change the colors of the inner frame elements, particularly blocks, which are used in presenting mathematical theorems and proofs. As such, they may not be especially useful to folks in political science. Regardless, you can use inner color themes to modify other color themes, in which case the inner color theme command should follow the command for the other theme. The inner color themes are named after owers: lily, orchid, and rose. Outer Color Themes Outer color themes change the colors of the headline, footline, and sidebar. Can you spot the theme in the names? Outer color themes include whale, seahorse, and dolphin. Do you guess sea animals? If so, you are correct!
9.2.3
Inner Themes
Inner themes dictate certain frame elements are typeset, including title pages, gures, and itemized environments (which is probably where youll notice the biggest dierence since they change how bullets work). Call the inner theme you want to use in the preamble of your presentation: \useinnertheme{circles} Inner themes do not have catchy names, but here they are: circles, rectangles, rounded, and inmargin.
9.2.4
Outer Themes
Finally, outer themes dictate the layout of the headline and footline, sidebars, logo, and frame title. Outer themes are a good way to personalize the look of your presentation, particularly if you are unhappy with all of the presentation themes, since you can specify which elements you would like to have. The possibilities (with limited descriptions): infolines: adds informative head- and footlines miniframes: adds headline with navigation bar smoothbars: similar to miniframes, but doesnt add a footline sidebar: adds a (guess what?) sidebar with navigation; you can size it by adding a width or height option or move it to the right or left with options split shadow tree 48
9.2.5
Logos
Finally, youll of course want to add your very own logo to your slides. Doing so involves using the logo command in your preamble. To add Bucky to my frames, I put this in my preamble: \logo{\includegraphics[height=2cm]{bucky.png}} If you want to use a logo, you will not be able to move it around freely on the frames; the location of the logo is determined by the theme that you are using.
49
Chapter 10
Formal Models
A Creating formal models in L TEX involves two styles, both available (along with documentation that describes additional options) here: http://www.economics.utoronto.ca/osborne/latex/. One, sgame.sty, makes strategic games, while the other, egameps.sty, constructs extendedform games. Both packages can be installed through the package manager in WinEdt. In addition to calling either package (or both!), you will need to put \usepackage{pstricks} at the beginning of your document. Compiling .tex les and creating pdf documents that contain either sgame or egameps gures is a less straightforward process than a straightforward text-based .tex le. Because the games are included as PostScript les (but not imported with the usegraphic command like other .ps or .eps gures), youll need to compile in three separate steps.1 First, create A a .dvi le with the L TEX button, create a PostScript le out of the .dvi with the dvi2ps button, and nally, turn the PostScript le into a pdf with the ps2pdf key. To compile A games, you cannot use the Bear, the PDFL TEX key, or the dvi2pdf command - you must follow the three step, dvi2ps2pdf process.
10.1
Strategic Games
The basic syntax for strategic games follows this format: \begin{figure{[htb] \begin{game}{numberofrows}{numberofcolumns} body \end{game} \end{figure} Where the game body follows the same format as the tabular environment described in Section 5.2. For example:
Its also worth noting that sgame and egameps create a fair number of other compatibility issues with other style packages. They cannot, for example, be used in a document that contains imported graphics that are not .ps or .eps le types, and you cannot use them in the same document as the dcolumn package explained in section 5.2.1.
1
50
\begin{game}{2}{2} & $C$ & $D$\\ $C$ &$3,3$ &$1,4$\\ $D$ &$4,1$ &$2,2$ \end{game} produces a basic 2x2 Prisoners Dilemma game:
C D
C 3, 3 4, 1
D 1, 4 2, 2
However, a nicer-looking PD can be created by including some optional commands to center the matrix on the page, print player names, increase the size of the cells, and label the game.2 For example: \begin{figure}[h]\renewcommand{\gamestretch}{2}\hspace*{\fill}% \begin{game}{2}{2}[Player~A][Player~B] & $C$ & $D$\\ $C$ &$3,3$ &$1,4$\\ $D$ &$4,1$ &$2,2$ \end{game}\hspace*{\fill} \caption[]{Basic One-shot PD Game} \end{figure} Produces a much more attractive dilemma for our proverbial prisoners:
Player B C C Player A D 4, 1 2, 2 3, 3 D 1, 4
51
10.2
Extended-Form Games
Drawing an extended-form game is somewhat more complicated than creating strategicA form games. Creating a game tree requires telling L TEX the dimensions of the space you will draw in, creating labels and payos, specifying where branch lines begin (using grid coordinates), noting their slopes, and calculating where to start the next set of branches based on that information. I cant give you any better advice than this: sketch the game on paper rst. If you dont want to take my word for it, this advice comes straight from Martin Osborne (the creator of the code that creates these pretty games) so take it to heart. To start the process, the rst step is to specify the total width and height in pixels of the PostScript gure youll be creating \begin{egameps}(width,height) Where (width,height) might be (1000,500) for an average-sized horizontally-aligned game tree. For each branch, you need to specify: \putbranch(startwidth,startheight)(x,y){length} Where (startwidth,startheight) is the grid location of the initial node of the rst branch on the gure you created. You will also need to specify the number of branches on the node - either \ib (for one branch) \iib (for two branches) or \iiib (for three branches). Labels are placed in brackets and the payos (if desired) placed in square brackets after the command. Infosets are placed using the \infoset command. Here is some sample code for a strategic-form Prisoners Dilemma:
\begin{figure}[htb] \hspace*{\fill} \begin{egame}(600,280) \putbranch(300,240)(2,1){200} \iib{1}{$C$}{$D$} \putbranch(100,140)(1,1){100} \iib{}{$c$}{$d$}[$3,3$][$1,4$] \putbranch(500,140)(1,1){100} \iib{}{$c$}{$d$}[$1,4$][$2,2$] \infoset(100,140){400}{2} \end{egame} \hspace*{\fill} \caption[]{Sample Game}\label{mygame} \end{figure}
In this code: \begin{egame}(600,280) creates a game space that is 600 pixels wide by 280 pixels tall 52
\putbranch(300,240)(2,1){200} \iib{1}{$C$}{$D$} creates a branch in the horizontal center of the gures and 40 pixels from the top edge. This branch has a slope of two horizontal pixels for every one vertical pixels and is a total of 200 pixels wide (but only 100 pixels vertical, based on the specied slope) It is labeled for Player 1 and has branches labeled L and R. \putbranch(100,140)(1,1){100}\iib{}{$c$}{$d$}[$3,3$][$1,4$] creates a branch coming o the left node (note that is is 200 to the left and 100 below the origin point) that is steeper and shorter than the original branches. It is not labeled for a player, but has two labels and two payos. \putbranch(500,140)(1,1){100}\iib{}{$c$}{$d$}[$1,4$][$2,2$] creates a corresponding branch on the right node \infoset(100,140){400}{2} creates a dashed line for the infoset and labels it for Player 2 Which produces: 1 C 2 c 3, 3 d 1, 4 c 1, 4 d 2, 2 D
Using the same sort of commands, you can create virtually any game tree. Heres an example of a signaling game, with the code used to create it pasted below. Since creating A strategic-form games involves more trial-and-error than perhaps any other L TEX skill, its worth going through the code line-by-line to see how the gure was created from it. The only new command is \egalhshift=20 which shifts the line labels horizontally by 20mm (just like \egalvshift=50 would shift them vertically by 50mm).
\begin{figure}[htb] \hspace*{\fill} 53
2, 1
4, 3
2, 1
4, 3
C Y Hi X Lo Y q N ature (1 q)
Hi X Lo
1, 4
3, 2
\begin{egame}(1280,800) \putbranch(640,400)(1,0){440}\iib{$Nature$}{$q$}{$(1-q)$} \putbranch(200,400)(0,1)[r]{200} \iib{X}{$Hi$}{$Lo$} \putbranch(1080,400)(0,1)[l]{200} \iib{X}{$Hi$}{$Lo$} \infoset(200,600){880}{Y} \infoset(200,200){880}{Y} \putbranch(200,600)(1,1)[u]{200}\egalhshift=20\iib{}{$F$}{$C$}[$2,1$][$4,3$] \putbranch(1080,600)(1,1)[u]{200}\egalhshift=20\iib{}{$F$}{$C$}[$2,1$][$4,3$] \putbranch(200,200)(1,1)[d]{200}\egalhshift=20\iib{}{$F$}{$C$}[$1,4$][$3,2$] \putbranch(1080,200)(1,1)[d]{200}\egalhshift=20\iib{}{$F$}{$C$}[$1,4$][$3,2$] \end{egame} \hspace*{\fill} \caption{Resolve-signaling Game}\label{f:four} \end{figure}
54
Chapter 11
Sweave
Using Sweave is one step away from the pinnacle of stats-computing geekiness (we reserve the peak for those who use Linux, write their own programs and packages, etc.). Sweave A allows for a seamless integration of R and L TEX. The basic idea is that you write a le that contains both regular text and R commands. When you run the le in R, the output from the commands, plus your regular text, is placed in a .tex le that you can then compile as A you would any L TEX le. How can you achieve this miracle? 1. Make sure you have the utils package installed in R (this package contains Sweave) A and the Sweave.sty package in your L TEX package tree. If you dont have the style package, you can get it here: http://www.maths.lth.se/help/R/.R/share/texmf/Sweave.sty A just save it in the same directory as your L TEX document.
A 2. Open a blank document in WinEdt. Write as you would any L TEX document, except for the following:
Include \usepackage{Sweave} when you call packages at the beginning of the document. Save the document as a .Rnw le instead of a .tex.
A Within the L TEX document, you should enclose R commands like so:
<<echo=FALSE>>= library(foreign) load("indivdata-attitudes.RData") indivdata.att2<-subset(indivdata.attitudes,decade>=1950) attach(indivdata.att2) @ If you changed the <<echo=FALSE>> to <<echo=TRUE>>, both the commands and the output would print in your .tex le. With <<echo=FALSE>>, only the output will print. If youd like to send a gure to your .tex le, youll want to do it this way: 55
<<fig=TRUE,echo=FALSE>>= plot(swa.con.prop~decade.axis,type=l) @ You can also preset the size of your gure, etc. See the resources listed at the end of this chapter for more information. When your document is ready to go (make sure to save it as a .Rnw!), all you do is go into R, use setwd to set R to the correct directory and type the following: Sweave("docname.Rnw") This should run the R commands and create a .tex document that you can then open in WinEdt and TEX as usual. For more information, these sites are useful: http://www.ci.tuwien.ac.at/~leisch/Sweave/ http://www.peterrudloff.org/docs/sweave.pdf#search=%22sweave.sty%22 http://www.stat.wisc.edu/~neely/sweave/SweaveTalk.pdf#search=%22sweave%22
56
Chapter 12
57