latex lab: lists, figures, and tables - massachusetts...

10
LaTeX Lab: Lists, Figures, and Tables 2.680 Unmanned Marine Vehicle Autonomy, Sensing, and Communications Spring 2017 Kyle Woerner, k [email protected] Michael Benjamin, [email protected] Henrik Schmidt, [email protected] Department of Mechanical Engineering MIT, Cambridge MA 02139 1 Overview and Objectives 3 1.1 Objectives ............................................... 3 1.2 Deliverables .............................................. 3 1.3 What you will need to get started ................................. 3 2 Basic LaTeX References 4 2.1 Online Documentation ........................................ 4 2.2 Additional Documentation ...................................... 4 2.3 Creating a Basic LaTeX Document ................................. 4 3 Basic Figures 6 4 Lists 7 5 Tables 9 6 Labels 10 7 Bonus 10 1

Upload: vanlien

Post on 10-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

LaTeX Lab:Lists, Figures, and Tables

2.680 Unmanned Marine Vehicle Autonomy, Sensing, and Communications

Spring 2017

Kyle Woerner, k [email protected] Benjamin, [email protected]

Henrik Schmidt, [email protected] of Mechanical Engineering

MIT, Cambridge MA 02139

1 Overview and Objectives 31.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Deliverables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 What you will need to get started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Basic LaTeX References 42.1 Online Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 Additional Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.3 Creating a Basic LaTeX Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Basic Figures 6

4 Lists 7

5 Tables 9

6 Labels 10

7 Bonus 10

1

2

1 Overview and Objectives

This lab provides an introduction to using lists, figures, and tables.

1.1 Objectives

When finished with this lab, you will have completed the following objectives:

• code a basic LaTeX document using provided templates including

– include and resize figures

– create itemized, enumerated, and descriptive lists

– create a basic table

– label and reference the above

1.2 Deliverables

You will complete the following deliverables at the completion of this lab:

1. produce a LaTeX-based document using the provided templates and references.

1.3 What you will need to get started

You will need a machine that has:

• Emacs as a text editor.

• The pdflatex compiler installed. In this lab, we assume the compiler is the executablepdflatex.

3

2 Basic LaTeX References

This section is provided for your easy of reference only. You may proceed to the next section.

2.1 Online Documentation

Some basics for LaTeX documents maybe found at the following links:

1. https://en.wikibooks.org/wiki/LaTeX/

2. http://latex.wikia.com/wiki/Main_Page

3. https://www.sharelatex.com/

Additionally, you may find the following book helpful for more advanced concepts:

• Tex Unbound: Latex & Tex Strategies for Fonts, Graphics, & More: LaTex and TeX Strategiesfor Fonts, Graphics, and More by Alan Hoenig (1998-01-01); Publisher: Oxford UniversityPress USA; ASIN: B01K0SZJOS.

2.2 Additional Documentation

Some additional references that are recommended are found below.

LaTeX Quick Reference http://oceanai.mit.edu/k_w/latex_lab/refs/latex.pdf

LaTeX Cheat Sheet http://oceanai.mit.edu/k_w/latex_lab/refs/latexsheet.pdf

Auctex Reference Card http://oceanai.mit.edu/k_w/latex_lab/refs/auctex.pdf

Auctex Manual https://www.gnu.org/s/auctex/manual/auctex.pdf

2.3 Creating a Basic LaTeX Document

Complete the following steps to create, edit, compile, and open a basic LaTeX document.

1. create a new file (myfile.tex) using emacs

2. edit the file and insert the basic LaTeX document structure. Save the file frequently.

Listing 1: LaTeX File Structure.

0 \documentclass[onecolumn,letterpaper,11pt]{article}

1 % Insert any packages, environments, counters, etc. here

2 \begin{document}

3 % Insert your document contents here

4 Hello world!

5 \end{document}

3. compile the LaTeX document (command line sequence, makefile, then using Auctex shortcuts)

4

(a) compile from the console using a file named myfile.tex

$$ pdflatex myfile; pdflatex myfile

(b) compile and open from the console for a makefile named ”makefile”

$$ make pdfo

Listing 2: Example LaTex makefile (named ”makefile”).

.SILENT:

.PHONY : all clean

LATEX = pdflatex

PAPER = myfile #name of main file without ‘‘.tex’’

main: $(PNGFILES)

$(LATEX) $(PAPER)

bibtex $(PAPER) # if using a bibliography

$(LATEX) $(PAPER)

pdfo: main # opens paper after compiling

open $(PAPER).pdf &

pdfoq: # opens paper after single compile

$(LATEX) $(PAPER)

open $(PAPER).pdf &

pdfv: # only opens paper

open $(PAPER).pdf &

clean: # cleans files made while compiling

rm -f $(PAPER).dvi *~ $(PAPER).log $(PAPER).pdf $(PAPER

).ind

rm -f $(PAPER).bbl $(PAPER).blg $(PAPER).ps $(PAPER).aux

rm -f $(PNGFILES) $(PAPER).toc $(PAPER).idx $(PAPER).ilg

rm -f $(LDIR)*.bak $(LDIR)*~ $(PAPER).adx $(PAPER).and

rm -f $(PAPER).out $(PAPER).lot $(PAPER).lof

(c) from the emacs editor with Auctex installed (Section ??), use either of the followingshortcuts:

C+c C+c <RETURN> (<- this compiles; note, will need to run multiple times)

# OR #

C+c C+a <RETURN> (<- this compiles and opens)

4. open the resulting PDF (tip: keeping the PDF file open next to your editor allows for quicklyviewing changes after each compile. Most editors will refresh with the current view andlocation of the document. If using Mac, consider using the Skim PDF viewer if Previewreturns you to the beginning of the document after each compilation.)

5

3 Basic Figures

In LaTeX, pictures and images are called figures. These are often created using some other programand simply referenced by your tex file. The figures you reference are placed using the compiler’s bestestimate of positioning that is aesthetically pleasing, though there are several highly configurableparameters if you so choose to tweak the appearance.

We will need to ensure the following packages are included in your document header. You may alsofind other packages that you prefer or require depending on the type of images you are working withor how you want them presented. For example, it may be easier to use the packages “sidewaysfigure”rather than trying to rotate and size an image manually.

Listing 3: Adding Graphics Packages.

\usepackage{graphics,graphicx} % for pdf, bitmapped graphics files

The most basic placement of a figure may appear like this and take the following form:

Figure 1: This is the caption appearing adjacent to the images. The “TOC Entry Here” between the brackets isoptional and is what will be displayed in the table of contents (if used).

Listing 4: Example Figure Placement.

\begin{figure}[h] % t - top, b - bottom, h - here

\centering % center the figure inside the space you create

% now insert the file and specify its width

\includegraphics[width=0.49\textwidth]{figures/latexlogo2-Cropped-528x193.jpg}

\caption[TOC Entry Here]{This is the caption appearing adjacent to the images.

The ‘‘TOC Entry Here’’ between the brackets is optional and is what will be

displayed in the table of contents (if used).

}

\label{fig:latexlogo}

\end{figure}

It is common practice to have a folder (or folder tree) for figures. In the example above, the

6

images was foudn in the folder “figures”. Note that just like we labeled and referenced sections andequations, we can label and reference figures. As with equations and sections, figure numbers use acounter just for figures. We just created Figure 1.

Using any image of your choice, place a figure with a caption between two paragraphs of text.

Exercise:http://oceanai.mit.edu/k_w/latex_lab/lab_4_exercise_figure.pdf

Solution:http://oceanai.mit.edu/k_w/latex_lab/lab_4_exercise_figure.tex

Now recreate the following document using the “graphicx” package and the image file “figures/latexlogo2-Cropped-528x193.jpg”.

Exercise:http://oceanai.mit.edu/k_w/latex_lab/lab_4_exercise_figure_styles.pdf

Solution:http://oceanai.mit.edu/k_w/latex_lab/lab_4_exercise_figure_styles.tex

4 Lists

Lists provide a way to present data in a concise, ordered, and thoughtful way. There are three basictypes of lists: enumerated, itemized, and descriptive. Enumerated lists use numbers or letters forbullets. Itemized lists use a constant symbol (usually a bullet). Descriptive lists use a user-specifieddescription (normally a single word) inside brackets for each “bullet” or line.

For the following three in-line exercises, recreate the given lists. The solutions are given in theblocks that follow.

Your listed information starts here:

1. the information inside the begin and end braces tells LaTex the type of list

2. try “enumerate” for numbered lists

3. try “itemize” for bullets

4. try “description” for labeled lists with \item[descriptionname] list content

Listing 5: Making Lists.

Your listed information starts here:

\begin{enumerate}

\item the information inside the begin and end braces tells LaTex the type of list

\item try ‘‘enumerate’’ for numbered lists

\item try ‘‘itemize’’ for bullets

\item try ‘‘description’’ for labeled lists with \item[descriptionname] list content

\end{enumerate}

7

Your listed information starts here:

• the information inside the begin and end braces tells LaTex the type of list

• try “enumerate” for numbered lists

• try “itemize” for bullets

• try “description” for labeled lists with \item[descriptionname] list content

Listing 6: Making Lists.

Your listed information starts here:

\begin{itemize}

\item the information inside the begin and end braces tells LaTex the type of list

\item try ‘‘enumerate’’ for numbered lists

\item try ‘‘itemize’’ for bullets

\item try ‘‘description’’ for labeled lists with \item[descriptionname] list content

\end{itemize}

Your listed information starts here:

info the information inside the begin and end braces tells LaTex the type of list

enumerate try “enumerate” for numbered lists

itemize try “itemize” for bullets

description try “description” for labeled lists with \item[descriptionname] list content

Listing 7: Making Lists.

Your listed information starts here:

\begin{description}

\item [info]the information inside the begin and end braces tells LaTex the type of list

\item [enumerate]try ‘‘enumerate’’ for numbered lists

\item [itemize]try ‘‘itemize’’ for bullets

\item [description]try ‘‘description’’ for labeled lists with

\textbackslash item[descriptionname] list content

\end{description}

Now recreate the following list.

Exercise:http://oceanai.mit.edu/k_w/latex_lab//lab_4_exercise_nested_lists.pdf

Solution:http://oceanai.mit.edu/k_w/latex_lab//lab_4_exercise_nested_lists.tex

8

5 Tables

We will use the basic package “booktabs” to make a table that is formatted with a caption, label,and horizontal dividing lines. Insert horizontal lines using toprule, midrule, and bottomrule. Theletters on the \begin {tabular} line are one per column and take the value of the alignment of thatcolumn. Placing a vertical line “|” (sometimes called a pipe symbol) between letters will add avertical line between those columns. Use the & symbol to move to the next column and a doublebackslash to move to the next row. See the following example. Like figures, the table is placed onthe page according to the position you give it: h = here, b = bottom, and t = top. A “p” may beused to place the table (or figure) on the next page of float. This means that it will appear on thenext page of only figures/tables/etc. An “!” may be used to “insist” on the placement you giveit even to LaTeX’s displeasure. The “!” will ignore certain other restrictions for placement (e.g.,number of floats on a page; maximum size of bottom floats, etc.).

Table 1: Summary of Equations

Number Full Equation

1 x = a2 x = b2

3 x = c + d

Listing 8: Making Tables.

\begin{table}[h] % position on page: h - here, b - bottom, t - top

\centering %center with respect to page

\caption{Summary of Equations}

\begin{tabular}{cc} % column alignment: c - center, r - right, l - left

% go to next column with a "&"

\toprule % think line for the top

Number & Full Equation \\

\midrule % thin line in the middle

1 & $x = a$ \\

2 & $x = b^2$ \\

3 & $x = c + d $\\

\bottomrule % thick line at bottom

\end{tabular}%

\label{tab:example}%

\end{table}%

\end{description}

Recreate the following table.

Exercise:http://oceanai.mit.edu/k_w/latex_lab/lab_4_exercise_table.pdf

Solution:http://oceanai.mit.edu/k_w/latex_lab/lab_4_exercise_table.tex

9

6 Labels

Labels with figures and tables work the same way as they did for sections and equations. Thecounters for figures and tables start back at the beginning of the document and increment for eachfigure or table that the compiler finds (unless it is marked with an asterisk). We reference labels forfigures and tables in the same manner as we did sections (“\ref”). As before, we should immediatelyprecede the “ref” with a tilde to prevent a line break the referenced number being by itself on thenext line.

7 Bonus

Bonus: Reconstruct the following document.

Exercise:http://oceanai.mit.edu/k_w/latex_lab/lab_4_exercise_bonus.pdf

Solution:http://oceanai.mit.edu/k_w/latex_lab/lab_4_exercise_bonus.tex

10