























































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!
























































(^1) We would like to thank the former UW-Madison graduate students who contributed to this guide: Rudy Espino, Erika Franklin Fowler, Mike Franz, Stacey Pelika, and Travis Ridout. In addition, some of the material on figures and tables was drawn from “Doing Figures and Tables in LATEX” by Charles Franklin. Please do not copy or draw from this work without permission.
1.1 What in the Heck Is LATEX?
LATEX (pronounced ‘la tech’ or ‘lay tech’) is a cultish typesetting program that is beloved by academics for the flexibility it offers in creating documents and the beautiful products that result. It is important to note that LATEX is not a word-processing program! Unlike Word, in which you enter content and format as you go, LATEX is more like a programming language. You enter your content and the LATEX commands into a text editor (such as WinEdt), then use LATEX to create a .dvi (for ‘device independent’) file. This .dvi file must then be translated by a device driver into output that is readable by humans. In general, folks in North Hall translate their files into the familiar .pdf format. The structure of the program means that as you’re working on your document, you will not, sadly, see what it will look like when it is finished. However, that despair will be erased when you see how pretty it is in the end! Also, LATEX feeds into the inner geek in all of us by allowing for endless expansion through ‘packages,’ or macros that tell LATEX to do use certain fonts, format text in particular ways, or include unique functions, such as printing in musical notation.
1.2 Getting LATEX
Installing LATEX can be a somewhat intimidating experience. The upside is that all of the programs are free! In general, you will want to install the following programs and package sets:
1.3 Environments and Commands
Throughout this document we will refer to the use of environments and commands to format your document and text. In general, environments are used to format larger chunks of text – for example, making an enumerated list. Environments start with \begin{environmentname} and end with \end{environmentname}. In contrast, commands are used to format smaller pieces of text or to reference a citation or label. Commands look like this: \commandname[option]{}. Somewhat confusingly, there are some functions (such as the Verbatim environment) that can be invoked as either an environment or a command!
1.4 Important Features of WinEdt
Assuming you’re using WinEdt, there are a few important features that will make your life a lot easier!
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:
If you click on any of the items in this menu, you will be taken to that cite, label, and so on, providing a handy way to navigate through your document. In addition, if you need to put an item into a reference or citation and you don’t or can’t use the ‘type {} and have the box pop up’ method, you can double-click on cites or labels in the Gather menu to place them into \ref{} or \cite{} commands.
1.6 Further Assistance
Although working with LATEX is fairly easy once you get used to the syntax, problems will inevitably arise. When you need help, we recommend the following sites:
We will also place the handouts from today’s workshop and some other helpful guides in a LATEX folder on the public drive.
2.1 Sample Template
To write a document, you can utilize the document template that we have placed on the Public drive of the Political Science Server. This template loads important packages and sets the fonts, as well as adding a title and abstract to your document if you wish.
P:\latex\textemplate.tex
The Template file has the following, entered “as is” in your WinEdt file:
\documentclass [11pt]{article} \usepackage[margin=1in]{geometry}
\title{A New Theory of Post Office Committee Behavior\thanks{This paper was prepared for the 2002 Conference on the Post Office Committee, University of Alaska, Fairbanks, Alaska, July 19-21. Thanks to David Canon for his assistance.}} \date{July 19, 2002} \author{Your Name\University of Wisconsin-Madison\ [email protected]}
\begin{document}
\maketitle
\begin{abstract} The Post Office Committee has long been the most important committee in Congress. \end{abstract}
To change line spacing in only a segment of a document:
2.5 Indenting and Un-indenting
LATEX will automatically indent all paragraphs except for the first one in a segment of text (a section, chapter, etc.). To add an indent to a paragraph, use \indent at the beginning of the paragraph. To remove an indent, use \noindent at the beginning of the paragraph.
2.6 Aligning Left, Right, and Center
If you haven’t noticed already, LATEX attempts to make every line of text the same length — much like justified formatting in Microsoft Word. This is the default setting, but you can request that it format your page differently by using the flushleft, flushright, and center environments. To get your document to align left, you can request the flushleft environment using the following commands:
\begin{flushleft} This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. \end{flushleft}
In the document, you see that LATEX is no longer trying to make all lines the same length, and all lines are aligned left.
This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment. This is a test of the flushleft environment.
The flushright and center environments work the same way!
2.7 Line Breaking, Page Breaking, and Leaving Blank Pages
To create a new paragraph in LATEX, all you need to do is hit return twice in WinEdt – in other words, you need to leave a full space between your paragraphs so LATEX knows it’s a new paragraph. You can also force a line break by typing ‘\’ or by typing \newline. To break to a new page, you can either use \newpage or \clearpage. The latter command makes sure to process all commands up to that point, so it’s often the better choice, or, alternately, you should use them in combination. However, if you’d like to leave a totally blank page, you can’t simply use \newpage or \clearpage twice in a row. Instead, you have to trick LATEX into thinking that there’s something in between the two commands to break a page. The easiest way to do this is by making an empty box with no border. The commands look like this:
\newpage \mbox{} \newpage
2.8 Adding Vertical Space
Sometimes you need to insert a bigger chunk of space than a line. LATEX can be finicky about this – you can’t simply use \ as many times as you’d like to get a lot of space. Instead, it’s much easier to use the \vspace{} command. In the brackets, you put the amount of space you’d like to leave, which can be in millimeters or inches (and probably picas or other measures as well). For example, if you wanted to leave an inch between paragraphs, you’d use \vspace{1in}. One caveat: LATEX will not allow you to add space at the very top of your first page with this command. To do that, you need to use \vspace{} – the * lets LATEX know you really mean it! To put 10 millimeters at the top of the page, for example, use: \vspace{10mm}.
2.9 Titles, Abstracts, and Table of Contents
This guide covers commands within the ‘Article’ document class since it is the most com- monly used. Most of the same commands apply to other document classes (Book, Re- port, etc), but this is not intended to be a complete guide. For more information, see http://tex.loria.fr/index.html.
Creating titles in LATEX is easy. Titles have three basic arguments:
Creating a table of contents is a painless task. LATEX keeps track of all of your section headings and page numbers for you. All you have to do is insert a table of contents command after the title page. The \newpage commands below ensure that it appears on its own page, but they are not required. After your title and abstract insert:
\newpage \tableofcontents \newpage
One important note: In order for LATEX to compile all of the page numbers for the con- tents page correctly, you need to make sure you LATEX the document twice (or, sometimes, more than twice!).
2.10 Chapters, Sections, Subsections, and Subsubsections
To help organize your document, you can divide your work into chapters and sections by using the section commands: \chapter{} (for Report and Book classes), \section{}, \subsection{}, and \subsubsection{}. The heading for this section was created by using the following command:
\section{Sections, Subsections, and Subsubsections}
The \subsection{}, and \subsubsection{} commands work the exact same way.
2.11 Labels and Cross-References
One of the biggest advantages to LATEX is its automatic numbering and reference system. Much like the way it keeps track of section numbers, the program also keeps track of how many tables and figures you have in your document and automatically numbers them for you. As a result, you never have to worry about inserting new tables at the beginning of your paper and screwing up the numbering throughout the rest of the document. The trick to using references in your document is to label anything you think you may want to refer to later. For example, if I wanted to refer to this section, I would need to include a \label command directly after the section command. Labelling tip: make sure you label items with a descriptive title, so you can easily find which one you need. For this example, I have labeled the section ‘Reference Section.’ The code looks like this:
\section{Labels and Cross-References}\label{Reference Section}
If you wanted to refer to this section, you would type \ref{}. A selection box will automatically pop up in WinEdt when you type the closing bracket (}) with all of the labels currently in your document for you to select the appropriate one. When you highlight the reference you want and hit return, the program will fill in the label within the reference
command for you. In this case, it would fill in like this: \ref{Reference Section}. So, a reference to the current section in WinEdt would look like this:
‘‘in Section \ref{Reference Section} we discussed labels and cross-references."
The sentence will appear in the document as follows: “in Section 2.11 we discussed labels and cross-references.” LATEX also keeps track of the page numbers that correspond with each of your labels, so you can refer readers to the specific page if you like using the \pageref{} command:
‘‘in Section \ref{Reference Section} on page \pageref{Reference Section} we discussed labels and cross-references."
It will appear like this: “in Section 2.11 on page 10 we discussed labels and cross-references.”
2.12 Hyperreferences
Sometimes you’ll open a document generated in LATEX (such as this one) and realize that all of the references work like hyperlinks – in other words, you can click on the reference in Adobe Acrobat and you’ll be taken to that section. Doing this is remarkably easy. All you need to do is add \usepackage{hyperref} as the very last package call in your preamble. Once caveat: if you’ve already generated a table of contents for your document before inserting the call to hyperref, go into the directory your file is in and delete the .toc document for that file or else LATEX won’t compile your document.
Command Font Style \textbf{} Bold \textit{} Italics \texttt{} Typewriter \textsc{} Small Caps
3.3 The Verbatim Environment
Wondering how to get LATEX to print commands without executing them? How can you get the program to display exactly what you type? The answer is through the verbatim environment. In order to display the commands throughout this document, the following commands are used:
\begin{verbatim}
These commands will ask {\LaTeX} to print things exactly as you type them.
\end{verbatim}
To display commands lines within a paragraph, you can use the \verb++ command, where text placed in between the two plus signs (+) is printed in typewriter font, just as in the verbatim environment. For example, to type the previous sentence, you would need to type, “To display command lines within a paragraph, you can use the \verb++ command, where text in between the two plus signs (+) is printed in typewriter font, just as in the verbatim environment.”
3.4 Special Characters
There are 10 special characters. They are:
These characters are part of commands in LATEX, so if you would like to use one of these characters in your text (i.e., I have only $5 in my pocket), you must type this as:
I have only $5 in my pocket.
Note the backslash before the dollar sign. So, to produce these characters, instead of typing the character itself, you must type one of the following:
# $ % & _ {} $\tilde{}$ $\grave{}$ \verb++
You’ll notice that LATEX assumes that every single or double quote typed using the normal keys is a closing quote (’ or ”). So, for example, if you type "Cool!", you’ll get: ”Cool!” To get an opening quote, use the accent key (generally found on the same keyboard key as the˜) – one accent for a single quote, and two for a double quote. For example, ‘‘Great!" gives you: “Great!” and all the quotation marks are facing the proper direction just as they should be.
LATEX offers a variety of hyphen and dash lengths. To get a regular hyphen, simply type a single hyphen. For a longer dash (–), type two hyphens (--). For a really long dash (—), use the bar (|).
3.5 Quotes
To set text as a quote, use the quote environment. For example,
\begin{quote} I have a dream that my four children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character.\end{quote}
will get you:
I have a dream that my four children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character.
Since inline quotes in a double-spaced document are generally single-spaced, you will want to combine the \begin{quote} and \end{quote} commands with \begin{singlespace} and \end{singlespace} commands. In a double-spaced document, the quote above would need to be inserted as:
\begin{quote} \begin{singlespace} I have a dream that my four children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character. \end{singlespace} \end{quote}
3.6 Footnotes and Endnotes
To enter footnotes, simply put
\footnote{}