A Short Manual Of La Te X
User Manual:
Open the PDF directly: View PDF .
Page Count: 9
Download | |
Open PDF In Browser | View PDF |
A Short Manual of LATEX Haohan Chen ∗ August 13, 2015 In this short manual, I will summarize all LATEXcommands that we practiced in our workshop. Hope it serves as a quick reference when you start working on it. 1 To Write an Article: Everything you need to get started... The following code should cover most of the functions we need from LATEX. Feel free to copy from the following template before you are fully familiar with it. \documentclass[11pt, letter]{article} Define document class as ’article’ and set the size of the text and type of the paper \usepackage{graphicx} \usepackage{natbib} \usepackage{amsmath} \usepackage{hyperref} You need it if you include figures. This package creates nice citations and bibliography for you You need it if you type maths. With this package, your table of contents, list of figures, list of tables, citations, reference to tables (using \ref) will have hyperlinks directing readers to those contents respectively. \usepackage[margin=2.5cm]{geometry} You may set your page margin here. If you want to further customize, type, for instance, [left=2cm, right=2cm, top=2.5cm, bottom=2.5cm] in place of [margin = 2.5cm] Use Times font. Spacing between lines \usepackage{times} \linespread{1.5} \author{Your Name \thanks{Duke} } \title{Your Title} \date{} Print author. Anything after \thanks appear as footnote on the page where you print your title. The title of your article If you do NOT want date printed, put nothing between {}. If you would like to print the date of today, put \today between {}, or simply do not include this command. ∗ haohan.chen@duke.edu 1 A Short Manual of LATEX \begin{document} \maketitle \newpage \tableofcontents \listoffigures \listoftables \section{...} \subsection{...} \paragraph{} \begin{itemize} \item YOUR TEXT \\ \item YOUR TEXT \\ ... \end{itemize} \begin{figure}[hptp!] \centering \caption{Title} Political Science Math Camp 2015 Haohan Chen This marks the start of your document. Anything before this sets up the document, while everything between this and \end{document} will appear in the final product. Tell LATEXto print the title, author and date here. Start the following in a new page. You can put it anywhere you wish to break the page in your document. Make a table of content Make a list of figures Make a list of tables Start a new section. Use \section*{} if you do not want the section to be numbered. The sign ’*’ serves the same function for many others command in LATEX. Start a paragraph. I use this when I need to add a little title for a paragraph. Otherwise I will simply start typing the content right away. Note that a blank line starts a new paragraph. Write bullet points The first item... Make sure to leave a space between \item and your text so that LATEXcan recognize the start of each point. Also don’t forget the end-of-paragraph sign \\ before you start your next point. Note: If you want your bullet points number, replace itemize with enumerate, at the beginning and the end of the command. If you want a nested bullet point, you can put \begin{itemize}...\end{itemize} inside a bullet pint environment. FIGURE. Adding a figure into your document. What’s inside [..] tells LATEX where to place the figure. h: here; p: in a separate page with other figures/ tables; t: top; b: bottom; !: tells LATEXto try HARD to over the default setting (i.e. tbp) with your preferred setting indicated here. Try not to use description such as ’the figure above’ because LATEXis very likely to rearrange the placement of your figures as you edit the document. Put the figure in the center The title of your figure 2 A Short Manual of LATEX Political Science Math Camp 2015 \label{fig1} \includegraphics[width=4in]{"name"} Haohan Chen Create a reference point so that you can refer to the figure in your text using \ref{}. Here I set the reference name as fig1. You may use whatever name you want, as long as one figure has a unique reference name. Set up the figure. You can set the width and height of the figure: [width=4in, height=4in]. If you include only one of them (as I do on the left), the figure will be re-sized proportionally. You use {"name"} to tell LATEX the name of the image file, which you should put in the same folder as your .tex file. Caution: Use simple names for the source files of figures. Otherwise there might be strange errors. \end{figure} The code on the left gives you a table that appears as the following: Table 1: Your Title 11 12 13 21 22 23 31 32 33 \begin{table}[hptb!] \centering \caption{Your Title} \label{tab1} \begin{tabular}{|l|c r|} \hline \hline 11 & 12 & 13 \\ 21 & 22 & 23 \\ 31 & 32 & 33 \\ \hline \multicolumn{2}{|l|}{41-2} & 43\\ \hline 41 & \multicolumn{2}{|r|}{42-3}\\ \hline \multicolumn{3}{|c|}{51-3}\\ \hline \hline \end{tabular} \end{table} 41-2 43 41 42-3 51-3 Some highlight: • At the first line, ’|’ Tells LATEX whether to add border between two columns or not. You can see border between the first and the second column but no border between the second and the third column here. l,c,r tells LATEX to align all cell of a column to the left, center or right respectively. • ’&’ moves from one cell from another cell within one row • ’ \\’ moves from one row to next row • To add border between two rows, add \hline in between (after \\ of the previous row) • To merge columns, use \multicolumn. For instance \multicolumn{3}{c}{51-3} means: merging 3 cells, aligning to the center in this merged cell, the text in the cell being ”51-3”. Again, ’|’ adds borders Play with the settings and you will see how it works! 3 A Short Manual of LATEX Political Science Math Camp 2015 ...see Figure \ref{fig1} ...see Table \ref{tab1} Haohan Chen Referring to tables or figures in your text.You may refer to the figure that you label. Note that the label of the figure does not have to be defined before you call it with \ref. Personally I think using the reference system (i.e. \label and \ref) instead of directly typing in the number of the table/ figures help managing your work more efficiently. Same as above. ...we have the equation $a+b=c$... MATHS. When you type math in your main text, DON’T FORGET to use ’$’ to start AND end your equations/ formulas! Remember to check that when you get error reports. \begin{equation} (a + b) (c + d) = e \end{equation} You need this when you enter a single equation. Using {equation*} get rid of the numbers of after equations. \begin{align} y = x^2 & + 3x + 4 \\ & = a + b \\ & = 10 \end{align} You need this when you enter a group of equations and want them aligned to certain place. Here they align to the equal sign. \begin{gather} (x + 3)(y - 1) = 0 \\ xy - x + 3y - 3 = 0 \\ xy - x + 3y =3 \end{gather} You need this when you enter a group of equations and want them aligned to the center. 4 A Short Manual of LATEX Political Science Math Camp 2015 Haohan Chen CITATION AND BIBLIOGRAPHY. Before you start to cite in your document, please do the following: 1. Create a NEW file in LATEX to store your bibliography information. Save it into the same folder as your .tex file. You may give if whatever name as you wish, but the extension should be .bib. For instance, in my example, The name is ref.bib. \citet{...} \citeauthor{...} \citep{...} \citep[postfix][prefix]{keylist} 2. Add bibliography information to the .bib file you have created and saved. I strongly recommend using Google Scholar to collect such information (but make sure to check for occasional mistakes). How to do it? Under your search result, click ”cite”. Next, at the bottom left of the pop-up window, click ”Import to BibTeX”. Then, select-all and copy the information to your.bib file. Last, you should save it, before which it will not appear in the document that cites it. 3. Cite in the document using the command on the left. Note that what you put in {..} should be the reference name of the entry. Here is an example: @article{acemoglu2006facto, title={De facto political power and institutional...}, author={Acemoglu, Daron and Robinson, James A}, journal={The American economic review}, pages={325--330}, year={2006}, publisher={JSTOR} } Here the reference name of this ’acemoglu2006facto’. That is, this work, you should enter, for \citet{acemoglu2006facto}. \bibliographystyle{chicago} \bibliography{ref} \end{document} work is to cite instance, At the end of your document, you may produce your bibliography. This line first sets the reference style as ’Chicago’. This command link your document with a bibliography file named ’ref.bib’, which, as is explained above, you have created in the same folder as your .tex file. End the document. Without this at the end, LATEX will not compile. Sometimes you may accidentally enter stuff after \end{document}, in which case no error will be reported but you lose all information after this point. Be careful! 5 A Short Manual of LATEX 2 Political Science Math Camp 2015 Haohan Chen To Write a Presentation \documentclass{beamer} \usetheme{default} \title{Title of the Presentation} \subtitle{Subtitle} \author{Your Name} \institute{Duke University} \date{\today} \begin{document} \maketitle \section{Name of 1st Section} \begin{frame} \frametitle{Name of 1st frame} \framesubtitle{Subtitle of 1st frame} \begin{itemize} \item First argument \pause \item Second argument \pause \item Third argument \pause \end{itemize} \begin{block}{This is a block} Additional information Additional information \end{block} \end{frame} \section{Name of 2nd Section} \begin{frame} \begin{figure} \caption{...} \label{fig} \includegraphics[width = 4in]{...} \end{figure} \end{frame} If you pay close attention to the previous part, the code on the left is very likely to be easily understandable. Below are several highlights: • beamer is the document class that is most commonly used for presentations. If you use \pause in your pages and you would like to generate handouts, simply substitute \documentclass{beamer} by \documentclass[handout]{beamer}. • Available themes include (to be put after \usetheme, which is defult in my example): default, Antibes, Bergen, Berkeley, Berlin, Copenhagen, Darmstadt, Dresden, Frankfurt, Goettingen, Hannover, Ilmenau, JuanLesPins, Luebeck, Madrid, Malmoe, Marburg, Montpellier, PaloAlto, Pittsburgh, Rochester, Singapore, Szeged, Warsaw, boxes. You can of course search and download other themes from external sources. • Names of sections defined by \section{} will appear in the navigation bar (only applicable when using themes that show navigation bar, for instance Warsaw). • Things between \begin{frame} and \end{frame} makes one slide. • \pause tells LATEX to put the content afterwards to a following page. • You may insert figures or tables as what you do in an article (as I have demonstrated in the second frame of this example). \end{document} 6 A Short Manual of LATEX 3 Political Science Math Camp 2015 Haohan Chen Knitr Motivation Knitr is a handy tool for reproducible research. It allows you to mix your R code and output with your report or paper written in LATEX. If you are following the recent LaCour (2014) scandal in our field, you may want to revisit this famous report that uncovers the fraud (Brookman et al. 2015, accesible from: http://stanford.edu/~dbroock/broockman_kalla_aronow_lg_irregularities.pdf). It is quite obvious that the report is generated by Knitr, which allows the authors demonstrate to the readers how they detect the fraud from the data. For our prospective study, a considerable number of methods courses require writing homework with LATEX. Editors RStudio is a good editor for knitr. However, its disadvantage compared to TeXstudio is that it does not automatically fill your TEX command. Setup I: Install the “knitr” package You may type in the console install.packages(‘‘knitr’’) and press “ENTER”. Or you may use the menu “Tools” → “install packages” and type “knitr” in the pop-up window. Setup II: Change setting Enter the Preference Setting of RStudio (“Global Options” for Windows users, “Preferences” for Mac users). Go to the “Sweave” tab at the left panel. Choose “Weave Rnw files using knitr”. Create a knitr doc To create, press “New File” → “R Sweave”. You will get a new windows with a file with the extension .Rnw. Adding R code chuncks In a knitr document, you indicate the start of a R code chunck with “<<>>=” and its end with “@”. A sample knitr document including simple R code that print the value of a variable and plot a scatter plot is shown as below: \documentclass{article} \begin{document} Below I calculate and print the value of $a = 1 + 1$ <<>>= a = 1 + 1 print(a) @ Below I draw a scatter plot of five points $(1, 1), (2, 2), (3, 3), (4, 4)$ <<>>= plot(x = 1:4, y = 1:4) @ \end{document} 7 A Short Manual of LATEX Political Science Math Camp 2015 Haohan Chen Options You may specify some options for your R chunks: name of the chunck, show/ hide the code (echo=), how to output the result (results=), whether to run the code (eval=), the height and width of a graph (for instance, fig.height = 4, fig.height= 4). Examine how the output of the following chuncks differ when I change the options. <<>>= a = 1 + 1 print(a) plot(x = 1:4, y = 1:4) @ <>= a = 1 + 1 print(a) plot(x = 1:4, y = 1:4) @ < >= a = 1 + 1 print(a) plot(x = 1:4, y = 1:4) @ < >= a = 1 + 1 print(a) plot(x = 1:4, y = 1:4) @ Above is a demonstration of frequently-used options, for more, visit the website of the package author: http://yihui.name/knitr/options/#chunk_options. 4 LyX LyX is a user-friendly TEXword processing software. If you would like to write on LATEXwithout having to worry to much about its syntax, this is what you may try. LyX is downloadable from http://www.lyx.org/ and a considerable number of tutorials are online. 8 A Short Manual of LATEX 5 Political Science Math Camp 2015 Haohan Chen Resources You may find the following resources useful when you work on LATEX: • To have a better understanding on the ’big picture’ of LATEX, you may use one of the following textbooks: – The No So Short Introduction to LATEX 2ε by Tobias Oetiker et al. Downloadable from http: //tobi.oetiker.ch/lshort/lshort.pdf – The Art of LaTeX by Helin Gai. Downloadable from http://www.math.ecnu.edu.cn/~latex/ docs/Eng_doc/LaTeX_Manual_8_6.pdf – If you would like to know more about how to type maths in LATEX, The LATEX Mathematics Companion by Helin Gai is a good place to start. Downloadable from http://hungrydummy.com/ static/pdf/MathCompanion.pdf • You may heavily draw on the following online resources as well: – The LATEX page on Wikibook: http://en.wikibooks.org/wiki/LaTeX. Especially, its ’mathematics’ page covers nearly all we need in our first-year methods class: http://en.wikibooks. org/wiki/LaTeX/Mathematics – Answers to specific questions on the forum stackoverflow (http://stackoverflow.com/) and StackExchange (http://tex.stackexchange.com/) are usually reliable. Try the answers with the highest vote. • Drawing Graphs with package TikZ – To draw scientific graphs, check out Pgfplot. Tutorials and examples are available on https: //www.sharelatex.com/learn/Pgfplots_package. – The package is a handy tool for game trees as well (you may use it for your Game Theory assignments). Here is a tutorial with good examples: http://www.sfu.ca/~haiyunc/notes/Game_ Trees_with_TikZ.pdf – More generally, see the following page for examples of graphs that TikZ can draw: http://www. texample.net/tikz/examples/tag/graphs/ Enjoy! Thank you! 9
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.5 Linearized : No Page Count : 9 Page Mode : UseOutlines Author : Title : Subject : Creator : LaTeX with hyperref package Producer : pdfTeX-1.40.18 Create Date : 2019:01:14 20:36:12-05:00 Modify Date : 2019:01:14 20:36:12-05:00 Trapped : False PTEX Fullbanner : This is MiKTeX-pdfTeX 2.9.6607 (1.40.18)EXIF Metadata provided by EXIF.tools