Upcoming SlideShare
×

878 views

Published on

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

Published in: Technology
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
878
On SlideShare
0
From Embeds
0
Number of Embeds
146
Actions
Shares
0
29
0
Likes
1
Embeds 0
No embeds

No notes for slide

1. 1. Advanced LaTeX Aubry Verret October 22, 2013
2. 2. Macros Deﬁnition A shorthand command used to abbreviate another command or series of commands. A Fact: LTEX is comprised of numerous macros built on the TEX language.
3. 3. How to write a Macro Deﬁne a macro in the Preamble using: newcommand{command name}{deﬁnition}
4. 4. How to write a Macro Deﬁne a macro in the Preamble using: newcommand{command name}{deﬁnition} Example: newcommand{uva}{University of Virginia}
5. 5. How to write a Macro Deﬁne a macro in the Preamble using: newcommand{command name}{deﬁnition} Example: newcommand{uva}{University of Virginia} Whenever you want ”University of Virginia” to appear you use the uva command.
6. 6. Macros with Arguments Specify the number of arguments in square braces: newcommand{command name}[# args]{deﬁnition} Refer to the arguments as #1, #2, #3, #4 etc. in the deﬁnition.
7. 7. Macros with Arguments Specify the number of arguments in square braces: newcommand{command name}[# args]{deﬁnition} Refer to the arguments as #1, #2, #3, #4 etc. in the deﬁnition. Example: newcommand{shout}[1]{{Huge{bf {#1}}}
8. 8. Macros with Arguments Specify the number of arguments in square braces: newcommand{command name}[# args]{deﬁnition} Refer to the arguments as #1, #2, #3, #4 etc. in the deﬁnition. Example: newcommand{shout}[1]{{Huge{bf {#1}}} Pay Attention!
9. 9. Macros with Arguments Specify the number of arguments in square braces: newcommand{command name}[# args]{deﬁnition} Refer to the arguments as #1, #2, #3, #4 etc. in the deﬁnition. Example: newcommand{shout}[1]{{Huge{bf {#1}}} Pay Attention! shout{Pay Attention!}
10. 10. Macros with Math \$\$sum_{i=0}^n i^n\$\$ n in i=0 newcommand{sums}{\$\$sum {i=0}ˆn iˆn\$\$}
11. 11. Macros with Math \$\$sum_{i=0}^n i^n\$\$ n in i=0 newcommand{sums}{\$\$sum {i=0}ˆn iˆn\$\$} sums
12. 12. Macros with Math \$\$sum_{i=0}^n i^n\$\$ n in i=0 newcommand{sums}{\$\$sum {i=0}ˆn iˆn\$\$} sums newcommand{sums}[1]{\$\$sum {i=0}ˆ#1 iˆ#1\$\$} sums{5} 5 i5 i=0
13. 13. Renewcommand Use renewcommand to redeﬁne an existing command
14. 14. Renewcommand Use renewcommand to redeﬁne an existing command Example: The emph command italicizes its input.
15. 15. Renewcommand Use renewcommand to redeﬁne 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}}}
16. 16. Renewcommand Use renewcommand to redeﬁne 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!}
17. 17. Renewcommand Use renewcommand to redeﬁne 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!
18. 18. PerlTeX PerlTeX allows you to deﬁne macros using the Perl programming language Download: http://www.ctan.org/tex-archive/macros/latex/contrib/ perltex/ User Manual: http: //www.tug.org/TUGboat/Articles/tb25-2/tb81pakin.pdf
19. 19. Ams-LaTeX A Ams-LaTeX is a collection of extensions for LTEX in the form of document classes and packages designed to enhance the typesetting of mathematics. The Amsmath package is an extension of AMS-LaTeX that provides: Superior equation formatting Support for multiline equations Support for better equation numbering Auxilliary packages that provide additional support for displayed equations
20. 20. Additional Packages The Amsthm package provides extensions to the A LTEX newtheorem command which include: Various theorem styles More control over numbering A proof environment
21. 21. Additional Packages The Amsthm package provides extensions to the A LTEX newtheorem command which include: Various theorem styles More control over numbering A proof environment The Amssymb package provides additional fonts and symbols:
22. 22. Additional Packages The Amsthm package provides extensions to the A LTEX newtheorem command which include: Various theorem styles More control over numbering A proof environment The Amssymb package provides additional fonts and symbols:
23. 23. 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: A Better spacing than the LTEX eqnarray environment Use the ”∗” to suppress numbering - begin{array∗} Use nonumber to suppress numbering of individual equations 1 This and all following Amsmath slides adapted from http://www.icms.org.uk/downloads/pgcourses/15october/Zachary.pdf
24. 24. Amsmath Equation Environments - Multline begin{multline} lim_{xtoinfty}frac{P(M>x)}{overline{F^s}(x)} le limsup_{xtoinfty} 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} lim x→∞ P(M > x) F s (x) ≤ lim sup x→∞ P(M > x, Sτ1 > x − R + a − ) F s (x) 2−γ +γ (a − )(1 − γ)2 (2)
25. 25. Amsmath Equation Environments - Cases begin{equation*} I_A = begin{cases} 1 & text{if \$xin A\$} 0 & text{otherwise} end{cases} end{equation*} IA = 1 0 if x ∈ A otherwise
26. 26. More Environments Equation - single equation on a single line Gather - multiple equations with no alignment Flalign - horizontally spread version of align 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 + b 2 ) = a3 + 3a2 b + 3ab 2 + b 3 (3)
27. 27. Matrix Environments begin{equation} begin{matrix} 1 & 0 0 & 1 end{matrix} end{equation} 1 0 0 1 (4)
28. 28. More Matrix Environments pmatrix 1 0 0 1 (5) 1 0 0 1 (6) 1 0 0 1 (7) 1 0 0 1 (8) 1 0 0 1 (9) bmatrix Bmatrix vmatrix Vmatrix
29. 29. 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
30. 30. Headers and Footers Fancyhdr package creates customizable headers and footers:
31. 31. Headers and Footers Fancyhdr package creates customizable headers and footers: documentclass { a r t i c l e } usepackage { fancyhdr } pagestyle{ fancyplain } b e g i n { document } l h e a d { Aubry W. V e r r e t } r h e a d { t o d a y } end{ document }
32. 32. Fancyhdr Output
33. 33. Fancyhdr Help You can get assistance with Fancyhdr here: ftp://ctan.tug.org/tex-archive/macros/latex/ contrib/fancyhdr/fancyhdr.pdf
34. 34. Minipages The Minipage environment creates miniature pages within pages. begin{minipage}...end{minipage} It is suitable for: Grouping ﬁgures or tables Placement of footnotes attached to images Placing a border around a ﬁgure and its title
35. 35. Minipage example b e g i n { f i g u r e } [ htbp ] centering b e g i n { m i n i p a g e } [ b ] { 5 cm} centering i n c l u d e g r a p h i c s { image 1} c a p t i o n { C a p t i o n 1} end{ m i n i p a g e } b e g i n { m i n i p a g e } [ b ] { 5 cm} centering i n c l u d e g r a p h i c s { image 2} c a p t i o n { C a p t i o n 2} end{ m i n i p a g e } end{ f i g u r e }
36. 36. Output Figure: Science Cat Figure: Physics Cat
37. 37. Minipage Example Two b e g i n { f i g u r e } [ htbp ] centering b e g i n { m i n i p a g e } [ b ] { 3 . 3 cm} centering 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 p t i o n { S c i e n c e Cat } end{ m i n i p a g e } b e g i n { m i n i p a g e } [ b ] { 3 . 3 cm} centering 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 p t i o n { P h y s i c s Cat } end{ m i n i p a g e } b e g i n { m i n i p a g e } [ b ] { 3 . 3 cm} centering 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 p t i o n { S c i e n c e Cat } end{ m i n i p a g e } b e g i n { m i n i p a g e } [ b ] { 3 . 3 cm} centering 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 p t i o n { P h y s i c s Cat } end{ m i n i p a g e } end{ f i g u r e } cat } cat } cat } cat }
38. 38. Figure: Science Cat Figure: Physics Cat Figure: Science Cat Figure: Physics Cat
39. 39. Fonts Default Font: Computer modern Default font size: 10pt How to change the default font: Additional fonts are available for installation (http://www.tug.dk/FontCatalogue/)
40. 40. Fonts Default Font: Computer modern Default font size: 10pt How to change the default font: Additional fonts are available for installation (http://www.tug.dk/FontCatalogue/) How to change the default font size: documentclass command accepts [11pt] and [12pt] as options ﬁx-cm package overrides font size defaults special commands
41. 41. Font Size Commands tiny(5pt) scriptsize(7pt) footnotesize(8pt) small(9pt) normalsize(10pt) large(12pt) Large(14pt) LARGE(18pt) huge(20pt) Huge(24pt)
42. 42. Colored text Use the xcolor package to add color to your text: usepackage{xcolor} Use {color{color name} text} to change the text color. Predeﬁned colors include: black, white, red, yellow, blue, green, cyan, magenta
43. 43. Example {color{red} This text is red!} This text is red!
44. 44. Colored Text Background colorbox{yellow}{This text has a yellow background!} This text has a yellow background!
45. 45. More Colors! Use the [dvipsnames] option when you call the color environment: usepackage[dvipsnames]{xcolor} You can now access 68 more colors!
46. 46. New Colors
47. 47. Wrap ﬁgure To wrap text around a ﬁgure use the Wrapﬁg package: usepackage{wrapﬁg} Wrap the ﬁgure in the wrapﬁgure environment: begin{wrapﬁgure}{alignment}{width}...end{wrapﬁgure} alignment Either l (left) or r (right) width Width of image
48. 48. Wrapﬁg Example Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam porttitor rutrum felis eget faucibus. Aliquam erat volutpat. Duis commodo, libero nec adipiscing pellentesque, risus velit faucibus augue, eget molestie nibh risus et augue. b e g i n { w r a p f i g u r e }{ l }{40mm} begin { center } includegraphics { far side } end{ c e n t e r } caption { Einstein } end{ w r a p f i g u r e } Integer quis tristique est. Pellentesque lacinia mi mattis ipsum rutrum egestas. Aliquam vestibulum pharetra felis, in congue eros posuere ac.
49. 49. Output
50. 50. Compiling multiple .tex ﬁles As your tex ﬁle grows, you may ﬁnd that it becomes more diﬃcult to manage (compiling starts to take a long time, it gets hard to ﬁnd things, bugs are harder to ﬁnd, etc.) The solution: write several ﬁles sepearately and compile them toether at the end. Use the input command to read each “child” ﬁle into your “root” document... input{child1.tex} input{child2.tex} input{child3.tex}
51. 51. Compiling multiple .tex ﬁles The problem with input is that the “child” ﬁles won’t compile on their 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 as follows: subfile{child} The ”child” documents must start with the following statements: documentclass[rootdocument.tex]{subfiles} begin{document} and end with: end{document}
52. 52. Alternate Output A LTEX can directly generate two formats: dvi Generate using the latex command pdf Generate using the pdﬂatex command dvi supports only the eps image format pdf supports jpg, png, pdf image formats
53. 53. Converting from DVI to PDF Directly (dvi → pdf): Use dvipdfm. A There is a special button for this in most LTEXeditors.
54. 54. Converting from DVI to PDF Directly (dvi → pdf): Use dvipdfm. A There is a special button for this in most LTEXeditors. Use this if the original ﬁle contains postscript ﬁgures
55. 55. Converting from DVI to PDF Directly (dvi → pdf): Use dvipdfm. A There is a special button for this in most LTEXeditors. Use this if the original ﬁle contains postscript ﬁgures Indirectly (dvi → ps → pdf): Use dvips, then sp2pdf
56. 56. Converting from DVI to PDF Directly (dvi → pdf): Use dvipdfm. A There is a special button for this in most LTEXeditors. Use this if the original ﬁle contains postscript ﬁgures Indirectly (dvi → ps → pdf): Use dvips, then sp2pdf typically ineﬀecient and can produce larger ﬁles of lower quality
57. 57. HTML output A There are several programs for converting LTEX to HTML: Hyperlatex Actively maintained to keep up with HTML standards TTH Good at formula conversion Heava Good overall, written in O Caml LaTeX2HTML Not well maintained text4ht Diﬃcult to conﬁgure but produces good output
58. 58. Beamer It is possible to create sophisticated presentations while A harnessing the power of LTEX The Beamer class produces presentations that: Can be easily cutomized Contain overlays Can display sophisitcated mathematics Are easily converted to handouts Compile directly to PDF
59. 59. 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/
60. 60. Frames Beamer uses the Frame environment: begin{frame}[options]...end{frame}
61. 61. Frames Beamer uses the Frame environment: begin{frame}[options]...end{frame} Options include: fragile allows you to include text using the verbatim or listings packages on a slide allowframebreaks allows Beamer to create extra slides to handle overﬂow text shrink shrinks contents to ﬁt on one slide
62. 62. Example of Frame
63. 63. How to Make A Table A To make a table in LTEX use the tabular environment: begin{tabular}...end{tabular}
64. 64. How to Make A Table A To make a table in LTEX use the tabular environment: begin{tabular}...end{tabular} Separate columns with the ”&” symbol Separate rows with the double backslash ””
65. 65. Tabular Layout Specify the column layout when you call tabular: begin{tabular}{l|l|l} Vertical bars produce vertical lines between columns. Alignment Symbols l - align left r - align right c - centered
66. 66. 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 mammal mammal mammal reptile reptile aves Species lion tiger platypus iguana snake ﬂamingo Lays eggs? % % ! ! ! !
67. 67. Tables Change 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 mammal mammal mammal reptile reptile aves Species lion tiger platypus iguana snake ﬂamingo Lays eggs? % % ! ! ! !
68. 68. Tables Add horizontal lines: begin{tabular}{| l | r | c | } hline Class & Species & Lays eggs? hlinehline 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 mammal mammal mammal reptile reptile aves Species lion tiger platypus iguana snake ﬂamingo Lays eggs? % % ! ! ! !
69. 69. Tables Not so many: begin{tabular}{| l | r | c | } hline Class & Species & Lays eggs? hlinehline mammal & lion & XSolidBrush & tiger & XSolidBrush & platypus & Checkmark hline reptile & iguana & Checkmark & snake & Checkmark hline aves & flamingo & Checkmark hline end{tabular} Class mammal reptile aves Species lion tiger platypus iguana snake ﬂamingo Lays eggs? % % ! ! ! !
70. 70. Tables Partial hlines begin{tabular}{| l | r | c | } hline Class & Species & Lays eggs? hlinehline 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 mammal reptile aves Species lion tiger platypus iguana snake ﬂamingo Lays eggs? % % ! ! ! !
71. 71. Tables Multirow begin{tabular}{| l | r | c | } hline Class & Species & Lays eggs? hlinehlin 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 hl end{tabular} Class mammal reptile aves Species lion tiger platypus iguana snake ﬂamingo Lays eggs? % % ! ! ! !
72. 72. Tables Color (colortbl package) begin{tabular}{| l | r | c | } hline rowcolor[gray]{0.8} Class & Species & Lays eggs? hlinehl 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 hl end{tabular} Class mammal reptile aves Species lion tiger platypus iguana snake ﬂamingo Lays eggs? % % ! ! ! !
73. 73. 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 botto end{tabular}
74. 74. Tables Better horizontal lines: booktabs package Class Species lion mammal tiger platypus reptile iguana snake aves ﬂamingo Lays eggs? % % ! ! ! !
75. 75. Tables The table enviroment: begin{table} ... end{table} allows you to: Turn a table into a ﬂoat Add a caption Number the table for referencing
76. 76. Tables table environment Table: Who lays eggs? Class Species lion mammal tiger platypus reptile iguana snake aves ﬂamingo Lays eggs? % % ! ! ! !
77. 77. 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
78. 78. Tables One ﬁx: 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
79. 79. 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
80. 80. 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
81. 81. 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} ``` ``` Argument ``` 0 π/2 ``` Function sin 0 1 cos 1 0
82. 82. Tables Making tables look good... D 5in 5in 5in 10in 10in 10in test test test test test test 1 2 3 1 2 3 Pu 285 287 230 430 433 431 lb lb lb lb lb lb σN 38.200 psi 38.27 psi 30.67 psi 248.67 psi 28.8 psi 28.7334 psi
83. 83. Tables ...takes practice. Table: Maximum load and nominal tension. D (in) Pu (lbs) σN (psi) 5 test 1 test 2 test 3 285 287 230 38.00 38.27 30.67 10 test 1 test 2 test 3 430 433 431 28.67 28.87 28.73
84. 84. Where To Get Help A Books - LTEXConcisely by Adrian Johnstone Online - numerous manuals available Research Computing Lab www2.lib.virginia.edu/brown/rescomp/ help/index.html