84
Advanced LaTeX Aubry Verret October 22, 2013

Advanced latex

Embed Size (px)

DESCRIPTION

Contains a variety of topics that might be of interest to someone who uses LaTeX frequently including minipages, tables, and Beamer.

Citation preview

Page 1: Advanced latex

Advanced LaTeX

Aubry Verret

October 22, 2013

Page 2: Advanced latex

Macros

Definition

A shorthand command used to abbreviate anothercommand or series of commands.

Fact: LATEX is comprised of numerous macros builton the TEX language.

Page 3: Advanced latex

How to write a Macro

Define a macro in the Preamble using:

\newcommand{command name}{definition}

Example:

\newcommand{\uva}{University of Virginia}

Whenever you want ”University of Virginia” to appear you usethe \uva command.

Page 4: Advanced latex

How to write a Macro

Define a macro in the Preamble using:

\newcommand{command name}{definition}

Example:

\newcommand{\uva}{University of Virginia}

Whenever you want ”University of Virginia” to appear you usethe \uva command.

Page 5: Advanced latex

How to write a Macro

Define a macro in the Preamble using:

\newcommand{command name}{definition}

Example:

\newcommand{\uva}{University of Virginia}

Whenever you want ”University of Virginia” to appear you usethe \uva command.

Page 6: Advanced latex

Macros with Arguments

Specify the number of arguments in square braces:

\newcommand{command name}[# args]{definition}

Refer to the arguments as #1, #2, #3, #4 etc. in thedefinition.

Example:

\newcommand{\shout}[1]{{\Huge{\bf {#1}}}

Pay Attention!\shout{Pay Attention!}

Page 7: Advanced latex

Macros with Arguments

Specify the number of arguments in square braces:

\newcommand{command name}[# args]{definition}

Refer to the arguments as #1, #2, #3, #4 etc. in thedefinition.

Example:

\newcommand{\shout}[1]{{\Huge{\bf {#1}}}

Pay Attention!\shout{Pay Attention!}

Page 8: Advanced latex

Macros with Arguments

Specify the number of arguments in square braces:

\newcommand{command name}[# args]{definition}

Refer to the arguments as #1, #2, #3, #4 etc. in thedefinition.

Example:

\newcommand{\shout}[1]{{\Huge{\bf {#1}}}

Pay Attention!

\shout{Pay Attention!}

Page 9: Advanced latex

Macros with Arguments

Specify the number of arguments in square braces:

\newcommand{command name}[# args]{definition}

Refer to the arguments as #1, #2, #3, #4 etc. in thedefinition.

Example:

\newcommand{\shout}[1]{{\Huge{\bf {#1}}}

Pay Attention!\shout{Pay Attention!}

Page 10: Advanced latex

Macros with Math

$$\sum_{i=0}^n i^n$$

n∑i=0

in

\newcommand{sums}{$$\sum {i=0}ˆn iˆn$$}

\sums

\newcommand{sums}[1]{$$\sum {i=0}ˆ#1 iˆ#1$$}

\sums{5}5∑

i=0

i5

Page 11: Advanced latex

Macros with Math

$$\sum_{i=0}^n i^n$$

n∑i=0

in

\newcommand{sums}{$$\sum {i=0}ˆn iˆn$$}

\sums

\newcommand{sums}[1]{$$\sum {i=0}ˆ#1 iˆ#1$$}

\sums{5}5∑

i=0

i5

Page 12: Advanced latex

Macros with Math

$$\sum_{i=0}^n i^n$$

n∑i=0

in

\newcommand{sums}{$$\sum {i=0}ˆn iˆn$$}

\sums

\newcommand{sums}[1]{$$\sum {i=0}ˆ#1 iˆ#1$$}

\sums{5}5∑

i=0

i5

Page 13: Advanced latex

Renewcommand

Use \renewcommand to redefine an existing command

Example:

The \emph command italicizes its input.

Suppose you want to use it instead of the shout command:

\renewcommand{\emph}[1]{{\Huge{\bf {#1}}}

\emph{Pay Attention!}

Pay Attention!

Page 14: Advanced latex

Renewcommand

Use \renewcommand to redefine an existing command

Example:

The \emph command italicizes its input.

Suppose you want to use it instead of the shout command:

\renewcommand{\emph}[1]{{\Huge{\bf {#1}}}

\emph{Pay Attention!}

Pay Attention!

Page 15: Advanced latex

Renewcommand

Use \renewcommand to redefine an existing command

Example:

The \emph command italicizes its input.

Suppose you want to use it instead of the shout command:

\renewcommand{\emph}[1]{{\Huge{\bf {#1}}}

\emph{Pay Attention!}

Pay Attention!

Page 16: Advanced latex

Renewcommand

Use \renewcommand to redefine an existing command

Example:

The \emph command italicizes its input.

Suppose you want to use it instead of the shout command:

\renewcommand{\emph}[1]{{\Huge{\bf {#1}}}

\emph{Pay Attention!}

Pay Attention!

Page 17: Advanced latex

Renewcommand

Use \renewcommand to redefine an existing command

Example:

The \emph command italicizes its input.

Suppose you want to use it instead of the shout command:

\renewcommand{\emph}[1]{{\Huge{\bf {#1}}}

\emph{Pay Attention!}

Pay Attention!

Page 18: Advanced latex

PerlTeX

PerlTeX allows you to define macros using the Perl programminglanguage

Download:

http://www.ctan.org/tex-archive/macros/latex/contrib/

perltex/

User Manual:http:

//www.tug.org/TUGboat/Articles/tb25-2/tb81pakin.pdf

Page 19: Advanced latex

Ams-LaTeX

Ams-LaTeX is a collection of extensions for LATEX in the form ofdocument classes and packages designed to enhance thetypesetting of mathematics.

The Amsmath package is an extension of AMS-LaTeX thatprovides:

I Superior equation formatting

I Support for multiline equations

I Support for better equation numbering

I Auxilliary packages that provide additional support fordisplayed equations

Page 20: Advanced latex

Additional Packages

The Amsthm package provides extensions to theLATEX \newtheorem command which include:

I Various theorem styles

I More control over numbering

I A proof environment

The Amssymb package provides additional fonts and symbols:

Page 21: Advanced latex

Additional Packages

The Amsthm package provides extensions to theLATEX \newtheorem command which include:

I Various theorem styles

I More control over numbering

I A proof environment

The Amssymb package provides additional fonts and symbols:

Page 22: Advanced latex

Additional Packages

The Amsthm package provides extensions to theLATEX \newtheorem command which include:

I Various theorem styles

I More control over numbering

I A proof environment

The Amssymb package provides additional fonts and symbols:

Page 23: Advanced latex

Amsmath Equation Environments - Align 1

\begin{align}

x^2 + y^2 & = z^2 \nonumber \\

x^3 + y^3 & < z^3

\end{align}

x2 + y2 = z2

x3 + y3 < z3 (1)

Facts:

I Better spacing than the LATEX eqnarray environment

I Use the ”∗” to suppress numbering - \begin{array∗}I Use \nonumber to suppress numbering of individual equations

1This and all following Amsmath slides adapted fromhttp://www.icms.org.uk/downloads/pgcourses/15october/Zachary.pdf

Page 24: Advanced latex

Amsmath Equation Environments - Multline

\begin{multline}

\lim_{x\to\infty}\frac{P(M>x)}{\overline{F^s}(x)} \\

\le \limsup_{x\to\infty}

\frac{P(M>x,\,S_{\tau_1}>x-R+a-\epsilon)}%

{\overline{F^s}(x)} \\

+\gamma

\left(\frac{2-\gamma}{(a-\epsilon)(1-\gamma)^2}\right)

\end{multline}

limx→∞

P(M > x)

F s(x)

≤ lim supx→∞

P(M > x , Sτ1 > x − R + a− ε)F s(x)

+ γ

(2− γ

(a− ε)(1− γ)2

)(2)

Page 25: Advanced latex

Amsmath Equation Environments - Cases

\begin{equation*}

I_A =

\begin{cases}

1 & \text{if $x\in A$}\\

0 & \text{otherwise}

\end{cases}

\end{equation*}

IA =

{1 if x ∈ A

0 otherwise

Page 26: Advanced latex

More Environments

I Equation - single equation on a single line

I Gather - multiple equations with no alignment

I Flalign - horizontally spread version of align

I Split - split single equations with alignment

\begin{equation}

\begin{split}

(a + b)^3 &= (a + b) (a + b)^2 \\

&= (a + b)(a^2 + 2ab + b^2) \\

&= a^3 + 3a^2b + 3ab^2 + b^3

\end{split}

\end{equation}

(a + b)3 = (a + b)(a + b)2

= (a + b)(a2 + 2ab + b2)

= a3 + 3a2b + 3ab2 + b3(3)

Page 27: Advanced latex

Matrix Environments

\begin{equation}

\begin{matrix}

1 & 0 \\

0 & 1

\end{matrix}

\end{equation}

1 00 1

(4)

Page 28: Advanced latex

More Matrix Environments

I pmatrix (1 00 1

)(5)

I bmatrix [1 00 1

](6)

I Bmatrix {1 00 1

}(7)

I vmatrix ∣∣∣∣1 00 1

∣∣∣∣ (8)

I Vmatrix ∥∥∥∥1 00 1

∥∥∥∥ (9)

Page 29: Advanced latex

AMS-LaTeX Assistance

For info on AMS-LaTeX:

http://www.ams.org/tex/amslatex.html

For info on the Amsmath package:

ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf

For info on Amsthm:

ftp://ftp.ams.org/pub/tex/doc/amscls/amsthdoc.pdf

Page 30: Advanced latex

Headers and Footers

Fancyhdr package creates customizable headers andfooters:

\ d o c u m e n t c l a s s { a r t i c l e }\ u s e p a c k a g e { f a n c y h d r }\ p a g e s t y l e { f a n c y p l a i n }

\ b e g i n {document}

\ l h e a d {Aubry W. V e r r e t }\ r h e a d {\ today }

\end{document}

Page 31: Advanced latex

Headers and Footers

Fancyhdr package creates customizable headers andfooters:

\ d o c u m e n t c l a s s { a r t i c l e }\ u s e p a c k a g e { f a n c y h d r }\ p a g e s t y l e { f a n c y p l a i n }

\ b e g i n {document}

\ l h e a d {Aubry W. V e r r e t }\ r h e a d {\ today }

\end{document}

Page 32: Advanced latex

Fancyhdr Output

Page 33: Advanced latex

Fancyhdr Help

You can get assistance with Fancyhdr here:

ftp://ctan.tug.org/tex-archive/macros/latex/

contrib/fancyhdr/fancyhdr.pdf

Page 34: Advanced latex

Minipages

The Minipage environment creates miniature pages withinpages.

\begin{minipage}...\end{minipage}

It is suitable for:

I Grouping figures or tables

I Placement of footnotes attached to images

I Placing a border around a figure and its title

Page 35: Advanced latex

Minipage example

\ b e g i n { f i g u r e } [ htbp ]\ center ing\ b e g i n {min ipage } [ b ]{5 cm}\ center ing\ i n c l u d e g r a p h i c s { image 1}\ c a p t i o n {Capt ion 1}

\end{min ipage }\ b e g i n {min ipage } [ b ]{5 cm}\ center ing\ i n c l u d e g r a p h i c s { image 2}\ c a p t i o n {Capt ion 2}

\end{min ipage }\end{ f i g u r e }

Page 36: Advanced latex

Output

Figure: Science Cat Figure: Physics Cat

Page 37: Advanced latex

Minipage Example Two\ b e g i n { f i g u r e } [ htbp ]\ center ing\ b e g i n {min ipage } [ b ] { 3 . 3 cm}\ center ing\ i n c l u d e g r a p h i c s [ s c a l e =.14]{ g r a p h i c s / s c i e n c e c a t }\ c a p t i o n { S c i e n c e Cat}

\end{min ipage }\ b e g i n {min ipage } [ b ] { 3 . 3 cm}\ center ing\ i n c l u d e g r a p h i c s [ s c a l e =.23]{ g r a p h i c s / p h y s i c s c a t }\ c a p t i o n { P h y s i c s Cat}

\end{min ipage }\ b e g i n {min ipage } [ b ] { 3 . 3 cm}\ center ing\ i n c l u d e g r a p h i c s [ s c a l e =.14]{ g r a p h i c s / s c i e n c e c a t }\ c a p t i o n { S c i e n c e Cat}

\end{min ipage }\ b e g i n {min ipage } [ b ] { 3 . 3 cm}\ center ing\ i n c l u d e g r a p h i c s [ s c a l e =.23]{ g r a p h i c s / p h y s i c s c a t }\ c a p t i o n { P h y s i c s Cat}

\end{min ipage }\end{ f i g u r e }

Page 38: Advanced latex

Figure: Science Cat Figure: Physics Cat

Figure: Science Cat Figure: Physics Cat

Page 39: Advanced latex

Fonts

Default Font: Computer modern

Default font size: 10pt

How to change the default font:

I Additional fonts are available for installation(http://www.tug.dk/FontCatalogue/)

How to change the default font size:

I \documentclass command accepts [11pt] and [12pt] as options

I fix-cm package overrides font size defaults

I special commands

Page 40: Advanced latex

Fonts

Default Font: Computer modern

Default font size: 10pt

How to change the default font:

I Additional fonts are available for installation(http://www.tug.dk/FontCatalogue/)

How to change the default font size:

I \documentclass command accepts [11pt] and [12pt] as options

I fix-cm package overrides font size defaults

I special commands

Page 41: Advanced latex

Font Size Commands

\tiny(5pt)

\scriptsize(7pt)

\footnotesize(8pt)

\small(9pt)

\normalsize(10pt)

\large(12pt)

\Large(14pt)

\LARGE(18pt)

\huge(20pt)\Huge(24pt)

Page 42: Advanced latex

Colored text

Use the xcolor package to add color to your text:

\usepackage{xcolor}

Use {\color{color name} text} to change the text color.

Predefined colors include:

black, white, red, yellow, blue, green, cyan, magenta

Page 43: Advanced latex

Example

{\color{red} This text is red!}

This text is red!

Page 44: Advanced latex

Colored Text Background

\colorbox{yellow}{This text has a yellow background!}

This text has a yellow background!

Page 45: Advanced latex

More Colors!

Use the [dvipsnames] option when you call the colorenvironment:

\usepackage[dvipsnames]{xcolor}

You can now access 68 more colors!

Page 46: Advanced latex

New Colors

Page 47: Advanced latex

Wrap figure

To wrap text around a figure use the Wrapfig package:

\usepackage{wrapfig}

Wrap the figure in the wrapfigure environment:

\begin{wrapfigure}{alignment}{width}...\end{wrapfigure}

alignment Either l (left) or r (right)

width Width of image

Page 48: Advanced latex

Wrapfig Example

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullamporttitor rutrum felis eget faucibus. Aliquam erat volutpat. Duiscommodo, libero nec adipiscing pellentesque, risus velit faucibusaugue, eget molestie nibh risus et augue.

\ b e g i n {w r a p f i g u r e }{ l }{40mm}\ b e g i n { c e n t e r }\ i n c l u d e g r a p h i c s { f a r s i d e }

\end{ c e n t e r }\ c a p t i o n { E i n s t e i n }

\end{w r a p f i g u r e }

Integer quis tristique est. Pellentesque lacinia mi mattis ipsumrutrum egestas. Aliquam vestibulum pharetra felis, in congue erosposuere ac.

Page 49: Advanced latex

Output

Page 50: Advanced latex

Compiling multiple .tex files

As your tex file grows, you may find that it becomes more difficultto manage (compiling starts to take a long time, it gets hard tofind things, bugs are harder to find, etc.)

The solution: write several files sepearately and compile themtoether at the end. Use the \input command to read each “child”file into your “root” document...

\input{child1.tex}

\input{child2.tex}

\input{child3.tex}

Page 51: Advanced latex

Compiling multiple .tex filesThe problem with \input is that the “child” files won’t compile ontheir own. The solution is in the subfile package.In the ”root” document the package must be loaded as:

\usepackage{subfiles}

Instead of using \input, ”child” documents must be loaded asfollows:

\subfile{child}

The ”child” documents must start with the following statements:

\documentclass[rootdocument.tex]{subfiles}

\begin{document}

and end with:

\end{document}

Page 52: Advanced latex

Alternate Output

LATEX can directly generate two formats:

dvi Generate using the latex command

pdf Generate using the pdflatex command

dvi supports only the eps image format

pdf supports jpg, png, pdf image formats

Page 53: Advanced latex

Converting from DVI to PDF

Directly (dvi → pdf):

Use dvipdfm.

There is a special button for this in most LATEXeditors.

I Use this if the original file contains postscript figures

Indirectly (dvi → ps → pdf):

Use dvips, then sp2pdf

I typically ineffecient and can produce larger files of lowerquality

Page 54: Advanced latex

Converting from DVI to PDF

Directly (dvi → pdf):

Use dvipdfm.

There is a special button for this in most LATEXeditors.

I Use this if the original file contains postscript figures

Indirectly (dvi → ps → pdf):

Use dvips, then sp2pdf

I typically ineffecient and can produce larger files of lowerquality

Page 55: Advanced latex

Converting from DVI to PDF

Directly (dvi → pdf):

Use dvipdfm.

There is a special button for this in most LATEXeditors.

I Use this if the original file contains postscript figures

Indirectly (dvi → ps → pdf):

Use dvips, then sp2pdf

I typically ineffecient and can produce larger files of lowerquality

Page 56: Advanced latex

Converting from DVI to PDF

Directly (dvi → pdf):

Use dvipdfm.

There is a special button for this in most LATEXeditors.

I Use this if the original file contains postscript figures

Indirectly (dvi → ps → pdf):

Use dvips, then sp2pdf

I typically ineffecient and can produce larger files of lowerquality

Page 57: Advanced latex

HTML output

There are several programs for converting LATEX to HTML:

Hyperlatex Actively maintained to keep up with HTMLstandards

TTH Good at formula conversion

Heava Good overall, written in O Caml

LaTeX2HTML Not well maintained

text4ht Difficult to configure but produces good output

Page 58: Advanced latex

Beamer

It is possible to create sophisticated presentations whileharnessing the power of LATEX

The Beamer class produces presentations that:

I Can be easily cutomized

I Contain overlays

I Can display sophisitcated mathematics

I Are easily converted to handouts

I Compile directly to PDF

Page 59: Advanced latex

How to Use Beamer

Use beamer as the document class:

\documentclass[style]{beamer}

Go here for examples of Beamer styles:

http://mike.depalatis.net/beamerthemes/

Page 60: Advanced latex

Frames

Beamer uses the Frame environment:

\begin{frame}[options]...\end{frame}

Options include:

I fragile allows you to include text using the verbatim orlistings packages on a slide

I allowframebreaks allows Beamer to create extra slides tohandle overflow text

I shrink shrinks contents to fit on one slide

Page 61: Advanced latex

Frames

Beamer uses the Frame environment:

\begin{frame}[options]...\end{frame}

Options include:

I fragile allows you to include text using the verbatim orlistings packages on a slide

I allowframebreaks allows Beamer to create extra slides tohandle overflow text

I shrink shrinks contents to fit on one slide

Page 62: Advanced latex

Example of Frame

Page 63: Advanced latex

How to Make A Table

To make a table in LATEX use the tabular environment:

\begin{tabular}...\end{tabular}

Separate columns with the ”&” symbol

Separate rows with the double backslash ”\\”

Page 64: Advanced latex

How to Make A Table

To make a table in LATEX use the tabular environment:

\begin{tabular}...\end{tabular}

Separate columns with the ”&” symbol

Separate rows with the double backslash ”\\”

Page 65: Advanced latex

Tabular Layout

Specify the column layout when you call tabular:

\begin{tabular}{l|l|l}

Vertical bars produce vertical lines between columns.

Alignment Symbols

I l - align left

I r - align right

I c - centered

Page 66: Advanced latex

Tables

\begin{tabular}{ l | l | l }

Class & Species & Lays eggs? \\

mammal & lion & \XSolidBrush \\

mammal & tiger & \XSolidBrush \\

mammal & platypus & \Checkmark \\

reptile & iguana & \Checkmark \\

reptile & snake & \Checkmark \\

aves & flamingo & \Checkmark \\

\end{tabular}

Class Species Lays eggs?

mammal lion %

mammal tiger %

mammal platypus !

reptile iguana !

reptile snake !

aves flamingo !

Page 67: Advanced latex

TablesChange alignments:

\begin{tabular}{| l | r | c | }

Class & Species & Lays eggs? \\

mammal & lion & \XSolidBrush \\

mammal & tiger & \XSolidBrush \\

mammal & platypus & \Checkmark \\

reptile & iguana & \Checkmark \\

reptile & snake & \Checkmark \\

aves & flamingo & \Checkmark \\

\end{tabular}

Class Species Lays eggs?

mammal lion %

mammal tiger %

mammal platypus !

reptile iguana !

reptile snake !

aves flamingo !

Page 68: Advanced latex

TablesAdd horizontal lines:

\begin{tabular}{| l | r | c | } \hline

Class & Species & Lays eggs? \\ \hline\hline

mammal & lion & \XSolidBrush \\ \hline

mammal & tiger & \XSolidBrush \\ \hline

mammal & platypus & \Checkmark \\ \hline

reptile & iguana & \Checkmark \\ \hline

reptile & snake & \Checkmark \\ \hline

aves & flamingo & \Checkmark \\ \hline

\end{tabular}

Class Species Lays eggs?

mammal lion %

mammal tiger %

mammal platypus !

reptile iguana !

reptile snake !

aves flamingo !

Page 69: Advanced latex

TablesNot so many:

\begin{tabular}{| l | r | c | } \hline

Class & Species & Lays eggs? \\ \hline\hline

mammal & lion & \XSolidBrush \\

& tiger & \XSolidBrush \\

& platypus & \Checkmark \\ \hline

reptile & iguana & \Checkmark \\

& snake & \Checkmark \\ \hline

aves & flamingo & \Checkmark \\ \hline

\end{tabular}

Class Species Lays eggs?

mammal lion %

tiger %

platypus !

reptile iguana !

snake !

aves flamingo !

Page 70: Advanced latex

TablesPartial hlines

\begin{tabular}{| l | r | c | } \hline

Class & Species & Lays eggs? \\ \hline\hline

mammal & lion & \XSolidBrush \\ \cline{2-3}

& tiger & \XSolidBrush \\ \cline{2-3}

& platypus & \Checkmark \\ \hline

reptile & iguana & \Checkmark \\ \cline{2-3}

& snake & \Checkmark \\ \hline

aves & flamingo & \Checkmark \\ \hline

\end{tabular}

Class Species Lays eggs?

mammal lion %

tiger %

platypus !

reptile iguana !

snake !

aves flamingo !

Page 71: Advanced latex

TablesMultirow

\begin{tabular}{| l | r | c | } \hline

Class & Species & Lays eggs? \\ \hline\hline

\multirow{3}{*}{mammal} & lion & \XSolidBrush \\ \cline{2-3}

& tiger & \XSolidBrush \\ \cline{2-3}

& platypus & \Checkmark \\ \hline

\multirow{2}{*}{reptile} & iguana & \Checkmark \\ \cline{2-3}

& snake & \Checkmark \\ \hline

aves & flamingo & \Checkmark \\ \hline

\end{tabular}

Class Species Lays eggs?

mammallion %

tiger %

platypus !

reptileiguana !

snake !

aves flamingo !

Page 72: Advanced latex

TablesColor (colortbl package)

\begin{tabular}{| l | r | c | } \hline

\rowcolor[gray]{0.8} Class & Species & Lays eggs? \\ \hline\hline

\multirow{3}{*}{mammal} & lion & \XSolidBrush \\ \cline{2-3}

& tiger & \XSolidBrush \\ \cline{2-3}

& platypus & \Checkmark \\ \hline

\multirow{2}{*}{reptile} & iguana & \Checkmark \\ \cline{2-3}

& snake & \Checkmark \\ \hline

aves & flamingo & \Checkmark \\ \hline

\end{tabular}

Class Species Lays eggs?

mammallion %

tiger %

platypus !

reptileiguana !

snake !

aves flamingo !

Page 73: Advanced latex

Tables

Better horizontal lines: booktabs package

\begin{tabular}{lrc} \toprule

Class & Species & Lays eggs? \\ \toprule

\multirow{3}{*}{mammal} & lion & \XSolidBrush \\ \cmidrule{2-3}

& tiger & \XSolidBrush \\ \cmidrule{2-3}

& platypus & \Checkmark \\ \midrule

\multirow{2}{*}{reptile}& iguana& \Checkmark \\ \cmidrule{2-3}

& snake & \Checkmark \\ \midrule

aves & flamingo& \Checkmark \\ \bottomrule

\end{tabular}

Page 74: Advanced latex

Tables

Better horizontal lines: booktabs package

Class Species Lays eggs?

mammallion %

tiger %

platypus !

reptileiguana !

snake !

aves flamingo !

Page 75: Advanced latex

Tables

The table enviroment:

\begin{table} ... \end{table}

allows you to:

I Turn a table into a float

I Add a caption

I Number the table for referencing

Page 76: Advanced latex

Tables

table environment

Table: Who lays eggs?

Class Species Lays eggs?

mammallion %

tiger %

platypus !

reptileiguana !

snake !

aves flamingo !

Page 77: Advanced latex

Tables

Formatting Numbers

\begin{tabular}{c r}

Expression & Value \\ \hline

$\pi$ & 3.1416 \\ \hline

$\pi^{\pi}$ & 36.46 \\ \hline

$\pi^{\pi^{\pi}}$ & 80662.7 \\ \hline

\end{tabular}

Expression Valueπ 3.1416ππ 36.46

πππ

80662.7

Page 78: Advanced latex

Tables

One fix:

\begin{tabular}{c r @{.} l}

Expression & \multicolumn {2}{c}{Value} \\ \hline

$\pi$ & 3 & 1416 \\ \hline

$\pi^{\pi}$ & 36 & 46 \\ \hline

$\pi^{\pi^{\pi}}$ & 80662 & 7 \\ \hline

\end{tabular}

Expression Valueπ 3.1416ππ 36.46

πππ

80662.7

Page 79: Advanced latex

Tables

Another Fix (dcolumn package)

\begin{tabular}{cD{,}{.}{5.4}}

Expression & \multicolumn {1}{c}{Value} \\ \hline

$\pi$ & 3,1416 \\ \hline

$\pi^{\pi}$ & 36,46 \\ \hline

$\pi^{\pi^{\pi}}$ & 80662,7 \\ \hline

\end{tabular}

Expression Valueπ 3.1416ππ 36.46

πππ

80662.7

Page 80: Advanced latex

Tables

Another Fix (rccol package)

\begin{tabular}{cR[,][.]{5}{3}}

Expression & \multicolumn {1}{c}{Value} \\ \hline

$\pi$ & 3,1416 \\ \hline

$\pi^{\pi}$ & 36,46 \\ \hline

$\pi^{\pi^{\pi}}$ & 80662,7 \\ \hline

\end{tabular}

Expression Valueπ 3.142ππ 36.460

πππ

80662.700

Page 81: Advanced latex

Tables

Slashed Boxes (slashbox package)

\begin{tabular}{|l|>{$}c<{$}|>{$}c<{$}|} \hline

\backslashbox{Function}{Argument} & 0 & \pi/2 \\ \hline

$\sin$ & 0 & 1 \\ \hline

$\cos$ & 1 & 0 \\ \hline

\end{tabular}

````````````FunctionArgument

0 π/2

sin 0 1cos 1 0

Page 82: Advanced latex

Tables

Making tables look good...

D Pu σN5in test 1 285 lb 38.200 psi5in test 2 287 lb 38.27 psi5in test 3 230 lb 30.67 psi10in test 1 430 lb 248.67 psi10in test 2 433 lb 28.8 psi10in test 3 431 lb 28.7334 psi

Page 83: Advanced latex

Tables

...takes practice.

Table: Maximum load and nominal tension.

D Pu σN(in) (lbs) (psi)

5test 1 285 38.00test 2 287 38.27test 3 230 30.67

10test 1 430 28.67test 2 433 28.87test 3 431 28.73

Page 84: Advanced latex

Where To Get Help

I Books - LATEXConcisely by Adrian Johnstone

I Online - numerous manuals available

I Research Computing Lab -www2.lib.virginia.edu/brown/rescomp/

help/index.html