TLC2,ch-front.tex,v: 1.29,2004/03/26p.i a The L T X Companion E Second Edition TLC2,ch-front.tex,v: 1.29,2004/03/26p.ii Addison-Wesley Series on Tools and Techniques for Computer Typesetting Thisseriesfocusesontoolsandtechniquesneededforcomputertypesettingandinforma- tionprocessingwithtraditionalandnewmedia.Booksintheseriesaddressthepractical needs of both users and system developers. Initial titles comprise handy references for LaTEXusers;forthcomingworkswillexpandthatcore.Ultimately,theserieswillcoverother typesettingandinformationprocessingsystems,aswell,especiallyinsofarasthosesys- tems offer unique value to the scientific and technical community. The series goal is to enhanceyourabilitytoproduce,maintain,manipulate,orreusearticles,papers,reports, proposals,books,andotherdocumentswithprofessionalquality. Ideasforthisseriesshouldbedirectedtotheeditor:[email protected]. Sendallothercommentstothepublisher:[email protected]. SeriesEditor FrankMittelbach ManagerLATEX3Project,Germany EditorialBoard JacquesAndré TimBray ChrisRowley Irisa/Inria-Rennes,France TextualityServices,Canada OpenUniversity,UK BarbaraBeeton PeterFlynn RichardRubinstein Editor,TUGboat,USA UniversityCollege,Cork, HumanFactors DavidBrailsford Ireland International,USA UniversityofNottingham, LeslieLamport PaulStiff UK CreatorofLATEX,USA UniversityofReading,UK SeriesTitles GuidetoLATEX,FourthEdition,byHelmutKopkaandPatrickW.Daly TheLATEXCompanion,SecondEdition,byFrankMittelbachandMichelGoossens withJohannesBraams,DavidCarlisle,andChrisRowley TheLATEXGraphicsCompanion,byMichelGoossens,SebastianRahtz,andFrankMittelbach TheLATEXWebCompanion,byMichelGoossensandSebastianRahtz AlsofromAddison-Wesley: LATEX:ADocumentPreparationSystem,SecondEdition,byLeslieLamport TheUnicodeStandard,Version4.0,bytheUnicodeConsortium TLC2,ch-front.tex,v: 1.29,2004/03/26p.iii a The L T X Companion E Second Edition Frank Mittelbach LATEX3Project,Mainz,Germany Michel Goossens CERN,Geneva,Switzerland with Johannes Braams, David Carlisle, and Chris Rowley and contributions by Christine Detig and Joachim Schrod Boston • San Francisco • New York • Toronto • Montreal London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City TLC2,ch-front.tex,v: 1.29,2004/03/26p.iv Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheir productsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,and Addison-Wesleywasawareofatrademarkclaim,thedesignationshavebeenprintedwith initialcapitallettersorinallcapitals. Theauthorsandpublisherhavetakencareinthepreparationofthisbook,butmakeno expressedorimpliedwarrantyofanykindandassumenoresponsibilityforerrorsor omissions.Noliabilityisassumedforincidentalorconsequentialdamagesinconnection withorarisingoutoftheuseoftheinformationorprogramscontainedherein. Thepublisheroffersdiscountsonthisbookwhenorderedinquantityforbulkpurchases andspecialsales.Formoreinformation,pleasecontact: U.S.CorporateandGovernmentSales (800)382-3419 [email protected] ForsalesoutsideoftheU.S.,pleasecontact: InternationalSales (317)581-3793 [email protected] VisitAddison-WesleyontheWeb:www.awprofessional.com LibraryofCongressCataloging-in-PublicationData Mittelbach, Frank. The LaTeX Companion.– 2nd ed. / Frank Mittelbach and Michel Goossens, with Johannes Braams, David Carlisle, and Chris Rowley. p. cm. Goossens’ name appears first on the earlier edition. Includes bibliographical references and index. ISBN 0-201-36299-6 (pbk. : alk. paper) 1. LaTeX (Computer file) 2. Computerized typesetting. I. Goossens, Michel. II. Rowley, Chris, 1948- III. Title. Z253.4.L38G66 2004 686.2’2544536–dc22 2003070810 Copyright©2004byPearsonEducation,Inc. Allrightsreserved.Nopartofthispublicationmaybereproduced,storedinaretrieval system,ortransmitted,inanyform,orbyanymeans,electronic,mechanical, photocopying,recording,orotherwise,withoutthepriorconsentofthepublisher. PrintedintheUnitedStatesofAmerica.PublishedsimultaneouslyinCanada. Forinformationonobtainingpermissionforuseofmaterialfromthiswork,please submitawrittenrequestto: PearsonEducation,Inc. RightsandContractsDepartment 75ArlingtonStreet,Suite300 Boston,MA02116 Fax:(617)848-7047 ISBN0-201-36299-6 Textprintedonrecycledpaper 12345678910—CRW—0807060504 Firstprinting,April2004 TLC2,ch-front.tex,v: 1.29,2004/03/26p.v WededicatethisbooktothememoryofMichaelDownes(1958–2003), agreatfriendandwonderfulcolleagueontheLaTEXTeam. Histhoughtfulcontributionstoourworkandourlivesarediverse andprofound.Moreover,hebrightensthelivesofcountlessgrateful (LA)TEXusersthroughthewisdombuiltintohissupportforall aspectsofmathematicaltypesetting—verymanymasterpiecesofthe publishingart willstandforeverassuperbmemorialstohisquiet butdeepinsights. TLC2,ch-front.tex,v: 1.29,2004/03/26p.vi TLC2,ch-front.tex,v: 1.29,2004/03/26p.vii Contents ListofFigures xix ListofTables xxi Preface xxv 1 Introduction 1 1.1 Abriefhistory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Today’ssystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.3 Workingwiththisbook . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.3.1 What’shere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.3.2 Typographicconventions. . . . . . . . . . . . . . . . . . . . . 11 1.3.3 Usingtheexamples . . . . . . . . . . . . . . . . . . . . . . . . 14 2 TheStructureofaLATEXDocument 15 2.1 Thestructureofasourcefile . . . . . . . . . . . . . . . . . . . . . . . 15 2.1.1 Processingofoptionsandpackages . . . . . . . . . . . . . . 17 2.1.2 Splittingthesourcefileintoparts . . . . . . . . . . . . . . . 18 2.1.3 Combiningseveralfiles . . . . . . . . . . . . . . . . . . . . . . 20 2.1.4 optional—Providingvariantsinthedocumentsource . . . 21 2.2 Sectioningcommands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.2.1 Numberingheadings . . . . . . . . . . . . . . . . . . . . . . . 24 2.2.2 Formattingheadings . . . . . . . . . . . . . . . . . . . . . . . 27 2.2.3 Changingfixedheadingtexts . . . . . . . . . . . . . . . . . . 34 2.2.4 fncychap—Predefinedchapterheadinglayouts . . . . . . . 34 2.2.5 quotchap—Mottosonchapters . . . . . . . . . . . . . . . . . 35 2.2.6 titlesec—Adifferentapproachtoheadings . . . . . . . . . . 36 TLC2,ch-front.tex,v: 1.29,2004/03/26p.viii viii Contents 2.3 Tableofcontentsstructures . . . . . . . . . . . . . . . . . . . . . . . . 45 2.3.1 Enteringinformationintothecontentsfiles . . . . . . . . . 46 2.3.2 Typesettingacontentslist . . . . . . . . . . . . . . . . . . . . 49 2.3.3 Combiningcontentslists . . . . . . . . . . . . . . . . . . . . . 52 2.3.4 Providingadditionalcontentsfiles . . . . . . . . . . . . . . . 54 2.3.5 shorttoc—Summarytableofcontents . . . . . . . . . . . . . 55 2.3.6 minitoc—Multipletablesofcontents. . . . . . . . . . . . . . 56 2.3.7 titletoc—Adifferentapproachtocontentslists . . . . . . . 58 2.4 Managingreferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 2.4.1 showkeys—Displayingthereferencekeys . . . . . . . . . . 68 2.4.2 varioref—Moreflexiblecross-references. . . . . . . . . . . . 68 2.4.3 prettyref—Addingfrillstoreferences . . . . . . . . . . . . . 75 2.4.4 titleref—Non-numericalreferences . . . . . . . . . . . . . . . 76 2.4.5 hyperref—Activereferences . . . . . . . . . . . . . . . . . . . 78 2.4.6 xr—Referencestoexternaldocuments . . . . . . . . . . . . 78 3 BasicFormattingTools 79 3.1 Phrasesandparagraphs. . . . . . . . . . . . . . . . . . . . . . . . . . . 80 3.1.1 xspace—Gentlespacingafteramacro . . . . . . . . . . . . . 80 3.1.2 ellipsis,lips—Marksofomission . . . . . . . . . . . . . . . . 81 3.1.3 amsmath—Nonbreakingdashes. . . . . . . . . . . . . . . . . 83 3.1.4 relsize—Relativechangestothefontsize . . . . . . . . . . 83 3.1.5 textcase—Changecaseoftextintelligently . . . . . . . . . . 85 3.1.6 ulem—Emphasizeviaunderline. . . . . . . . . . . . . . . . . 87 3.1.7 soul—Letterspacingorstealingsheep . . . . . . . . . . . . . 88 3.1.8 url—TypesettingURLs,pathnames,andthelike . . . . . . 93 3.1.9 euro—Convertingandtypesettingcurrencies . . . . . . . . 96 3.1.10 lettrine—Droppingyourcapital . . . . . . . . . . . . . . . . . 99 3.1.11 ParagraphjustificationinLaTEX . . . . . . . . . . . . . . . . . 102 3.1.12 ragged2e—Enhancingjustification . . . . . . . . . . . . . . . 105 3.1.13 setspace—Changinginterlinespacing . . . . . . . . . . . . . 106 3.1.14 picinpar—Makingrectangularholes . . . . . . . . . . . . . . 108 3.2 Footnotes,endnotes,andmarginals . . . . . . . . . . . . . . . . . . . 109 3.2.1 Usingstandardfootnotes . . . . . . . . . . . . . . . . . . . . 110 3.2.2 Customizingstandardfootnotes . . . . . . . . . . . . . . . . 112 3.2.3 ftnright—Rightfootnotesinatwo-columnenvironment. . 114 3.2.4 footmisc—Variousfootnotesstyles . . . . . . . . . . . . . . 114 3.2.5 perpage—Resettingcountersona“per-page”basis . . . . 120 3.2.6 manyfoot—Independentfootnotes . . . . . . . . . . . . . . . 122 3.2.7 endnotes—Analternativetofootnotes . . . . . . . . . . . . 125 3.2.8 Marginalnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 3.3 Liststructures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 3.3.1 Modifyingthestandardlists . . . . . . . . . . . . . . . . . . . 128 3.3.2 paralist—Extendedlistenvironments . . . . . . . . . . . . . 132 TLC2,ch-front.tex,v: 1.29,2004/03/26p.ix Contents ix 3.3.3 amsthm—Providingheadedlists . . . . . . . . . . . . . . . . 138 3.3.4 Makingyourownlists . . . . . . . . . . . . . . . . . . . . . . . 144 3.4 Simulatingtypedtext . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 3.4.1 Simpleverbatimextensions . . . . . . . . . . . . . . . . . . . 152 3.4.2 upquote—Computerprogramstylequoting . . . . . . . . . 153 3.4.3 fancyvrb—Highlycustomizableverbatimenvironments . . 155 3.4.4 listings—Pretty-printingprogramcode . . . . . . . . . . . . 168 3.5 Linesandcolumns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 3.5.1 lineno—Numberinglinesoftext . . . . . . . . . . . . . . . . 176 3.5.2 parallel—Twotextstreamsaligned . . . . . . . . . . . . . . . 181 3.5.3 multicol—Aflexiblewaytohandlemultiplecolumns . . . 184 3.5.4 changebar—Addingrevisionbarstodocuments . . . . . . 189 4 TheLayoutofthePage 193 4.1 Geometricaldimensionsofthelayout . . . . . . . . . . . . . . . . . . 193 4.2 Changingthelayout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 4.2.1 layouts—Displayingyourlayout . . . . . . . . . . . . . . . . 199 4.2.2 Acollectionofpagelayoutpackages . . . . . . . . . . . . . 202 4.2.3 typearea—Atraditionalapproach . . . . . . . . . . . . . . . 203 4.2.4 geometry—Layoutspecificationwithauto-completion. . . 206 4.2.5 lscape—Typesettingindividualpagesinlandscapemode . 211 4.2.6 crop—Producingtrimmingmarks . . . . . . . . . . . . . . . 212 4.3 Dynamicpagedata:pagenumbersandmarks . . . . . . . . . . . . . 215 4.3.1 LaTEXpagenumbers . . . . . . . . . . . . . . . . . . . . . . . . 215 4.3.2 lastpage—Awaytoreferenceit . . . . . . . . . . . . . . . . . 216 4.3.3 chappg—Pagenumbersbychapters . . . . . . . . . . . . . . 216 4.3.4 LaTEXmarkcommands . . . . . . . . . . . . . . . . . . . . . . . 217 4.3.5 extramarks—Providingnewmarks . . . . . . . . . . . . . . . 220 4.4 Pagestyles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 4.4.1 Thelow-levelpagestyleinterface . . . . . . . . . . . . . . . 223 4.4.2 fancyhdr—Customizingpagestyles . . . . . . . . . . . . . . 224 4.4.3 truncate—Truncatetexttoagivenlength. . . . . . . . . . . 232 4.5 Visualformatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 4.5.1 nextpage—Extensionsto\clearpage . . . . . . . . . . . . . 235 4.6 Doinglayoutwithclass . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 4.6.1 KOMA-Script—Adrop-inreplacementforarticleetal.. . . 236 4.6.2 memoir—Producingcomplexpublications . . . . . . . . . . 237 5 TabularMaterial 239 5.1 StandardLaTEXenvironments . . . . . . . . . . . . . . . . . . . . . . . . 240 5.1.1 Usingthetabbingenvironment . . . . . . . . . . . . . . . . 241 5.1.2 Usingthetabularenvironment . . . . . . . . . . . . . . . . 242 5.2 array—Extendingthetabularenvironments. . . . . . . . . . . . . . 243 5.2.1 Examplesofpreamblecommands . . . . . . . . . . . . . . . 244 TLC2,ch-front.tex,v: 1.29,2004/03/26p.x x Contents 5.2.2 Definingnewcolumnspecifiers . . . . . . . . . . . . . . . . . 248 5.3 Calculatingcolumnwidths . . . . . . . . . . . . . . . . . . . . . . . . . 249 5.3.1 Explicitcalculationofcolumnwidths . . . . . . . . . . . . . 250 5.3.2 tabularx—Automaticcalculationofcolumnwidths. . . . . 251 5.3.3 tabulary—Columnwidthsbasedoncontent . . . . . . . . . 253 5.3.4 Differencesbetweentabular*,tabularx,andtabulary 255 5.4 Multipagetabularmaterial . . . . . . . . . . . . . . . . . . . . . . . . . 255 5.4.1 supertabular—Makingmultipagetabulars . . . . . . . . . . 256 5.4.2 longtable—Alternativemultipagetabulars . . . . . . . . . . 259 5.5 Colorintables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 5.6 Customizingtablerulesandspacing . . . . . . . . . . . . . . . . . . . 265 5.6.1 Coloredtablerules. . . . . . . . . . . . . . . . . . . . . . . . . 265 5.6.2 Variable-widthrules . . . . . . . . . . . . . . . . . . . . . . . . 266 5.6.3 hhline—Combininghorizontalandverticallines . . . . . . 266 5.6.4 arydshln—Dashedrules. . . . . . . . . . . . . . . . . . . . . . 267 5.6.5 tabls—Controllingrowspacing . . . . . . . . . . . . . . . . . 269 5.6.6 booktabs—Formalruledtables . . . . . . . . . . . . . . . . . 269 5.7 Furtherextensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 5.7.1 multirow—Verticalalignmentintables . . . . . . . . . . . . 273 5.7.2 dcolumn—Decimalcolumnalignments . . . . . . . . . . . . 274 5.8 Footnotesintabularmaterial . . . . . . . . . . . . . . . . . . . . . . . 277 5.8.1 Usingminipagefootnoteswithtables. . . . . . . . . . . . . 277 5.8.2 threeparttable—Settingtableandnotestogether . . . . . . 278 5.9 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 5.9.1 Managingtableswithwideentries . . . . . . . . . . . . . . . 279 5.9.2 Tablesinsidetables . . . . . . . . . . . . . . . . . . . . . . . . 280 6 MasteringFloats 283 6.1 Understandingfloatparameters. . . . . . . . . . . . . . . . . . . . . . 284 6.2 Floatplacementcontrol . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 6.2.1 placeins—Preventingfloatsfromcrossingabarrier . . . . 288 6.2.2 afterpage—Takingcontrolatthepageboundary . . . . . . 289 6.2.3 endfloat—Placingfiguresandtablesattheend . . . . . . . 289 6.3 ExtensionstoLaTEX’sfloatconcept . . . . . . . . . . . . . . . . . . . . 291 6.3.1 float—Creatingnewfloattypes . . . . . . . . . . . . . . . . . 291 6.3.2 caption—Fornonfloatingfiguresandtables . . . . . . . . . 295 6.3.3 rotating—Rotatingfloats . . . . . . . . . . . . . . . . . . . . . 296 6.3.4 rotfloat—Combiningfloatandrotating . . . . . . . . . . . . 298 6.4 Inlinefloats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 6.4.1 wrapfig—Wrappingtextaroundafigure . . . . . . . . . . . 299 6.4.2 picins—Placingpicturesinsidethetext . . . . . . . . . . . . 302 6.5 Controllingthefloatcaption . . . . . . . . . . . . . . . . . . . . . . . . 306 6.5.1 caption—Customizingyourcaptions . . . . . . . . . . . . . 308 6.5.2 subfig—Substructuringfloats . . . . . . . . . . . . . . . . . . 315