Guide To La Te X Kopka, Helmut Et Al

Guide%20to%20LaTeX%20-%20Kopka%2C%20Helmut%20et%20al

Guide%20to%20LaTeX%20-%20Kopka%2C%20Helmut%20et%20al

Guide%20to%20LaTeX%20-%20Kopka%2C%20Helmut%20et%20al

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 658

DownloadGuide To La Te X - Kopka, Helmut Et Al
Open PDF In BrowserView PDF
A Guide to

A
LT

X
E

and Electronic Publishing
Fourth edition

Helmut Kopka
Patrick W. Daly

Addison-Wesley
Harlow, England ˆ Reading, Massachusetts ˆ Menlo Park, California
New York ˆ Don Mills, Ontario ˆ Amsterdam ˆ Bonn ˆ Sydney ˆ Singapore
Tokyo ˆ Madrid ˆ San Juan ˆ Milan ˆ Mexico City ˆ Seoul ˆ Taipei

© Addison Wesley Longman Limited 2004
Addison Wesley Longman Limited
Edinburgh Gate
Harlow
Essex CM20 2JE
England
and Associated Companies throughout the World.
The rights of Helmut Kopka and Patrick W. Daly to be identified as authors of
this Work have been asserted by them in accordance with the Copyright,
Designs and Patents Act 1988.
All rights reserved. No part of this publication may be reproduced, stored in a
retrieval system, or transmitted in any form or by any means, electronic,
mechanical, photocopying, recording or otherwise, without either the prior
written permission of the publisher or a licence permitting restricted copying in
the United Kingdom issued by the Copyright Licensing Agency Ltd,
90 Tottenham Court Road, London W1P 9HE.
The programs in this book have been included for their instructional value.
They have been tested with care but are not guaranteed for any particular
purpose. The publisher does not offer any warranties or representations nor
does it accept any liabilities with respect to the programs.
Many of the designations used by manufacturers and sellers to distinguish their
products are claimed as trademarks. Addison Wesley Longman Limited has
made every attempt to supply trademark information about manufacturers and
their products mentioned in this book. A list of the trademark designations and
their owners appears on page v.
Cover designed by Designers & Partners, Oxford
Typeset by the authors with the LATEX Documentation System
Printed in Great Britain by Henry Ling Ltd, at the Dorset Press, Dorchester,
Dorset
First published 1993
Second edition 1995
Third edition 1999. Reprinted 1999, 2000
Fourth edition 2004
ISBN ????????????
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library
Library of Congress Cataloging-in-Publication Data
Kopka, Helmut.
A guide to LATEX : and Electronic Publishing
/ Helmut Kopka, Patrick W. Daly -- 4th ed.
p. cm.
Includes bibliographical references and index.
ISBN 0-201-39825-7
1. LATEX (Computer file) 2. Computerized typesetting. I. Daly,
Patrick W. II. Title.
????????????
???????????

???????
CIP

v
Trademark notices
METAFONT™ is a trademark of Addison-Wesley Publishing Company.
TEX™, AMS-TEX™, and AMS-LATEX™ are trademarks of the American
Mathematical Society.
Lucida™ is a trademark of Bigelow & Holmes.
Microsoft , MS-DOS , Windows , Internet Explorer are registered
trademarks of Microsoft Corporation.
PostScript , Acrobat Reader , Acrobat logo are registered trademarks and
PDF™ a trademark of Adobe Systems Incorporated.
UNIX is a registered trademark in the United States and other countries,
licensed exclusively through X/Open Company, Limited.
VAX™ and VMS™ are trademarks of Digital Equipment Corporation.
IBM is a registered trademark and techexplorer Hypermedia Browser™ a
trademark of International Business Machines Corporation.
Netscape™ and Netscape Navigator™ are trademarks of Netscape
Communications Corporation.
TrueType™ is a trademark and Apple and Macintosh are registered
trademarks of Apple Computer Inc.

®
®

®

®

®

®

®

®

®

®

®

Preface
A new edition to A Guide to LATEX begs the fundamental question: Has
LATEX changed so much since the appearance of the third edition in 1999
that a new release of this manual is justified?
The simple answer to that question is ‘Well . . . .’ In 1994, the LATEX world
was in upheaval with the issue of the new version LATEX 2ε , and the second
edition of the Guide came out just then to act as the bridge between the
old and new versions. By 1998, the initial teething problems had been
worked out and corrected through semi-annual releases, and the third
edition could describe an established, working system. However, homage
was still paid to the older 2.09 version since many users still employed its
familiar syntax, although they were most likely to be using it in a LATEX 2ε
environment. LATEX has now reached a degree of stability that since 2000
the regular updates have been reduced to annual events, which often
appear months after the nominal date, something that does not worry
anyone. The old version 2.09 is obsolete and should no longer play any
role in such a manual. In this fourth edition, it is reduced to an appendix
just to document its syntax and usage.
But if LATEX itself has not changed substantially since 1999, many of its
peripherals have. The rise of programs like pdfTEX and dvipdfm for PDF
output adds new possibilities, which are realized, not in LATEX directly, but
by means of more modern packages to extend the basic features. The
distribution of TEX/LATEX installations has changed, such that most users
are given a complete, ready-to-run setup, with all the ‘extras’ that one
used to have to obtain oneself. Those extras include user-contributed
packages, many of which are now considered indispensable. Today ‘the
LATEX system’ includes much more than the basic kernel by Leslie Lamport,
encompassing the contributions of hundreds of other people. This edition
reflects this increase in breadth.
The changes to the fourth edition are mainly those of emphasis.
1. The material has been reorganized into ‘Basics’ and ‘Beyond the
Basics’ (‘advanced’ sounds too intimidating) while the appendices
contain topics that really can be skipped by most everyday users.
Exception: Appendix H is an alphabetized command summary that
many people find extremely useful (including ourselves).
This reorganizing is meant to stress certain aspects over others. For
vii

viii

Preface
example, the section on graphics inclusion and color was originally
treated as an exotic freak, relegated to an appendix on extensions;
in the third edition, it moved up to be included in a front chapter
along with the picture environment and floats; now it dominates
Chapter 6 all on its own, the floats come in the following Chapter 7,
and picture is banished to the later Chapter 13. This is not to say
that the picture features are no good, but only that they are very
specialized. We add descriptions of additional drawing possibilities
there too.
2. It is stressed as much as possible that LATEX is a markup language,
with separation of content and form. Typographical settings should
be placed in the preamble, while the body contains only logical
markup. This is in keeping with the modern ideas of XML, where
form and content are radically segregated.
3. Throughout this edition, contributed packages are explained at that
point in the text where they are most relevant. The fancyhdr
package comes in the section on page styles, natbib where literature
citations are explained. This stresses that these ‘extensions’ are part
of the LATEX system as a whole. However, to remind the user that
they must still be explicitly loaded, a marginal note is placed at the
start of their descriptions.
4. PDF output is taken for granted throughout the book, in addition
to the classical DVI format. This means that the added possibilities
of pdfTEX and dvipdfm are explained where they are relevant. A
separate Chapter 10 on PostScript and PDF is still necessary, and the
best interface to PDF output, the hyperref package by Sebastian
Rahtz, is explained in detail. PDF is also included in Chapter 15 on
presentation material.
On the other hand, the other Web output formats, HTML and XML,
are only dealt with briefly in Appendix E, since these are large topics
treated in other books, most noticeably the LATEX Web Companion.
5. This book is being distributed with the TEXLive CD, with the kind
permission of Sebastian Rahtz who maintains it for the TEX Users
Group. It contains a full TEX and LATEX installation for Windows,
Macintosh, and Linux, plus many of the myriad extensions that
exist.
We once again express our hope that this Guide will prove more than
useful to all those who wish to find their way through the intricate world
of LATEX. And with the addition of the TEXLive CD, that world is brought
even closer to their doorsteps.
Helmut Kopka and Patrick W. Daly
June, 2003

Contents
Preface
I
1

Basics
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

3
3
4
6
10
11
14

Command names and arguments
Environments . . . . . . . . . . . .
Declarations . . . . . . . . . . . . .
Lengths . . . . . . . . . . . . . . . .
Special characters . . . . . . . . . .
Exercises . . . . . . . . . . . . . . .
Fine-tuning text . . . . . . . . . . .
Word division . . . . . . . . . . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

17
17
19
20
21
22
27
28
34

Document Layout and Organization
3.1
3.2
3.3
3.4

4

Just what is LATEX? . . . . .
Markup Languages . . . .
TEX and its offspring . . .
How to use this book . . .
Basics of a LATEX file . . . .
TEX processing procedure

Text, Symbols, and Commands
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8

3

1

Introduction
1.1
1.2
1.3
1.4
1.5
1.6

2

vii

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

37
37
42
52
58

Changing font . . . . . . . .
Centering and indenting . .
Lists . . . . . . . . . . . . . .
Generalized lists . . . . . .
Theorem-like declarations

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

61
61
67
69
74
80

Document class . . . .
Page style . . . . . . . .
Parts of the document
Table of contents . . .

.
.
.
.

.
.
.
.

Displayed Text
4.1
4.2
4.3
4.4
4.5

ix

x

CONTENTS
4.6
4.7
4.8
4.9
4.10
4.11

5

9

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
81
.
85
.
95
. 110
. 112
. 118

Mathematical environments .
Main elements of math mode
Mathematical symbols . . . . .
Additional elements . . . . . .
Fine-tuning mathematics . . .
Beyond standard LATEX . . . . .

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

119
119
120
124
130
145
151

153
The graphics packages . . . . . . . . . . . . . . . . . . . . . . 153
Adding color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

169
169
171
171
173
174
177
178

Counters . . . . . . . . . . . . . . . . . . . . . .
Lengths . . . . . . . . . . . . . . . . . . . . . . .
User-defined commands . . . . . . . . . . . . .
User-defined environments . . . . . . . . . . .
Some comments on user-defined structures

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

181
181
184
185
195
200

Float placement . . . . . . . . . .
Postponing floats . . . . . . . . .
Style parameters for floats . . .
Float captions . . . . . . . . . . .
Float examples . . . . . . . . . . .
References to figures and tables
Some float packages . . . . . . .

. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
in text
. . . . .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

User Customizations
8.1
8.2
8.3
8.4
8.5

II

.
.
.
.
.
.

Floating tables and figures
7.1
7.2
7.3
7.4
7.5
7.6
7.7

8

.
.
.
.
.
.

Graphics Inclusion and Color
6.1
6.2

7

.
.
.
.
.
.

Mathematical Formulas
5.1
5.2
5.3
5.4
5.5
5.6

6

Tabulator stops . . . . . . . . .
Boxes . . . . . . . . . . . . . . .
Tables . . . . . . . . . . . . . . .
Printing literal text . . . . . . .
Footnotes and marginal notes
Comments within text . . . . .

Beyond the Basics

205

Document Management
9.1
9.2
9.3
9.4

Processing parts of a
In-text references . .
Bibliographies . . . .
Keyword index . . . .

document
. . . . . . .
. . . . . . .
. . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

207
207
213
216
225

CONTENTS

xi

10 PostScript and PDF

231
10.1 LATEX and PostScript . . . . . . . . . . . . . . . . . . . . . . . . 231
10.2 Portable Document Format . . . . . . . . . . . . . . . . . . . . 236

11 Multilingual LATEX

251
11.1 The babel system . . . . . . . . . . . . . . . . . . . . . . . . . 252
11.2 Contents of the language.dat file . . . . . . . . . . . . . . . 256

12 Math Extensions with AMS-LATEX
12.1
12.2
12.3
12.4

Invoking AMS-LATEX . . . . . . .
Standard features of AMS-LATEX
Further AMS-LATEX packages . .
The AMS fonts . . . . . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

257
258
258
280
283

13 Drawing with LATEX

287
13.1 The picture environment . . . . . . . . . . . . . . . . . . . . 287
13.2 Extended pictures . . . . . . . . . . . . . . . . . . . . . . . . . . 302
13.3 Other drawing packages . . . . . . . . . . . . . . . . . . . . . . 307

14 Bibliographic Databases and BIBTEX

309
14.1 The BIBTEX program . . . . . . . . . . . . . . . . . . . . . . . . . 309
14.2 Creating a bibliographic database . . . . . . . . . . . . . . . . 311
14.3 Customizing bibliography styles . . . . . . . . . . . . . . . . 321

15 Presentation Material
15.1
15.2
15.3
15.4

Slide production with SLITEX . . . . . . . .
Slide production with seminar . . . . . .
Electronic documents for screen viewing
Special effects with PDF . . . . . . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

323
324
330
340
343

16 Letters

351
16.1 The LATEX letter class . . . . . . . . . . . . . . . . . . . . . . . 351
16.2 A house letter style . . . . . . . . . . . . . . . . . . . . . . . . . 356
16.3 A model letter customization . . . . . . . . . . . . . . . . . . 359

Appendices
A The New Font Selection Scheme (NFSS)
A.1
A.2
A.3

367
Font attributes under NFSS . . . . . . . . . . . . . . . . . . . . 368
Simplified font selection . . . . . . . . . . . . . . . . . . . . . . 370
Installing fonts with NFSS . . . . . . . . . . . . . . . . . . . . . 372

xii

CONTENTS

B

The LATEX Clockwork
B.1
B.2
B.3
B.4
B.5
B.6

Installing LATEX . . . . . . .
Obtaining the Adobe euro
TEX directory structure . .
The CTAN server . . . . .
Additional standard files
The various LATEX files . .

. . . .
fonts
. . . .
. . . .
. . . .
. . . .

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

381
381
387
387
389
391
396

C Error Messages
C.1
C.2
C.3
C.4
C.5
C.6

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

401
401
409
415
424
429
435

Class and package files . . . . . . .
LATEX programming commands . . .
Sample packages . . . . . . . . . . .
Changing preprogrammed text . .
Direct typing of special letters . . .
Alternatives for special symbols . .
Managing code and documentation

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

437
437
440
451
459
461
462
462

Basic structure of error messages
Some sample errors . . . . . . . .
List of LATEX error messages . . . .
TEX error messages . . . . . . . . .
Warnings . . . . . . . . . . . . . . .
Search for subtle errors . . . . . .

D LATEX Programming
D.1
D.2
D.3
D.4
D.5
D.6
D.7

E

LATEX and World Wide Web
E.1
E.2
E.3

F

475
Converting to HTML . . . . . . . . . . . . . . . . . . . . . . . . 476
The Extensible Markup Language: XML . . . . . . . . . . . . . 478
The techexplorer Hypermedia Browser . . . . . . . . . . . 481

Obsolete LATEX
F.1
F.2
F.3

483
The 2.09 preamble . . . . . . . . . . . . . . . . . . . . . . . . . 483
Font selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
Obsolete means obsolete . . . . . . . . . . . . . . . . . . . . . 485

G TEX Fonts
G.1
G.2
G.3
G.4
G.5
G.6

Font metrics and bitmaps . . . .
Computer Modern fonts . . . . .
The METAFONT program . . . .
Extended Computer fonts . . . .
PostScript fonts . . . . . . . . . .
Computer Modern as PostScript

. . . .
. . . .
. . . .
. . . .
. . . .
fonts

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

487
487
488
497
498
503
505

LIST OF TABLES

xiii

H Command Summary
H.1
H.2

507
Brief description of the LATEX commands . . . . . . . . . . . . 507
Summary tables and figures . . . . . . . . . . . . . . . . . . . 595

Bibliography

605

Index

607

List of Tables
10.1 The psnfss packages and their fonts . . . . . . . . . . . . . 234
10.2 Acrobat menu actions . . . . . . . . . . . . . . . . . . . . . . . 248
A.1
A.2
A.3

The NFSS encoding schemes . . . . . . . . . . . . . . . . . . . 368
The NFSS series attributes . . . . . . . . . . . . . . . . . . . . . 369
Attributes of the Computer Modern fonts . . . . . . . . . . . 370

D.1
D.2

Input coding schemes for inputenc package . . . . . . . . . 462
Alternative commands for special symbols . . . . . . . . . . 463

G.1
G.2
G.3

Computer Modern text fonts . . . . . . . . . . . . . . . . . . . 491
Root names of the 35 standard PostScript fonts . . . . . . . 504
Encoding suffixes . . . . . . . . . . . . . . . . . . . . . . . . . . 505

H.1
H.2
H.3
H.4
H.5
H.6
H.7
H.8
H.9
H.10
H.11
H.12
H.13
H.14
H.15
H.16
H.17
H.18
H.19
H.20
H.21

Font attribute commands . . . . . . .
Math alphabet commands . . . . . . .
Font sizes . . . . . . . . . . . . . . . . .
LATEX 2.09 font declarations . . . . . .
Dimensions . . . . . . . . . . . . . . . .
Accents . . . . . . . . . . . . . . . . . .
Special letters from other languages
Special symbols . . . . . . . . . . . . .
Command symbols . . . . . . . . . . .
Greek letters . . . . . . . . . . . . . . .
Binary operation symbols . . . . . . .
Relational symbols . . . . . . . . . . .
Negated relational symbols . . . . . .
Brackets . . . . . . . . . . . . . . . . . .
Arrows . . . . . . . . . . . . . . . . . .
Miscellaneous symbols . . . . . . . .
Mathematical symbols in two sizes .
Function names . . . . . . . . . . . . .
Math accents . . . . . . . . . . . . . . .
AMS arrows . . . . . . . . . . . . . . .
AMS binary operation symbols . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

595
595
595
595
596
596
596
596
596
596
597
597
597
597
598
598
598
598
599
599
599

xiv

CONTENTS
H.22
H.23
H.24
H.25
H.26

AMS Greek and Hebrew letters .
AMS delimiters . . . . . . . . . . .
AMS relational symbols . . . . . .
AMS negated relational symbols
Miscellaneous AMS symbols . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

600
600
600
601
601

1.1

Sample display with the WinEdt editor . . . . . . . . . . . . .

16

3.1
3.2

Page layout parameters . . . . . . . . . . . . . . . . . . . . . .
Sample title page . . . . . . . . . . . . . . . . . . . . . . . . . .

48
53

4.1

The list parameters . . . . . . . . . . . . . . . . . . . . . . .

76

6.1

An embellished image file . . . . . . . . . . . . . . . . . . . . . 160

List of Figures

10.1 Output produced by pdfTEX with the hyperref package . . 240
13.1 Comparison of eepic with eepicemu . . . . . . . . . . . . . 306
15.2 Title page of a pdfscreen document . . . . . . . . . . . . . . 341
B.1
B.2
B.3
B.4

The TEXLive welcome . . . . . . . . . . .
The TEXLive documentation browser .
The TDS directory tree . . . . . . . . . .
Partial directory tree of CTAN servers

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

383
384
388
390

E.1

Example of TEX4ht and techexplorer output . . . . . . . . 482

H.1
H.2
H.3

Single column page format . . . . . . . . . . . . . . . . . . . . 602
Double column page format . . . . . . . . . . . . . . . . . . . 603
Format of the list environment . . . . . . . . . . . . . . . . 604

Part I

Basics

Introduction
1

1.1

Just what is LATEX?
To summarize very briefly:

• LATEX is a comprehensive set of markup commands used with the
powerful typesetting program TEX for the preparation of a wide
variety of documents, from scientific articles, reports, to complex
books.

• LATEX like TEX is an open software system, available free of charge.
Its core is maintained by the LATEX3 Project Group but it also benefits
from extensions written by hundreds of user/contributors, with all
the advantages and disadvantages of such a democracy.

• A LATEX document consists of one or more source files containing plain text characters, the actual textual content plus markup
commands. These include instructions which can insert graphical
material produced by other programs.

• It is processed by the TEX program to produce a binary file in DVI
(device independent) format, containing precise directions for the
typesetting of each character. This in turn can be viewed on a monitor, or converted into printer instructions, or some other electronic
form such as PostScript, HTML, XML, or PDF.

• A variant on the TEX program called pdfTEX produces PDF output
directly from the source file without going through the DVI intermediary. With this, LATEX can automatically include internal links
and bookmarks with little or no extra effort, plus PDF buttons and
external links, in addition to graphics in a wide range of common
formats.

• TEX activities are coordinated by the TEX Users Group, TUG (www.
tug.org) who distribute a set of CDs, called TEXLive, annually to its
3

4

Chapter 1. Introduction
members, containing a TEX/LATEX installation for various computer
types.
The rest of this book attempts to fill in the gaps in the above summary.
With the help of the included TEXLive CD for Windows, Macintosh, and
Linux, which also contains a directory specific to this book (\books\
Kopka_and_Daly\), we hope that the user will have additional pleasure
in learning the joys of LATEX.

1.2

Markup Languages

1.2.1

Typographical markup
In the days before computers, an author would prepare a manuscript
either by hand or by typewriter, which he or she would submit to a publisher. Once accepted for publication (and after several rounds of corrections and modifications, each requiring a rewrite of the paper manuscript),
it would be sent to a copy editor, a human being who would decorate the
manuscript with markup, marginal notes that inform the typesetter (another human being) which fonts and spacings and other typographical
features should be used to convert it to the final printed form that one
expects of books and articles.
Electronic processing of text today follows a similar procedure, except
that the humans have been replaced by computer programs. (So far the
author has avoided this fate, but they are working on it.) The markup
is normally included directly in the manuscript in such a way that it is
converted immediately to its output form and displayed on the computer
monitor. This is known as WYSIWYG, or ‘what you see is what you get’.
However, what you see is not always what you’ve got. An alternative
that is used more and more by major publishers is markup languages,
in which the raw text is interspersed with indicators ‘for the typesetter.’
The result as seen on the monitor is much the same as a typewritten
manuscript, except that the markup is no longer abbreviated marginal
notes, but cryptic code within the actual text. This source text, which
can be prepared by a simple, dumb text editor program, is converted into
typographically set output by a separate program.
For example, to code the line
He took a bold step forward.
with HTML, the classical markup language of the World Wide Web, one
enters in the source text:
He took a bold step forward.
In Plain TEX, the same sentence would be coded as:

1.2. Markup Languages

5

He took a {\bf bold step} forward.
The first example is to be processed (displayed) by a Web browser program
that decides to set everything between  and  as bold face. The
second example is intended for the TEX program (Section 1.3). The markup
in these two examples follow different rules, different syntax, but the
functionality is the same.

1.2.2

Logical markup
The above examples illustrate typographical markup, where the inserted
commands or tags give direct instructions to alter the appearance of the
output, here a change of font. An alternative is to indicate the purpose
of the text. For example, HTML recognizes several levels of headings; to
place a title into the highest level one enters:

Logical Markup

The equivalent LATEX entry would be: \section{Logical Markup} With this logical markup, the author concentrates entirely on the content and leaves the typographical considerations to the experts. One merely marks the structure of the document, and has no means of controlling how the logical elements, like section titles, are to be rendered typographically. This information is put into HTML style sheets or LATEX classes and packages, which are external to the actual source file. This means that the entire layout of a document can be overhauled with only minimal or even no alterations to the source file. Today much effort is being put into XML, the Extensible Markup Language, as the ultimate markup system, since it allows the markup, or tags, to be defined as needed, without any indication of how they are to be implemented. That is left to XSL, the Extensible Stylesheet Language. It must be emphasized that neither XML nor XSL are programs at all; they are specifications for how documents and databases may be marked up, and how the markup tags may be translated into real output. Programs still need to be found to do the actual job. And that is the fundamental idea behind markup languages: that the source text indicates the logical structure of its contents. Such source files, being written in plain ascii text, are extremely robust, not being married to any particular software package or computer type. What does all this have to do with LATEX? In the next Section we outline the development of TEX and LATEX, and go on to show that LATEX, a product of the mid 1980’s, is a programmable markup language that is ideally suited for the modern world of electronic publishing. 6 Chapter 1. Introduction 1.3 TEX and its offspring The most powerful formatting program for producing book quality text of scientific and technical works is that of Donald E. Knuth (Knuth, 1986a, 1986b, 1986c, 1986d, 1986e). The program is called TEX, which is a rendering in capitals of the Greek letters τχ. For this reason the last letter is pronounced not as an x, but as the ch in Scottish loch or German ach, or as the Spanish j or Russian kh. The name is meant to emphasize that the printing of mathematical texts is an integral part of the program and not a cumbersome add-on. In addition to TEX, the same author has developed a further program called METAFONT for the production of character fonts. The standard TEX program package contains 75 fonts in various design sizes, each of which is also available in up to eight magnification steps. All these fonts were produced with the program METAFONT. With additional applications, further character fonts have been created, such as for Cyrillic, Chinese, and Japanese, with which texts in these alphabets can be printed in book quality. The TEX program is free, and the source code is readily available. Anybody may take it and modify it as they like, provided they call the result something other than TEX. This indeed has occurred, and several TEX variants do exist, including pdfTEX which we deal with later in this Chapter. Only Knuth is allowed to alter TEX itself, which he does only to correct any obvious bugs. Otherwise, he considers TEX to be completed; the current version number is 3.14159, and with his death, the code will be frozen for all time, and the version number will become exactly π . 1.3.1 The TEX program The basic TEX program only understands a set of very primitive commands that are adequate for the simplest of typesetting operations and programming functions. However, it does allow more complex, higherlevel commands to be defined in terms of the primitive ones. In this way, a more user-friendly environment can be constructed out of the low-level building blocks. During a processing run, the program first reads in a so-called format file which contains the definitions of the higher-level commands in terms of the primitive ones, and which also contains the hyphenation patterns for word division. Only then does it read in the author’s source file containing the actual text to be processed, including formatting commands that are predefined in the format file. Creating new formats is something that should be left to very knowledgeable programmers. The definitions are written to a source file which is then processed with a special version of the TEX program called initex. It stores the new format file in a compact manner so that it can be read in quickly by the regular TEX program. 1.3. TEX and its offspring 7 Although the normal user will almost never write such a format, he or she may be presented with a new format source file that will need to be installed with initex. For example, this is just what must be done to upgrade LATEX periodically. How to do this is described in Appendix B. 1.3.2 Plain TEX Knuth has provided a basic format named Plain TEX to interact with TEX at its simplest level. This is such a fundamental part of TEX processing that one tends to forget the distinction between the actual processing program TEX and this particular format. Most people who claim to ‘work only with TEX’ really mean that they only work with Plain TEX. Plain TEX is also the basis of every other format, something that only reinforces the impression that TEX and Plain TEX are one and the same. 1.3.3 LATEX The emphasis of Plain TEX is still very much at the typesetter’s level, rather than the author’s. Furthermore, the exploitation of all its potential demands considerable experience with programming techniques. Its application thus remains the exclusive domain of typographic and programming professionals. For this reason, the American computer scientist Leslie Lamport has developed the LATEX format (Lamport, 1985), which provides a set of higher-level commands for the production of complex documents. With it, even the user with no knowledge of typesetting or programming is in a position to take extensive advantage of the possibilities offered by TEX, and to be able to produce a variety of text outputs in book quality within a few days, if not hours. This is especially true for the production of complex tables and mathematical formulas. As pointed out in Section 1.2.2, LATEX is very much more a logical markup language than the original Plain TEX, on which it is based. It contains provisions for automatic running heads, sectioning, tables of contents, cross-referencing, equation numbering, citations, floating tables and figures, without the author having to know just how these are to be formatted. The layout information is stored in additional class files which are referred to but not included in the input text. The predefined layouts may be accepted as they are, or replaced by others with minimal changes to the source file. Since its introduction in the mid-1980s, LATEX has been periodically updated and revised, like all software products. For many years the version number was fixed at 2.09 and the revisions were only identified by their dates. The last major update occurred on December 1, 1991, with some minor corrections up to March 25, 1992, at which point LATEX 2.09 became frozen. 8 Chapter 1. Introduction 1.3.4 LATEX 2ε The enormous popularity of LATEX and its expansion into fields for which it was not originally intended, together with improvements in computer technology, especially dealing with cheap but powerful laser printers, had created a diversity of formats bearing the LATEX label. In an effort to re-establish a genuine, improved standard, the LATEX3 Project was set up in 1989 by Leslie Lamport, Frank Mittelbach, Chris Rowley, and Rainer Schöpf. Their goal was to construct an optimized and efficient set of basic commands complemented by various packages to add specific functionality as needed. As the name of the project implies, its aim is to achieve a version 3 for LATEX. However, since that is the long-term goal, a first step towards it was the release of LATEX 2ε in mid-1994 together with the publication of the second edition of Lamport’s basic manual (Lamport, 1994) and of an additional book (Goossens et al., 1994) describing many of the extension packages available and LATEX programming in the new system. Since then, two further books have appeared, Goossens et al. (1997) dealing with the inclusion of graphics and color, and Goossens and Rahtz (1999) explaining how LATEX may be used with the World Wide Web. Both these topics are also dealt with in this Guide. Initially updates to LATEX 2ε were issued twice a year, in June and December, but it has now become so stable that since 2000 the changes are released only once a year, nominally in June. LATEX 2ε is now the standard version, and LATEX 2.09 is considered obsolete, although source files intended for the older version may still be processed with the newer one. In this book, unless otherwise indicated, ‘LATEX’ will always mean LATEX 2ε . 1.3.5 TEX fonts TEX initially made use of its own set of fonts, called Computer Modern generated by Knuth’s METAFONT program. The reason for doing this was that printers at that time (and even today) may contain their own preloaded fonts, but they are often slightly different from printer to printer. Furthermore, they lacked the mathematical character sets that are essential to TEX’s main hallmark, mathematical typesetting. So Knuth created pixel fonts that could be sent to every printer ensuring the same results everywhere. Today the situation with fonts has changed dramatically. Outline fonts (also known as type 1 fonts) are more compact and versatile than the pixel fonts (type 3). They also have a far superior appearance and are drawn much faster in PDF files. The original Computer Modern fonts have been converted to outline fonts, but there is no reason to stick with them, except possibly for the mathematical symbols. It is LATEX 2ε with its New 1.3. TEX and its offspring 9 Font Selection Scheme that freed TEX from its rigid marriage to Computer Modern. Fonts are discussed in more detail in Appendix G. 1.3.6 The LATEX bazaar: user contributions Like the TEX program on which is relies, LATEX is freeware. There may be a prejudice that what is free in not worth anything, but there are other examples in the computer world to contradict this statement. And since the LATEX macros are provided in files containing plain text, there is no problem to exchange, modify, and supplement them. In other words, the user can participate in extending the basic LATEX system. Taking advantage of a mechanism in LATEX 2.09 that allowed options to the default layouts to be contained in so-called style option files, many users began writing their own ‘options’ to provide additional features to the basic LATEX. They then made these available to other users via the Internet. Many were intended for very specific problems, but many more proved to be of such general usefulness that they have become part of the standard LATEX installation. In this way, the users themselves have built up a system that meets their needs. With LATEX 2ε , these user contributions acquired official status: they became known as packages, they could be entered directly into the document and not by the back door, guidelines were issued for writing them, and additional commands were introduced to assist package programming. Package files bear the extension .sty from LATEX 2.09 days, so that the older style option files may still function as packages today. Those packages that have established themselves as indispensable for sophisticated LATEX processing are described in this book in those sections where they are most relevant. This does not imply that other packages are less worthwhile, but simply that this book does have to make a selection. Many other packages are described fully in The LATEX Companion (Goossens et al., 1994) and it would go beyond the bounds of this book to reproduce it here. 1.3.7 LATEX and electronic publishing The most significant development in computer usage in the last decade is the rise of the World Wide Web (or the hijacking of the Internet by the glitzy society). LATEX makes its own contribution here with • programs to convert LATEX files to HTML (Appendix E); • means of creating PDF output, with hypertext features such as links, bookmarks, active buttons (Chapter 10); 10 Chapter 1. Introduction • interfacing to XML both by acting as an engine to render XML documents and with programs to convert LATEX to XML and vice versa (Appendix E). All these forms of electronic publishing are alternatives to traditional paper output. We do not expect paper to disappear entirely so quickly, but it is rapidly being replaced by electronic forms, which can always reproduce the paper whenever needed. 1.4 How to use this book This Guide is meant to be a mixture of textbook and reference manual. It explains all the essential elements of the current standard LATEX 2ε , but compared to Lamport (1985, 1994), it goes into more detail, offers more examples and exercises, and describes many ‘tricks’ based on the authors’ experiences. It explains not only the core LATEX installation, but also many of the contributed packages that have become essential to modern LATEX processing, and thus quasi-standard. We necessarily have to be selective, for we cannot go to the same extend as The LATEX Companion (Goossens et al., 1994), The LATEX Graphics Companion (Goossens et al., 1997), and The LATEX Web Companion (Goossens and Rahtz, 1999), which are still valid companions to this book. The first part of the book is entitled The Basics, and deals with the more fundamental aspects of LATEX: inputting text and symbols, document organization, lists and tables, entering mathematics, and customizations by the user. The second part is called Beyond the Basics, meaning it presents concepts which may be more advanced but which are still essential to producing complex, sophisticated documents. The distinction is rather arbitrary. Finally, the appendices contain topics that are not directly part of LATEX itself, but useful for understanding its applications: installation, error messages, creating packages, World Wide Web, fonts. Appendix H is an alphabetized summary of most of the commands and their use, cross-referenced to their locations in the main text. 1.4.1 Some conventions In the description of command syntax, typewriter type is used to indicate those parts that must be entered exactly as given, while italic is reserved for those parts that are variable or for the text itself. For example, the command to produce tables is presented as follows: \begin{tabular}{col form} lines \end{tabular} The parts in typewriter type are obligatory, while col form stands for the definition of the column format that must be inserted here. The allowed 1.5. Basics of a LATEX file 11 values and their combinations are given in the detailed descriptions of the commands. In the above example, lines stands for the line entries in the table and are thus part of the text itself. Sections describing a package, an extension to basic LATEX, have the Package: sample name of that package printed as a marginal note, as demonstrated here for this paragraph. In this way, you are reminded that you must include it with \usepackage (Section 3.1.2) in order to obtain the additional features. Without it, you are likely to get an error message about undefined commands. ! Sections of text that are printed in a smaller typeface together with the boxed exclamation mark at the left are meant as an extension to the basic description. They may be skipped over on a first reading. This information presents deeper insight into the workings of LATEX than is necessary for everyday usage, but which is invaluable for creating more refined control over the output. 1.5 Basics of a LATEX file 1.5.1 Text and commands The source file for LATEX processing, or simply the LATEX file, contains the source text that is to be processed to produce the printed output. Splitting the text up into lines of equal width, formatting it into paragraphs, and breaking it into pages with page numbers and running heads are all functions of the processing program and not of the input text itself. For example, words in the source text are strings of letters terminated by some non-letter, such as punctuation, blanks, or end-of-lines (hard end-of-lines, ones that are really there, not the soft ones that move with the window width); whereas punctuation marks will be transferred to the output, blanks and end-of-lines merely indicate a gap between words. Multiple blanks in the input, or blanks at the beginning of a line, have no effect on the interword spacing in the output. Similarly, a new paragraph is indicated in the input text by an empty line; multiple empty lines have the same effect as a single one. In the output, the paragraph may be formatted either by indentation of the first line, or by extra interline spacing, but this is not affected in any way by the number of blank lines or extra spaces in the input. The source file contains more than just text, however; it is also interspersed with markup commands that control the formatting or indicate the structure. It is therefore necessary for the author to be able to recognize what is text and what is a command. Commands consist either of certain single characters that cannot be used as text characters, or of words preceded immediately by a special character, the backslash (\). The syntax of source text is explained in detail in Chapter 2. 12 Chapter 1. Introduction 1.5.2 Contents of a LATEX source file Every LATEX file contains a preamble and a body. The preamble is a collection of commands that specify the global processing parameters for the following text, such as the paper format, the height and width of the text, the form of the output page with its pagination and automatic page heads and footlines. As a minimum, the preamble must contain the command \documentclass to specify the document’s overall processing type. This is the first command in the preamble. If there are no other commands in the preamble, LATEX selects standard values for the line width, margins, paragraph spacing, page height and width, and much more. By default, these specifications are tailored to the American norms. For European requirements, built-in options exist to alter the text height and width to the A4 standard. Furthermore, there are language-specific packages to translate certain headings such as ‘Chapter’ and ‘Abstract’. The preamble ends with \begin{document}. Everything that follows this command is interpreted as body. It consists of the actual text mixed with markup commands. In contrast to those in the preamble, these commands have only a local effect, meaning they apply only to a part of the text, such as indentation, equations, temporary change of font, and so on. The body ends with the command \end{document}. This is normally the end of the file as well. The general syntax of a LATEX file is as follows: \documentclass[options]{class} Further global commands and specifications \begin{document} Text mixed with additional commands of local effect \end{document} The possible options and classes that may appear in the \documentclass command are presented in Section 3.1.1. A minimal LATEX file named hi.tex contains just the following lines: \documentclass{article} \begin{document} Hi! \end{document} 1.5.3 Extending LATEX with packages Packages are a very important feature of LATEX. These are extensions to the basic LATEX commands that are written to files with names that end in.sty and are loaded with the command \usepackage in the preamble. Packages can be classified by their origin: 1.5. Basics of a LATEX file 13 core packages are an integral part of the LATEX basic installation and are therefore fully standard; tools packages are a set written by members of the LATEX3 Team, and should always be in the installation; graphics packages are a standardized set for including pictures generated by other programs, and for handling color; they are on the same level as the tools packages; AMS-LATEX packages published by the American Mathematical Society, should be in any installation; contributed packages have been submitted by actual users; certain of these have established themselves as ‘essential’ to standard LATEX usage, but all are useful. Only a limited number of these packages are described in this book, those that we consider indispensable. However, there is nothing to prevent the user from obtaining and incorporating any others that should prove beneficial for his or her purposes. There are over 1000 contributed packages on the included TEXLive CD. How can one begin to get an overview of what they offer? Graham Williams has compiled a list of brief descriptions which can be found online and on the TEXLive CD at \texmf\doc\html\catalogue\catalogue.html How to load packages into the LATEX source file is explained in Section 3.1.2. Documentation of contributed packages is somewhat haphazard, depending on how much the author has put into it. The preferred method for distributing packages is to integrate the documentation with the code into a single file with extension .dtx. A special program DocStrip (Section D.7.1) is used to extract the actual package file or files, while LATEXing the original .dtx file produces the instruction manual. Most ready-to-run installations will already have done all this for the user, with the resulting manuals stored as DVI or PDF files somewhere in \texmf\doc\latex\. . . . However, you might have to generate the documentation output yourself by processing the .dtx file, which should be found in \texmf\source\latex\. . . . (Section B.3 explains the organization of the TEX directory system.) Some package authors write their manuals as an extra .tex file, the output of which may or may not be prestored in DVI or PDF form. Others provide HTML files. And still others simply add the instructions as comments in the package file itself. (This illustrates some of the joys of an open system.) 14 Chapter 1. Introduction 1.6 TEX processing procedure Since LATEX is a set of definitions for the TEX program, LATEX processing itself is in fact TEX processing with the LATEX format. What TEX does with this is the same as for any other of the many formats available (of which LATEX is perhaps the most popular). All the typesetting work is done by TEX, while LATEX handles the conversion from the logical markup to the typesetting commands. It also enables cross-referencing, running headlines, table of contents, literature citations and bibliography, indexing, and more. However, the processing of the source file to final output is TEX’s task, regardless of the format being used. 1.6.1 In the good old days TEX arose over 20 years ago before there were such things as PCs, graphical displays, and before computers were infected with windows or mice. TEX and its support programs were invoked from a command line, not with a mouse click. This may sound very old fashioned, but it did guarantee portability to all computer types. The processing steps that were taken in those days still exist with today’s graphical interfaces, but are now executed more conveniently. One can still open a ‘command prompt window’ and run them from the command line. The first step is of course to use a text editor program to write the source file containing the actual text and markup. The rules for entering this source text are explained in Chapter 2. It goes into a text file, or what is often called an ‘ascii’ file containing only standard punctuation marks, numbers, unaccented letters, upper and lower case. In other words, the text is that which can be produced from a standard English typewriter. The name of the source file normally has the extension.tex; it is then processed by TEX to produce a new file with the same base name and the extension.dvi, for device independent file. This is a binary file (all codes possible, not a text file) containing precise instructions for the selection and placement of every symbol, a coded description of the final printed page. The command to invoke TEX with the source file hi.tex is tex &latex hi meaning run the TEX program with the format latex. Usually the installation has defined a shortcut named latex to do this, so latex hi should be sufficient. It is only necessary to specify the extension of the source file name if it is something other than.tex. During the processing, TEX writes information, warnings, error messages to the computer monitor, and to a transcript file with the extension .log. It is well worth inspecting this file when unexpected results appear. 1.6. TEX processing procedure 15 The final step is to produce the printed pages from the DVI file. This requires another program, a driver, to generate the instructions specific to the given printer. For example, to produce a PostScript file, one runs dvips hi to obtain hi.ps from hi.dvi. And then one sends hi.ps to the PostScript printer with the regular command for that computer system. Previewing the DVI file on a computer monitor before printing was a later development, requiring high quality graphics displays. These programs are essentially special drivers that send the output directly to the monitor rather than to a printer or printer file. One very popular previewer is called with xdvi hi to view hi.dvi before committing it to paper. 1.6.2 And today The various steps for LATEX processing described above are still necessary today, and one can open up a command prompt window and carry them out just as before. However, there now exist intelligent editors with LATEXsavvy that not only assist writing the source text, but also will call the various programs, TEX, previewer, printer driver, BIBTEX, MakeIndex (these are explained later) with a mouse click. One such editor for Windows, available on the enclosed TEXLive CD in the support directory, is called WinShell, written by Ingo H. de Boer (www. winshell.de). Although free of charge, its author appreciates donations to offset his expenses. Another such editor and LATEX interface is WinEdt by Aleksander Simonic (www.winedt.com). A sample window with the opening text of this chapter is shown in Figure 1.1. This program is available for a 30-day trial period, after which one must pay a nominal fee to obtain a licence. It is the editor that we ourselves use and we can highly recommend it. An alternative is LyX, a free, open source software for document processing in near WYSIWYG, acting as a front-end to LATEX, where the user need not know anything about LATEX. See its home page at www.lyx.org. It must be stressed that all the above are interfaces to an existing LATEX installation. On the other hand, there are also commercial packages which include both the TEX/LATEX installation and a graphics interface. These are listed in Section B.1.1. 1.6.3 Alternative to TEX: pdfTEX As we mentioned earlier, it is permitted to use the TEX source code to generate something else, as long as it bears another name. One such 16 Chapter 1. Introduction Figure 1.1: Sample display with the WinEdt editor for interfacing to LATEX. ´ Thành. This program modification is called pdfTEX, created by Hàn Thê does everything TEX does, but it optionally writes its output directly to a PDF file, bypassing the DVI output of regular TEX. It therefore combines the TEX program with a DVI-to-PDF driver program. Normally this option is also the default. There are many advantages to producing PDF output directly this way, apart from saving a step. The PDF file is generated in exactly the same way as the DVI file with TEX, and can be viewed immediately with the Acrobat Reader or other PDF viewer. The results can be sent directly to a printer without going through the DVI-to-Printer program. It is also much easier to include the hypertext features of a true active PDF file, as we explain in Section 10.2.4. Adding the LATEX macros to pdfTEX produces something one could call pdfLATEX. This distinction is only meaningful for invoking the programplus-format to process the LATEX source file. Except for some things that we note in Section 10.2.3, LATEX commands are identical whether used with TEX or with pdfTEX. This makes the conversion extremely easy. The rest of this book deals essentially with LATEX itself, regardless of what the end product is to be: paper, HTML, XML, or PDF. 2 Text, Symbols, and Commands The text that is to be the input to a LATEX processing run is written to a source file with a name ending in.tex, the file name extension. This file is prepared with a text editor, either one that handles straightforward plain text, or one that is configured to assist the writing and processing of LATEX files. In either case, the contents of this file are plain ascii characters only, with no special symbols, no accented letters, preferably displayed in a fixed width typewriter font, with no frills like bold or italics, all in one size. All these aspects of true typesetting are produced afterwards by the TEX processing program with the help of markup commands inserted visibly into the actual text. It is therefore vital to know how commands are distinguished from text that is to be printed, and, of course, how they function. (However, for languages other than English, native keyboard input may indeed be used, as shown in Section 2.5.9.) 2.1 Command names and arguments A command is an instruction to LATEX to do something special, like print some symbol or text not available to the restricted character set used in the input file, or to change the current typeface or other formatting properties. There are three types of command names: • the single characters # $ & ˜ _ ˆ % { } all have special meanings that are explained later in this chapter; • the backslash character \ plus a single non-letter character; for example \$ to print the $ sign; all the special characters listed above have a corresponding two-character command to print them literally; • the backslash character \ plus a sequence of letters, ending with the first non-letter; for example, \large to switch to a larger typeface. 17 18 Chapter 2. Text, Symbols, and Commands Command names are case sensitive, so \large, \Large and \LARGE are distinct commands. Many commands operate on some short piece of text, which then appears as an argument in curly braces following the command name. For example, \emph{stress} is given to print the word stress in an emphasized typeface (here italic) as stress. Such arguments are said to be mandatory because they must always be given. Some commands take optional arguments, which are normally employed to modify the effects of the command somehow. The optional arguments appear in square braces. In this book we present the general syntax of commands as \name[optional]{mandatory} where typewriter characters must be typed exactly as illustrated and italic text indicates something that must be substituted for. Optional arguments are put into square brackets [ ] and the mandatory ones into curly braces { }. A command may have several optional arguments, each one in its set of brackets in the specified sequence. If none of the optional arguments is used, the square brackets may be omitted. Any number of blanks, or even a single new line, may appear between the command name and the arguments, to improve legibility. Some commands have several mandatory arguments. Each one must be put into a { } pair and their sequence must be maintained as given in the command description. For example, \rule[lift]{width}{height} produces a black rectangle of size width and height, raised by an amount lift above the current baseline. A rectangle of width 10 mm and height 3 mm is made with \rule{10mm}{3mm}. Since the optional argument lift is omitted, the rectangle is set on the baseline with no lifting, as . The arguments must appear in the order specified by the syntax and may not be interchanged. Some commands have a so-called *-form in addition to their normal appearance. A * is added to their name to modify their functionality somehow. For example, the \section command has a *-form \section* which, unlike the regular form, does not print an automatic section number. For each such command, the difference between the normal and *-form will be explained in the description of the individual commands. Command names consist only of letters, with the first non-letter indicating the end of the name. If there are optional or mandatory arguments following the command name, then it ends before the [ or { bracket, since these characters are not letters. Many commands, however, possess no arguments and are composed of only a name, such as the command \LaTeX to produce the LATEX logo. If such a command is followed by 2.2. Environments 19 a punctuation mark, such as comma or period, it is obvious where the command ends. If it is followed by a normal word, the blank between the command name and the next word is interpreted as the command terminator: The \LaTeX logo results in ‘The LATEXlogo’, that is, the blank was seen only as the end of the command and not as spacing between two words. This is a result of the special rules for blanks, described in Section 2.5.1. In order to insert a space after a command that consists only of a name, either an empty structure {} or a space command (\ and blank) must be placed after the command. The proper way to produce ‘The LATEX logo’ is to type either The \LaTeX{} logo or The \LaTeX\ logo. Alternatively, the command itself may be put into curly braces, as The {\TeX} logo, which also yields the right output with the inserted blank: ‘The TEX logo’. Incidentally, the LATEX 2ε logo is produced with \LaTeXe. Can you see why this logo command cannot be named \LaTeX2e? 2.2 Environments An environment is initiated with the command \begin{name} and is terminated by \end{name}. An environment has the effect that the text within it is treated differently according to the environment parameters. It is possible to alter (temporarily) certain processing features, such as indentation, line width, typeface, and much more. The changes apply only within the environment. For example, with the quote environment, previous text \begin{quote} text1 \small text2 \bfseries text3 \end{quote} following text the left and right margins are increased relative to those of the previous and following texts. In the example, this applies to the three texts text1, text2, and text3. After text1 comes the command \small, which has the effect of setting the next text in a smaller typeface. After text2, there is an additional command \bfseries to switch to bold face type. Both these commands only remain in effect up to the \end{quote}. The three texts within the quote environment are indented on both sides relative to the previous and following texts. The text1 appears in the normal typeface, the same one as outside the environment. The text2 and text3 appear in a smaller typeface, and text3 furthermore appears in bold face. After the end of the quote environment, the subsequent text appears in the same typeface that was in effect beforehand. 20 Chapter 2. Text, Symbols, and Commands Note that if the names of the environment in the \begin{..} \end{..} pair do not match, an error message will be issued on processing. Most declaration command names (see next section) may also be used as environment names. In this case the command name is used without the preceding \ character. For example, the command \em switches to an emphatic typeface, usually italic, and the corresponding environment \begin{em} will set all the text in italic until \end{em} is reached. A nameless environment can be simulated by a {...} pair. The effect of any command within it ends with the closing curly brace. The user can even create his or her own environments, as described in Section 8.4. 2.3 Declarations A declaration is a command that changes the values or meanings of certain parameters or commands without printing any text. The effect of the declaration begins immediately and ends when another declaration of the same type is encountered. However, if the declaration occurs within an environment or a {...} pair, its scope extends only to the corresponding \end command, or to the closing brace }. The commands \bfseries and \small mentioned in the previous section are examples of such non-printing declarations that alter the current typeface. Some declarations have associated arguments, such as the command \setlength which assigns a value to a length parameter (see Sections 2.4 and 8.2). Examples: {\bfseries This text appears in bold face} The \bfseries declaration changes the typeface: This text appears in bold face. The effect of this declaration ends with the closing brace }. \setlength{\parindent}{0.5cm} The paragraph indentation is set to 0.5 cm. The effect of this declaration ends with the next encounter of the command \setlength{\parindent}, or at the latest with the \end command that terminates the current environment. \pagenumbering{roman} The page numbering is to be printed in Roman numerals. Some declarations, such as the last example, are global, that is, their effects are not limited to the current environment. The following declarations are of this nature, the meanings of which are given later: \newcounter \setcounter \addtocounter \pagenumbering \thispagestyle \newlength \newsavebox 2.4. Lengths 21 Declarations made with these commands are effective right away and remain so until they are overridden by a new declaration of the same type. In the last example above, page numbering will be done in Roman numerals until countermanded by a new \pagenumbering{arabic} command. 2.4 Lengths 2.4.1 Fixed lengths Lengths consist of a decimal number with a possible sign in front (+ or -) followed by a mandatory dimensional unit. Permissible units and their abbreviated names are: cm mm in pt bp pc dd cc em ex centimeter, millimeter, inch (1 in = 2.54 cm), point (1 in = 72.27 pt), big point (1 in = 72 bp), pica (1 pc = 12 pt), didôt point (1157 dd = 1238 pt), cicero (1 cc = 12 dd), a font-specific size, the width of the capital M, another font-related size, the height of the letter x. Decimal numbers in TEX and LATEX may be written in either the English or European manner, with a period or a comma: both 12.5cm and 12,5cm are permitted. Note that 0 is not a legitimate length since the unit specification is missing. To give a zero length it is necessary to add some unit, such as 0pt or 0cm. Values are assigned to a length parameter by means of the LATEX command \setlength, which is described in Section 8.2 along with other commands for dealing with lengths. Its syntax is: \setlength{\length name}{length spec} For example, the width of a line of text is specified by the parameter \textwidth, which is normally set to a default value depending on the class, paper type, and font size. To change the line width to be 12.5 cm, one would give: \setlength{\textwidth}{12.5cm} 2.4.2 Rubber lengths Some parameters expect a rubber length. These are lengths that can be stretched or shrunk by a certain amount. The syntax for a rubber length is: 22 Chapter 2. Text, Symbols, and Commands nominal value plus stretch value minus shrink value where the nominal value, stretch value, and shrink value are each a length. For example, \setlength{\parskip}{1ex plus0.5ex minus0.2ex} means: the extra line spacing between paragraphs, called \parskip, is to be the height of the x in the current font, but it may be increased to 1.5 or reduced to 0.8 times that size. One special rubber length is \fill. This has the natural length of zero but can be stretched to any size. 2.5 Special characters 2.5.1 Spaces The space or blank character has some properties different from those of normal characters, some of which have already been mentioned in Section 2.1. During processing, blanks in the input text are replaced by rubber lengths (Section 2.4.2) in order to allow the line to fill up to the full line width. As a result, some peculiar effects can occur if one is not aware of the following rules: • one blank is the same as a thousand, only the first one counts; • blanks at the beginning of an input line are ignored; • blanks terminating a command name are removed; • the end of a line is treated as a blank. Some of the consequences of these rules are that there may be as many blanks as desired between words or at the beginning of a line (to make the input text more legible) and that a word may come right at the end of a line without the spacing between it and the next word disappearing. To force a space to appear where it would otherwise be ignored, one must give the command \ (a \ followed by a space character, made visible here by the symbol ). To ensure that certain words remain together on the same line, a protected space is inserted between them with the ˜ character (Section 2.7.1, page 28). Multiple protected spaces are all printed out, in contrast to normal spaces. Sometimes it is necessary to suppress the space that appears because of the new line. In this case, the last character in the line must be the comment character % (Section 4.11). Paragraphs are separated in the source text by blank lines. As for blank characters, one blank line is the same as a thousand. 2.5. Special characters 23 Instead of a blank line, the command \par may also be used to indicate the end of a paragraph. 2.5.2 Quotation marks The quotation marks found on the typewriter " are not used in book printing. Instead different characters are used at the beginning and end, such as ‘single quotes’ and “double quotes”. Single quotes are produced with ‘ and ’, while double quotes are made by typing the respective characters twice: ‘‘ for “ and ’’ for ”. Furthermore the typewriter character " will also generate the double closing quote ”. However, it should be avoided since it can lead to confusion. 2.5.3 Hyphens and dashes In book printing, the character that appears on the typewriter as - comes in various lengths: -, –, —. The smallest of these, the hyphen, is used for compound words such as father-in-law and for word division at the end of a line; the middle-sized one, the en dash, is used in ranges of numbers, for example, pages 33–36; and the largest, the em dash, is used as punctuation—what is normally called the dash. These are generated by typing the hyphen character one, two, or three times, so that - yields -, while -- makes –, and --- produces —. A fourth type of dash is the minus sign −, which is entered in math mode as $-$ (Chapter 5). 2.5.4 Printing command characters As mentioned in Section 2.1, the characters # $ ˜ _ ˆ % { } are interpreted as commands. To print them as text, one must give a command consisting of \ plus that character. $ = \$ 2.5.5 & = \& % = \% # = \# = \_ { = \{ } = \} The special characters §, „, , ¶, © and £ These special characters do not exist on the computer keyboard. They can however be generated by special commands as follows: § = \S † = \dag ‡ = \ddag ¶ = \P © = \copyright £ = \pounds The production of Greek letters and other mathematical symbols is described in Chapter 5. 24 Chapter 2. Text, Symbols, and Commands 2.5.6 Non-English letters Special letters that exist in languages other than English can also be generated with TEX. These are: œ={\oe} ø ={\o} Œ={\OE} Ø ={\O} æ={\ae} ł ={\l} Æ={\AE} Ł ={\L} å={\aa} ß={\ss} Å ={\AA} SS={\SS} ¡ =!‘ ¿=?‘ Ångstrøm may be written as {\AA}ngstr{\o}m while Karlstraße can be input as Karlstra{\ss}e. The ‘letter’ \SS is the upper case equivalent of \ss, used for automatic conversion between upper and lower case. However, see Section 2.5.9 for the possibility of entering such characters directly. 2.5.7 Accents In non-English languages, there is a multiplicity of diacritical marks or accents, most of which can be printed with TEX: ò =\‘{o} ō =\={o}  oo=\t{oo} ö=\"{o} õ=\˜{o} ǒ=\v{o} ő=\H{o} o=\b{o} o̊=\r{o} ¯ The o above is given merely as an example: any letter may be used. With i and j it should be pointed out that the dot must first be removed. This is carried out by prefixing these letters with a backslash: the commands \i and \j yield ı and . In this way ı̆ and ̋ are formed by typing \u{\i} and \H{\j}. The accent commands consisting of a non-letter may also be given without the curly braces: ò=\‘o ó=\’o ó=\’{o} ȯ=\.{o} o̧=\c{o} ô=\ˆo ô=\ˆ{o} ŏ=\u{o} o.=\d{o} ö=\"o õ=\˜o ō=\=o ȯ=\.o The letter accent commands should always be used with the curly braces. 2.5.8 The euro symbol The euro symbol € (or e) is too new to be part of the original LATEX, but it can be produced with the help of some additional fonts and contributed packages. Just which package you may use depends on your installation, and whether you have access to these additional fonts. The Text Companion fonts, described in Section G.4.4, do contain a euro symbol. Since these fonts should be part of every modern LATEX installation, you should be able to use their euro symbol if all else fails. Package: The package textcomp must be loaded in the preamble with textcomp \usepackage{textcomp} 2.5. Special characters 25 which defines many commands including \texteuro to print the symbol €. Since the European Commission originally dictated that it should only be printed in a sans serif font, it is better to issue \textsf{\texteuro} to produce €. (The font selection commands are described in Section 4.1.4.) If you are going to use this very frequently, you might want to define a shortcut named \euro with \newcommand{\euro}{\textsf{\texteuro}} as described in Section 8.3 on defining commands. A better solution is presented by the eurosym package by Henrik Theiling and the associated fonts that come with it, which bear the names feymr10, feybr10, and so on. This package defines the \euro command to print e, which changes automatically to bold e and slanted e as needed. Package: The europs package by Joern Clausen interfaces to the type 1 (Posteurops Script) euro fonts published by Adobe. For licensing reasons, these fonts may only be obtained from Adobe directly, even though free of charge (see Section B.2). This package provides the command \EUR for a symbol that varies with font family (Roman €25, sans serif €25, and typewriter €25) as well as for bold €25 and slanted €25. There is also a command \EURofc for the invariable symbol €. Package: Finally, the package eurosans by Walter Schmidt also addresses the eurosans Adobe euro fonts, again with the command \euro, with the same behavior as that of eurosym: always sans serif family, but changes with the other font attributes. The table below summarizes the above packages: Package: eurosym Package Command Fonts Notes textcomp \texteuro Text Companion Non standard symbol eurosym \euro Eurosym Sans serif, variable europs \EUR PostScript Varies with font family Invariable, official \EURofc eurosans \euro PostScript Sans serif, variable So which package should one use? That really depends on the fonts available. Since the Adobe fonts can never be distributed with a TEX installation, they must be actively fetched and installed. However, it is worth doing so, because the European Commission has revised its initial directive and now allows the euro symbol to be typographically matched to the text, which is also standard practice in Europe today. This strengthens the case for the europs package and the \EUR command for €, at least for Roman fonts. 26 Chapter 2. Text, Symbols, and Commands 2.5.9 Typing special symbols directly The commands for producing the special characters and accented letters in the previous sections may be suitable for typing isolated ‘foreign’ words, but become quite tedious for inputting large amounts of text making regular use of such characters. Most computer systems provide non-English keyboards with appropriate fonts for typing these national variants directly. Unfortunately, the coding of such extra symbols is by no means standard, depending very much on the computer system. For example, the text Gauß meets Ampère entered with an MS-DOS editor (code page 437 or 850) appears in a Windows application as Gauá meets AmpŠre and on a Macintosh as Gau· meets Ampäre. Since LATEX is intended to run on all systems, it simply ignores all such extra character codes on the grounds that they are not properly defined. The inputenc package solves this problem. It not only informs LATEX which Package: inputenc input coding scheme is being used, it also tells it what to do with the extra characters. One invokes it with ! \usepackage[code]{inputenc} where code is the name of the coding scheme to be used. The current list of allowed values for code (more are added with each LATEX update) can be found in Table D.1 on page 462. For most users, the most interesting codes are: cp437 cp850 applemac ansinew IBM code page 437 (DOS, North America) IBM code page 850 (DOS, Western Europe) Macintosh encoding Windows ANSI encoding In short, you should select applemac for a Macintosh, and ansinew for Windows, and one of the others if you are working with DOS. Documents making use of this package are fully portable to other computer systems. The source text produced with a DOS editor may still look very strange to a human user reading it on a Macintosh, but when the Macintosh LATEX processes it, the proper DOS interpretations will be applied so that the end result is what the author intended. See Section D.5 for more details. 2.5.10 Ligatures In book printing, certain combinations of letters are not printed as individuals but as a single symbol, a so-called ligature. TEX processes the letter combinations ff, fi, fl, ffi, and ffl not as ff, fi, fl, ffi, ffl but rather as ff, fi, fl, ffi, ffl Ligatures may be broken, that is, forced to be printed as separate letters, by inserting \/ between the letters. This is sometimes desired for such words as shelfful (shelf\/ful), which looks rather strange when printed with the normal ff ligature, shelfful. 2.6. Exercises 27 2.5.11 The date The current date can be placed at any point in the text with the command \today. The standard form for the date is the American style of month, day, year (for example, January 15, 2004). The British form (15th January 2004) or the date in other languages can be generated with the help of the TEX commands \day, \month, and \year, which return the current values of these parameters as numbers. Examples of how such a new \today command may be made are shown on page 461 in Section D.4.2. It is in fact better to enter the date explicitly, rather than to rely on \today. Reprocessing a two-year-old LATEX source file will yield a document with the processing date, not the date when the text was written. 2.6 Exercises Exercise 2.1: This exercise tests the basic operations of running the LATEX program with a short piece of text. A few simple commands are also included. Use a text editor to produce the following source text and store it in a file named exer.tex. \documentclass{article} \begin{document} Today (\today) the rate of exchange between the British pound and American dollar is \pounds 1 = \$1.58, an increase of 1\% over yesterday. \end{document} Process this source file with LATEX by clicking the appropriate icon, or by issuing latex exer in a command window. If the processing occurs without any error messages, the .dvi file exer.dvi will have been successfully created and may be viewed by a dvi previewer or sent to a printer. The final printed result should look as follows except that your current date will appear: Today (January 15, 2004) the rate of exchange between the British pound and American dollar is £1 = $1.58, an increase of 1% over yesterday. Note the following points about the commands used: ˆ no blank is necessary after \today because the ) suffices to terminate it; ˆ the blank after \pounds is optional and it is not printed in the output; ˆ the commands \$ and \% do not require blanks to terminate them; if blanks are given, they will be printed. Exercise 2.2: Take some text of about 3/4 of a page long out of a book or journal article and type it into a LATEX source file. Pay attention that the paragraphs are separated by blank lines. Use the same set of commands as in Exercise 2.1, that is, put the text between the commands \begin{document}...\end{document} and repeat the procedures for obtaining the output. 28 Chapter 2. Text, Symbols, and Commands Exercise 2.3: If you are likely to need the euro symbol in your work, try redoing Exercise 2.1 as follows: \documentclass{article} \usepackage{eurosym} \begin{document} Today (\today) the rate of exchange between the British pound and European euro is \pounds 1 = \euro1.46, an increase of 1\% over yesterday. \end{document} If this fails, try one of the other packages described in Section 2.5.8, substituting \textsf{\texteuro} or \EUR for \euro as required. 2.7 Fine-tuning text The subject of the section concerns pure typographical markup, and has nothing to do with the logical markup that we wish to stress in this book. Unfortunately, there are times when the author or editor does have to help the typesetting program to achieve good appearance. 2.7.1 Word and character spacing The spacing between words and characters is normally set automatically by TEX, which not only makes use of the natural width of the characters but also takes into account alterations for certain character combinations. For example, an A followed by a V does not appear as AV but rather as AV; that is, they are moved together slightly for a more pleasing appearance. Interword spacing within one line is uniform, and is chosen so that the right and left ends match exactly with the side margins. This is called left and right justification. TEX also attempts to keep the word spacing for different lines as nearly the same as possible. Words that end with a punctuation mark are given extra spacing, depending on the character: following a period ‘.’ or exclamation mark ‘!’, there is more space than after a comma ‘,’. This corresponds to the rule in English typesetting that there should be extra spacing between sentences. In certain cases, the automatic procedures do not work properly, or it is desirable to override them, as described in the next sections. Sentence termination and periods TEX interprets a period following a lower case letter to be the end of a sentence where additional interword spacing is to be inserted. This leads to confusion with abbreviations such as i. e., Prof. Jones, or Phys. Rev., where the normal spacing is required. This can be achieved by using the characters ˜ or \ instead of the normal blank. (The character is 2.7. Fine-tuning text 29 simply a symbol for the blank which is otherwise invisible.) Both these methods insert the normal interword spacing; in addition, ˜ is a protected space that prevents the line from being broken at this point. The above examples should be typed in as i.˜e., Prof.˜Jones, and Phys.\ Rev., producing i. e., Prof. Jones, and Phys. Rev. with the correct spacing and forcing the first two to be all on one line. In the third case, there is nothing wrong with putting Phys. and Rev. on different lines. A period following an upper case letter is not interpreted as the end of a sentence, but as an abbreviation. If it really is the end of a sentence, then it is necessary to add \@ before the period in order to achieve the extra spacing. For example, this sentence ends with NASA. It is typed in as This sentence ends with NASA\@. French spacing The additional interword spacing between sentences can be switched off with the command \frenchspacing, which remains in effect until countermanded with \nonfrenchspacing. In this case, the command \@ is ignored and may be omitted. This paragraph has been printed with \frenchspacing turned on, so that all word spacings within one line are the same. It corresponds to the normal rule for non-English typesetting. Character combinations “ ‘ and ’ ” A small spacing is produced with the command \,. This may be used, for example, to separate the double quotes “ and ” from the corresponding single quotes ‘ and ’ when they appear together. For example, the text ‘‘\,‘Beginning’ and ‘End’\,’’ produces “ ‘Beginning’ and ‘End’ ”. Inserting arbitrary spacing Spacing of any desired size may be inserted into the text with the commands \hspace{space} \hspace*{space} where space is the length specification for the amount of spacing, for example 1.5cm or 3em. (Recall that one em is the width of the letter M in the current typeface.) This command puts blank space of width space at that point in the text where it appears. The standard form (without *) has no effect if it should come at the beginning of an output line, just as normal blanks are removed at the beginning of lines. The *-form, on the other hand, inserts the spacing no matter where it occurs. A blank before or after the command will also be included: 30 Chapter 2. Text, Symbols, and Commands This is This is This is This is\hspace{1cm}1cm This is \hspace{1cm}1cm This is \hspace{1cm} 1cm 1cm 1cm 1cm The length specification may be negative, in which case the command works as a backspace for overprinting characters with other ones, or moving them closer together. For example, there is an energy unit in physics called electron volt, abbreviated ‘eV’, which looks much better if the two letters are nearer together, as ‘eV’, with e\hspace{-.12em}V. The command \hfill is an abbreviation for \hspace{\fill} (see Section 2.4.2). It inserts enough space at that point to force the text on either side to be pushed over to the left and right margins. With Left\hfill Right one produces Left Right Multiple occurrences of \hfill within one line will each insert the same amount of spacing so that the line becomes left and right justified. For example, the text Left\hfill Center\hfill Right generates Left Center Right If \hfill comes at the beginning of a line, the spacing is suppressed in accordance with the behavior of the standard form for \hspace. If a rubber space is really to be added at the beginning or end of a line, \hspace*{\fill} must be used instead. However, LATEX also offers a number of commands and environments to simplify most such applications (see Section 4.2.2). A number of other fixed horizontal spacing commands are available: \quad and \qquad The command \quad inserts a horizontal space equal to the current type size, that is, 10 pt for a 10 pt typeface, whereas \qquad inserts twice as much. Inserting variable . . . . . . and sequences Two commands that work exactly the same way as \hfill are \dotfill and \hrulefill Instead of inserting empty space, these commands fill the gap with dots or a ruled line, as follows: Start \dotfill\ Finish\\ and Left \hrulefill\ Center \hrulefill\ Right\\ produce Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Finish Left Center Right 2.7. Fine-tuning text 31 Any combination of \hfill, \dotfill, and \hrulefill may be given on one line. If any of these commands appears more than once at one location, the corresponding filling will be printed that many more times than for a single occurrence. Departure \dotfill\dotfill\dotfill\ 8:30 \hfill\hfill Arrival \hrulefill\ 11:45\\ Departure . . . . . . . . . . . . . . . . . . . . . 8:30 2.7.2 Arrival 11:45 Line breaking Breaking text into lines is done automatically in TEX and LATEX. However, there are times when a line break must be forced or encouraged, or when a line break is to be suppressed. The command \\ A new line with or without additional line spacing can be achieved with the command \\. Its syntax is \\[space] \\*[space] The optional argument space is a length that specifies how much additional line spacing is to be put between the lines. If it is necessary to start a new page, the additional line spacing is not included and the new page begins with the next line of text. The *-form prevents a new page from occurring between the two lines. With \\*[10cm], the current line is ended and a vertical spacing of 10 cm is inserted before the next line, which is forced to be on the same page as the current line. If a page break is necessary, it will be made before the current line, which is then positioned at the top of the new page together with the 10 cm vertical spacing and the next text line. The command \newline is identical to \\ without the option space. That is, a new line is started with no additional spacing and a page break is possible at that point. Both commands may be given only within a paragraph, and not between them where they would be meaningless. Further line-breaking commands The command \linebreak is used to encourage or force a line break at a certain point in the text. Its form is \linebreak[num] 32 Chapter 2. Text, Symbols, and Commands where num is an optional argument, a number between 0 and 4 that specifies how important a line break is. The command recommends a line break, and the higher the number the stronger the recommendation. A value of 0 allows a break where it otherwise would not occur (like in the middle of a word), whereas 4 compels a line break, as does \linebreak without num. The difference between this command and \\ or \newline is that the current line will be fully justified, that is, interword spacing will be added so that the text fills the line completely. With \\ and \newline, however, the line is filled with empty space after the last word and the interword spacing remains normal. The opposite command \nolinebreak[num] discourages a line break at the given position, with num specifying the degree of discouragement. Again, \nolinebreak without a num argument has the same effect as \nolinebreak[4], that is, a line break is absolutely impossible here. Another way of forcing text to stay together on one line is with the command \mbox{text}. This is convenient for expressions such as ‘Voyager-1’ to stop a line break at the hyphen. 2.7.3 Vertical spacing It is possible to add extra vertical spacing of amount space between particular paragraphs using the commands \vspace{space} \vspace*{space} The *-form will add the extra space even when a new page occurs, or when the command appears at the top of a new page. The standard form ignores the extra vertical spacing in these situations. If these commands are given within a paragraph, the extra space is inserted after the current line, which is right and left justified as usual. The space parameter may even be negative, in order to move the following text higher up the page than where it would normally be printed. The command \vfill is an abbreviation for \vspace{\fill} (see Section 2.4.2). This is the equivalent of \hfill for vertical spacing, inserting enough blank vertical space to make the top and bottom of the text match up exactly with the upper and lower margins. The comments on multiple occurrences of \hfill also apply to \vfill. If this command is given at the beginning of a page, it is ignored, just like the standard form of \vspace{\fill}. If a rubber space is to be put at the top of a page, the *-form \vspace*{\fill} must be used. Further commands for increasing the spacing between paragraphs are 2.7. Fine-tuning text \bigskip \medskip 33 \smallskip which add vertical spacing depending on the font size declared in the document class. 2.7.4 Page breaking Breaking text into pages occurs automatically in TEX and LATEX, just as for line breaking. Here again, it may be necessary to interfere with the program’s notion of where a break should take place. Normal pages The commands \pagebreak[num] \nopagebreak[num] are the equivalents of \linebreak and \nolinebreak for page breaking. If \pagebreak appears between two paragraphs, a new page will be forced at that point. If it comes within a paragraph, the new page will be implemented after the current line is completed. This line will be right and left justified as usual. The command \nopagebreak has the opposite effect: between paragraphs, it prevents a page break from occurring there, and within a paragraph, it stops a page break that might take place at the end of the current line. Optional numbers between 0 and 4 express the degree of encouragement or discouragement for a page break. The analogy with the command \linebreak goes further: just as the line before the break is left and right justified with extra interword spacing, in the same way the page before the break is expanded with interline spacing to make it top and bottom justified. The proper command to end a page in the middle, fill it with blank spacing, and go on to a new page is \newpage which is equivalent to \newline with regard to page breaking. Pages with figures and tables If the text contains tables, pictures, or reserved space for figures, these are inserted at the location of the corresponding command, provided that there is enough room for them on the current page. If there is not enough space, the text continues and the figure or table is stored to be put on a following page. The command 34 Chapter 2. Text, Symbols, and Commands \clearpage ends the current page like \newpage and in addition outputs all the pending figures and tables on one or more extra pages (Chapter 7). Two-column pages If the document class option twocolumn has been chosen, or the command \twocolumn is in effect, then the two commands \pagebreak and \newpage end the current column and begin a new one, treating columns as pages. On the other hand, \clearpage and \cleardoublepage (see below) terminate the current page, inserting an empty right column if necessary. Two-sided pages An additional page-breaking command is available when the document class option twoside has been selected: \cleardoublepage which functions exactly the same as \clearpage (the current page is terminated, all pending figures and tables are output) but in addition, the next text will be put on to an odd-numbered page. If necessary, an empty page with an even number is printed to achieve this. Controlling page breaks LATEX provides the possibility of increasing the height of the current page slightly with commands \enlargethispage{size} \enlargethispage*{size} which add the length size to \textheight for this one page only. Sometimes the difference of a few points is all that is necessary to avoid a bad page break. The *-form of the command also shrinks any interline spacing as needed to maximize the amount of text on the page. 2.8 Word division When a line is to be right and left justified, it often turns out that the break cannot be made between whole words without either shoving the text too close together or inserting huge gaps between the words. It is then necessary to split a word. This fundamental task is performed by TEX, the underlying basis of LATEX, by means of a word-dividing algorithm 2.8. Word division 35 that works (almost) perfectly for English text, which is more than can be said for most authors. Nevertheless, even it makes mistakes at times which need to be corrected by human intervention. If normal TEX/LATEX is used for other languages, or if foreign words appear in English text, incorrect hyphenations are very likely to appear. (See Section 2.8.4 and Chapter 11 for more about LATEX with other languages.) In these cases too, something must be done to override TEX’s hyphenation rules, as described below. 2.8.1 Manual hyphenation The simplest way to correct a wrongly divided word is to include a \command at the right place within the word. The word manuscript, for example, will not be hyphenated at all, so if it causes problems with breaking a line, write it as man\-u\-script. This tells TEX to divide the word as necessary either as man-uscript or as manu-script, and to ignore its normal rules. The \- command merely makes hyphenation possible at the indicated locations; it does not force it. If the author absolutely insists in dividing a word at a certain point, say between the u and s in manuscript, he or she can type manu-\linebreak script to achieve this. However, this brute force method is not recommended, because the line break will always occur here even if the text is later changed. For English text, the spelling of a word remains the same when it is hyphenated, something that is not true in other languages. In traditional German spelling, for example, if ck is split, it becomes k-k. TEX allows such behavior with the general hyphenation command \discretionary{before}{after}{without} where before and after are the letters (with hyphen) that come on either side of the break if division takes place, and without is the normal text with no hyphenation. Thus Boris Becker’s name should be typed as Boris Be\discretionary{k-}{k}{ck}er something that one only wants to do in exceptional situations. Incidentally, the \- command is shorthand for \discretionary{-}{}{}. Note: In today’s new German spelling, ck is never split. This reformed spelling is still controversial however. 2.8.2 Hyphenation list Words that are incorrectly hyphenated and that appear frequently within the document can be put into a list of exceptions in the preamble, to avoid laboriously inserting \- every time: 36 Chapter 2. Text, Symbols, and Commands \hyphenation{list} The list consists of a set of words, separated by blanks or new lines, with the allowed division points indicated by hyphens. For example, \hyphenation{man-u-script com-pu-ter gym-na-sium coun-try-man re-sus-ci-tate ... } The list may contain only words with the normal letters a–z, with no special characters or accents. However, if the inputenc package is loaded, then the directly typed letters are also be included in the automatic hyphenation. 2.8.3 Suppressing hyphenation Another means of avoiding bad word divisions is to turn hyphenation off, at least for a paragraph or two. Actually the command \begin{sloppypar} paragraph text \end{sloppypar} does not prevent word division, but does permit larger interword spacings without giving a warning message. This means that practically all lines are broken between words. It is also possible to put the command \sloppy in the preamble or in the current environment to reduce the number of word divisions in the whole document or within the environment scope. This is recommended when the line width is rather narrow. When the command \sloppy is in effect, it is possible to undo it temporarily and to turn hyphenation back on with the command \fussy. 2.8.4 ! Word division with multilingual text Multiple hyphenation lists may be included in the TEX format, making it possible to switch hyphenation schemes within one document, using the TEX command \language. This command may be used as part of language-specific adaptations to translate certain explicit English words in the output (such as ‘Contents’), to simplify accents or punctuation, and to alter the definition of the date command \today. This topic is treated in more detail in Chapter 11. 3 3.1 Document Layout and Organization Document class The first command in the preamble of a LATEX file determines the global processing format for the entire document. Its syntax is: \documentclass[options]{class} where some value of class must be given, while [options] may be omitted if default values are acceptable. The standard values of class, of which one and only one may be given, are: book, report, article, or letter. (The properties of the letter class are explained in Chapter 16.) The basic differences between these classes lie not only in the page layouts, but also in the organization. An article may contain parts, sections, subsections, and so on, while a report can also have chapters. A book also has chapters, but treats even and odd pages differently; also, it prints running heads on each page with the chapter and section titles. Other classes besides the standard ones exist, as contributions for specific journals, or for book projects. These will have their own set of options and additional commands, which should be described in separate documentation or instructions. However, since they are normally modifications of one of the standard classes, most of the following options apply to them too. 3.1.1 Standard class options The options available allow various modifications to be made to the formatting. They can be grouped as follows. Selecting font size The basic font size is selected with one of the options 37 38 Chapter 3. Document Layout and Organization 10pt 11pt 12pt This is the size of the font in which the normal text in the document will be set. The default is 10pt, which means that this is the value assumed if no size option is specified. All other font size declarations are relative to this standard size, so that the section titles, footnotes, and so on will all change size automatically if a different basic font size is selected. Specifying paper size LATEX calculates the text line width and lines per page according to the selected font size and paper mode. It also sets the margins so that the text is centered both horizontally and vertically. In order to do this, it needs to know which paper format is being used. This is specified by one of the following options: letterpaper (11 × 8.5 in) legalpaper (14 × 8.5 in) executivepaper (10.5 × 7.25 in) a4paper (29.7 × 21 cm) a5paper (21 × 14.8 cm) b5paper (25 × 17.6 cm) The default is letterpaper, American letter size paper, 11 × 8.5 in. Normally, the paper format is such that the longer dimension is the vertical one, the so-called portrait mode. With the option landscape the shorter dimension becomes the vertical one, the landscape mode. (One still has to ensure that the output is printed as landscape; see for example page 232.) Page formats The text on the page may be formatted into one or two columns with the options onecolumn twocolumn The default is onecolumn. In the case of the twocolumn option, the separation between the columns as well as the width of any rule between them may be specified by \columnsep and \columnseprule, described below. The even- and odd-numbered pages may be printed differently according to the options oneside twoside With oneside, all pages are printed the same; however, with twoside, the running heads are such that the page number appears on the right on odd 3.1. Document class 39 pages and on the left on even pages. It does not force the printer to output double-sided. The idea is that when these are later printed back-to-back, the page numbers are always on the outside where they are more easily noticed. This is the default for the book class. For article and report, the default is oneside. With the book class, chapters normally start on a right-hand, odd-numbered page. The options openright openany control this feature: with openany a chapter always starts on the next page, but with openright, the default, a blank page may be inserted if necessary. Normally the title of a book or report will go on a separate page, while for an article, it is placed on the same page as the first text. With the options notitlepage titlepage this standard behavior may be overruled. See Sections 3.3.1 and 3.3.2. Further options The remaining standard options are: leqno Equation numbers in displayed formulas will appear on the left instead of the normal right side (Section 5.1). fleqn Displayed formulas will be set flush left instead of centered (Section 5.1). The amount of indentation may be set with the parameter \mathindent described below. openbib The format of bibliographies may be changed so that segments are set on new lines. By default, the texts for each entry are run together. draft If the LATEX line-breaking mechanism does not function properly and text must stick out into the right margin, then this is marked with a thick black bar, to make it noticeable. final The opposite of draft, and the default. Lines of text that are too wide are not marked in any way. If multiple options are to be given, they are separated by commas, as for example, \documentclass[11pt,twoside,fleqn]{article}. The order of the options is unimportant. If two conflicting options are specified, say oneside and twoside, it is not obvious which one will be effective. That depends entirely on the definitions in the class file itself, so it would be best to avoid such situations. 40 Chapter 3. Document Layout and Organization Parameters associated with some options Some options make use of parameters that have been given certain default values: \mathindent specifies the indentation from the left margin for the equation numbers when fleqn is selected (Section 5.1); \columnsep specifies the space between the two columns for the twocolumn option (see Figure H.2 on page 603); \columnseprule determines the width of the vertical line between the two columns for the twocolumn option. The default is zero width, that is, no vertical rule (see Figure H.2). The standard values of these parameters may be changed with the LATEX command \setlength. For example, to change \mathindent to 2.5 cm, give \setlength{\mathindent}{2.5cm} These parameters may be assigned values either in the preamble or at any place in the document. Parameters in the preamble apply to the entire document, whereas those within the text are in effect until the next change or until the end of the environment in which they were made (Section 2.3). In the latter case, the previous values become effective once more. Exercise 3.1: Take your text file from Exercise 2.2 and change the initial command \documentclass{article} first to \documentclass[11pt]{article} and then to \documentclass[12pt]{article} and print the results of each LATEX processing. Compare the line breaking of these outputs with that of Exercise 2.2. Note: if there are some improper word divisions, you call tell LATEX where the correct division should occur with the command \-, for example, man\-u\-script. (This is one of the few words that the TEX English word divider does not handle properly.) Additional means of modifying word division are given in Section 2.8. If there are warnings of the sort Overfull \hbox ... during the LATEX processing, TEX was not able to break the lines cleanly. In the output, these lines will extend beyond the right margin. The usual cause is that TEX was not able to divide some word, either because it is indivisible or because TEX’s word division routines were not adequate. Here again a suggested hyphenation in the text can solve the problem. Other solutions will be given shortly. Exercise 3.2: Now employ \documentclass[twocolumn]{article} in your text file. If you now receive a number of warnings with Underfull \hbox ..., then these lines will indeed be left and right justified but will have too much empty 3.1. Document class 41 space between the words. Check the output yourself to see whether the word spacing is acceptable. If not, try giving some hyphenation suggestions in the first words of the next line. Note: if you use the classes book or report instead of article in the preceding exercises, you will notice no difference in the outputs. These classes affect the subsequent structural elements of the document. Basically, you should use article for short articles (say 10–20 pages) and report for longer reports that are to be organized into chapters. The chapters always begin on a new page. The class book is available for producing books. 3.1.2 Loading packages In Section 1.5.3 we explained how LATEX can be extended by packages which are either part of the core installation or contributed by engaged users. How to write your own packages is described in Appendix D. A package is nothing more than a set of LATEX (or TEX) commands stored in a file with the extension .sty, although there are some special commands that may only appear within them. To invoke a package, simply call \usepackage{package} in the preamble, where package is the root name of the file. More than one package may be loaded with one call to \usepackage. For example, two packages provided with standard LATEX are stored in files makeidx.sty (Section 9.4.3) and ifthen.sty (Section 8.3.5). They may be read in together with \usepackage{makeidx,ifthen} A package may have options associated with it, which may be selected in the same way as for document classes: by including the option names within square braces. The general syntax is thus: \usepackage[opt1,opt2. . . ]{package1,package2,. . . } where all the listed options will be applied to all the selected packages. If any of the packages does not understand one of the options, a warning message is output to the monitor. 3.1.3 ! Global and local options One interesting feature about options specified with the \documentclass command is that they also apply to any packages that follow. This means that if several packages all take the same option, it is only necessary to declare it once in \documentclass. For example, one might design a package to modify article for generating a local house style that might do different things for single or double column text; this package could make use of the class options onecolumn and twocolumn to achieve this. Or it could elaborate on the draft 42 Chapter 3. Document Layout and Organization option to produce double line spacing, as for a manuscript. Alternatively, several packages might have language-dependent features that could be activated with options like french or german; it is sufficient to list such options only in \documentclass to apply them to all packages. Such options are called global, for they are passed on to all subsequent packages automatically. Global options need not be limited to the standard class options listed in Section 3.1.1. A warning message is printed only if neither the class nor any of the packages understand one or more of them. By contrast, any options specified with \usepackage will be applied only to those packages listed in that one command; and it is applied to all of them. A warning is printed if one or more of those packages does not recognize any one of these local options. 3.1.4 ! 3.2 Class and package versions Class and package files normally have an internal version specification in the form of their release date, as yyyy/mm/dd. If you wish to make use of some feature that you know was added on a certain date, you include that date in square brackets after the class or package name. An example of this is shown in Section 3.2.4 on page 46. The version date may also be added to the \documentclass command to ensure that the right version of the class file is being employed. The reason for doing this is to ensure that the source files are processed properly, say on other systems. Page style The basic page format is determined by the page style. With one exception, this command is normally given in the preamble. Its form is: \pagestyle{style} The mandatory argument style takes on one of the following values: plain The page head is empty, the foot contains the centered page number. This is the default for the article and report classes when no \pagestyle is given in the preamble. empty Both head and footlines are empty; no page numbers are printed. headings The head contains the page number as well as title information (chapter and section headings); the foot is empty. This is the default for book class. myheadings The same as headings except that the page titles in the head are not chosen automatically but rather are given explicitly by the commands \markright or \markboth (see below). 3.2. Page style 43 The command \thispagestyle{style} functions exactly as \pagestyle except that it affects only the current page. For example, the page numbering may be suppressed for just the current page with the command \thispagestyle{empty}. It is only the printing of the page number that is suppressed; the next page will be numbered just as though the command had never been given. 3.2.1 Heading declarations For the page styles headings and myheadings, the information appearing in the headline may be given with the declarations \markright{right head} \markboth{left head}{right head} The declaration \markboth is used with the document class option twoside, with even-numbered pages considered to be on the left and odd-numbered pages on the right. Furthermore, the page number is printed on the left side of the head for a left page and on the right side for a right page. For one-sided output, all pages are considered to be right-handed. In this case, the declaration \markright is appropriate. It may also be used with two-sided output to overwrite the right head given in \markboth. With the page style headings, the standard titles in the page headline are the chapter, section, or subsection headings, depending on the document and page style, according to the following scheme: Style Left Page Right Page book, report one-sided two-sided — Chapter Chapter Section article one-sided two-sided — Section Section Subsection If there are more than one \section or \subsection on a page, it is the heading of the last one that appears in the page head. 3.2.2 Customized head and footlines Package: fancyhdr The standard page styles described in Section 3.2 select how the head and footlines are to appear, and what information they contain. This is a very limited choice, and the fancyhdr package by Piet van Oostrum offers the user considerable more flexibility. This package makes available an additional page style named fancy which the user can easily redefine. Head and footlines consist each of 44 Chapter 3. Document Layout and Organization three parts, left, center, right, each of which can be individually defined with \lhead{Left head} \lfoot{Left foot} \chead{Center head} \rhead{Right head} \cfoot{Center foot} \rfoot{Right foot} where the various texts may be explicit, or a command like \thepage to print the current page number. Both head and footlines may be decorated with a rule, the widths of which are set by commands \headrulewidth and \footrulewidth. By default, the fancy head and footlines are much the same as for the headings page style, but the head rule is set to 0.4 pt and the foot rule set to 0 (no rule). The rules may be redefined with, for example, \renewcommand{\footrulewidth}{0.4pt} to turn the foot rule on. The above defining commands are in fact specific examples of the more general commands \fancyhead and \fancyfoot, where \lhead{..} is \fancyhead[L]{..} \cfoot{..} is \fancyfoot[C]{..} and so on, with L C R standing for ‘left’, ‘center’, ‘right’. For two-sided output with the twoside option, one normally wants the left and right parts to alternate with page number. The easiest way to do this is with \fancyhead[LE,RO]{Text 1} \fancyhead[LO,RE]{Text 2} to put the same Text 1 in the left part of even pages, and right part of odd pages, and Text 2 for the other way round. With \fancyhead{}, all head line parts are set to blanks, something that should be done before resetting them explicitly. Similarly \fancyfoot{} sets all foot entries to blank. The default (two-sided) definitions for the fancy page style are \fancyhead[EL,OR]{\textsl{\rightmark}} \fancyhead[ER,OL]{\textsl{\leftmark}} where \rightmark and \leftmark contain the automatic texts for the headings page style generated by the \chapter, \section, \subsection commands (Section 3.3.3), while \textsl (Section 4.1.4) sets its argument in a slanted typeface. The user may also make use of these to redefine the head line with automatic texts. There is also the most general \fancyhf command taking optional arguments [H] and [F] to apply to head or footlines. Thus \fancyhf[HL] {..} is the same as \fancyhead[L]{..}. Clearly, \fancyhf{} resets everything. 3.2. Page style 45 In many classes, the first page of a chapter, or the very first page of the document, is switched to plain automatically. If the user wants to change this, he or she must redefine that page style. The fancyhdr package simplifies this task with \fancypagestyle{plain}{definitions} where definitions consist of \fancyhead, \fancyfoot, and/or rule redefinitions that are to apply to the revised plain style. In fact, any existing page style can be redefined in this way. 3.2.3 Page numbering The declaration that specifies the style of the page numbering has the form \pagenumbering{num style} The allowed values of num style are: arabic for normal (Arabic) numerals, roman for lower case Roman numerals, Roman for upper case Roman numerals, alph for lower case letters, Alph for upper case letters. The standard value is arabic. This declaration resets the page counter to 1. In order to paginate the foreword of a document with Roman numerals and the rest with Arabic numbers beginning with page 1 for chapter 1, one must declare \pagenumbering{roman} at the start of the foreword and then reset the page numbering with \pagenumbering{arabic} immediately after the first \chapter command. (See Section 3.3.5 for the preferred method.) Pages may be numbered starting with a value different from 1 by giving the command \setcounter{page}{page num} where page num is the number to appear on the current page. Exercise 3.3: Expand your exercise text file so that it fills more than one page of output and include the following preamble: \documentclass{article} \pagestyle{myheadings} \markright{Exercises} \pagenumbering{Roman} \begin{document} 46 Chapter 3. Document Layout and Organization 3.2.4 Paragraph formatting The following parameters affect the appearance of a paragraph and may be given new values with \setlength as explained in Section 8.2: \parskip The distance between paragraphs, expressed in units of ex so that it will automatically change with character font size. This should be a rubber length. \parindent The amount of indentation for the first line of a paragraph. \baselinestretch This is a number that magnifies the normal distance between baselines, the line on which the letters sit. This number is initially 1, for standard line spacing. It may be changed to another number with \renewcommand{\baselinestretch}{factor} where factor is any decimal number, such as 1.5 for a 50% increase. This then applies to all font sizes. If this command is given outside the preamble, it does not come into effect until another font size has been selected (Section 4.1.2). These parameters may be set either in the preamble or anywhere in the text of the document. In the latter case, the changes remain in effect until the next change or until the end of the environment in which they were made (Section 2.3). To suppress indentation for one paragraph, or to force it where it would otherwise not occur, place \noindent or \indent at the beginning of the paragraph to be affected. Normally, the first paragraph of a section is not indented, not even with \indent. However, by including the package indentfirst one ensures that all paragraphs are indented. By default, LATEX indicates paragraphs by indenting the first line. Package: parskip An alternative is without indentation but with extra spacing between paragraphs. One could redefine \parindent and \parskip accordingly, or one could employ one of the oldest and simplest packages dating back to LATEX 2.09 days: parskip, written by H. Partl. For consistency, this package also makes some changes in the parameters for lists (Section 4.3). One loads this package with Package: indentfirst \usepackage{parskip} 3.2. Page style 47 There is a recent update to the parskip package by Robin Fairbairns that includes the option parfill, given as \usepackage[parfill]{parskip} that avoids ugly-looking rectangular paragraphs by ensuring that there is always space at the end of the last line. This update is dated April 9, 2001, so to be sure that this package version is loaded, add this date as \usepackage[parfill]{parskip}[2001/04/09] as explained in Section 3.1.4. A warning will be issued on processing if the actual version of parskip is earlier than this. There will also be warning about the unknown option parfill. Exercise 3.4: Add the following to the preamble of your exercise file: \usepackage{parskip} \renewcommand{\baselinestretch}{1.2} After processing this exercise, repeat it with another value for the parameter \baselinestretch, say 1.5, in order to get a feeling for how it works. Remove these lines from the exercise file afterwards. 3.2.5 Page format Each page consists of a head, the body containing the actual text, and a foot. The selection of the page style determines what information is to be found in the head and footlines. LATEX uses default values for the distances between the head, body, and foot, for the upper and left margins, and for the text line width and heights of the head, body, and foot. These formatting lengths are illustrated in Figure 3.1 on the next page. They may be changed by declaring new values for them, preferably in the preamble, with the command \setlength (Section 8.2). For example, give \setlength{\textwidth}{12.5cm} to make the text line width to be 12.5 cm. There is also a parameter \linewidth equal to the text line width in whatever environment one is currently in. This must never be changed, but is used when one needs to know this width. More detailed diagrams of the page formats for one- and two-column outputs are shown at the end of Appendix H in Figures H.1 and H.2. Package: You can examine your own page layout with the layout package from layout the tools collection. Simply issue the command \layout and a diagram similar to that in Figure 3.1 will be drawn at that point, together with a list of the current values of the layout parameters. Naturally, you would not do this in the middle of the final version of a document, but only as diagnostic check. Chapter 3. Document Layout and Organization 1 inch 6 • 6 ?  1 inch \oddsidemargin left margin for odd pages, \evensidemargin left margin for even pages, \topmargin upper margin to top of head, \headheight height of head, \headsep distance from the bottom of headline to top of body, \topskip distance from top of body to baseline of first line of text, \textheight, \textwidth height and width of main text, \footskip distance from bottom of body to bottom of foot, \paperwidth, \paperheight total width and height of paper as given by paper size option, including all margins. \paperheight 48 \topmargin ? \headheight Head 6 ? \headsep ? 6 \topskip ? First line of text Body  - \textheight 6 \textwidth ?  \oddsidemargin \evensidemargin Foot ?  \paperwidth \footskip ? - Figure 3.1: Page layout parameters ! ! In order to calculate the page layout precisely, one must realize that LATEX measures all distances from a point one inch from the top of the paper and one inch from the left edge. Thus the total left margin is \oddsidemargin plus one inch. The LATEX parameters \paperwidth and \paperheight, which include this extra inch, are given their values by the paper size option in the \documentclass command; they are used internally to calculate the margins so that the text is centered. The user may also take advantage of them for calculations. With document class book or with the option twoside, the bottom edge of the body will always appear at exactly the same position on every page. In the other classes or options, it will vary slightly. In the first two cases, the constant bottom edge is produced by the internal command \flushbottom, whereas the varying bottom is produced by the command \raggedbottom. The user may apply these declarations to change the behavior of the bottom edge at any time, independent of document class and options. Exercise 3.5: You can change the page format of your text by altering the above parameters. Add the following to the preamble of your text: \setlength{\textwidth}{13cm} \setlength{\textheight}{20.5cm} The upper and left margins of your output will now seem too small. Select new values for \oddsidemargin and \topmargin to correct this. Note: do not 3.2. Page style 49 forget the 1 inch margin at the left and top from which additional margins are measured. You must take this into account when you select \oddsidemargin and \topmargin. Exercise 3.6: Expand your text so that the output requires more than two full pages with the reduced page format. Add \flushbottom to the preamble and check that the last line of all pages is at exactly the same location. Exercise 3.7: Remove the command \flushbottom and select the document class \documentclass[twoside]{article}. Now the last lines are at the same location without the \flushbottom command. On the other hand, the left margin of the odd pages probably does not agree with the right margin of the even pages. Adjust the value of \evensidemargin to correct this. 3.2.6 Simplified page formatting Package: geometry Getting the page layout to be exactly the way you want it can be very tedious. Just centering the text on the page involves a complex set of settings that are not at all intuitive. The geometry package by Hideo Umeki offers considerable assistance. With this package, one can easily give values for some of the layout parameters, and the rest will be set automatically, taking into account the total paper size. For example, to set \textwidth to 15 cm and \textheight to 25 cm on A4 paper, one gives \usepackage{geometry} \geometry{a4paper,textwidth=15cm,textheight=25cm} which will also automatically set \oddsidemargin and \topmargin so that the text is centered horizontally and vertically, including the head and footlines. Or, one can set all the margins to be 1 inch on US letter paper with \geometry{letterpaper,margin=1in} Rather than using the \geometry command, one may also place the parameters as options to \usepackage, for example as \usepackage[a4paper,left=3cm,right=2cm]{geometry} to set the left and right margins to definite values, and \textwidth to what is left over. In general, all the parameters in Figure 3.1 may be specified by geometry by giving their names (without the backslash character). However, the package is far more powerful than that. Here we describe the essential features of version 2.3 from 2000/06/28. • The paper size is either inherited from the \documentclass option, given as a predefined option like a4paper, given explicitly as 50 Chapter 3. Document Layout and Organization paperwidth=pwidth and paperheight=pheight, or as papersize= {pwidth,pheight}. • By default, the other layout parameters are set so that \textwidth is 80% of \paperwidth and \textheight + \headheight + \headsep + \footskip is 90% of \paperheight, centered horizontally and vertically. • The text width and height may be set explicitly with width=width and height=height, or with body={width,height}. The margins are then set to center. Here height means total text height including head and footlines. • Margins may be explicitly given with left=lmarg and right=rmarg, or with hmargin={lmarg,rmarg}. Similarly with top=tmarg and bottom=bmarg, or vmargin={tmarg,bmarg}. If only one value of a pair is given, the other is set to that same value, unless the corresponding text height or width has been given explicitly. All margins may be set to a common value with margin=marg. Unlike LATEX standard \oddsidemargin and \topmargin, geometry’s margins are measured from the edge of the paper, and not from a point 1 inch removed. • With nohead, nofoot, noheadfoot, one tells geometry not to include the corresponding head or footline in the height calculation. Thus with noheadfoot, the total height is identical to \textheight. • With includemp, the marginal note parameters \marginparwidth and \marginparsep (Section 4.10.5) are included in the total width calculation, which is then less than \textwidth. With reversemp, the marginal notes appear in the left margin. • The text width and height may be set to a fraction of the paper size with hscale=h and vscale=v, or scale={h,v}. With scale=s, both h and v are set to s. For example, \geometry{scale=0.8} sets width and height to 80% of \paperwidth and \paperheight respectively. • For two-sided output, add the option twoside. In this case, the values of the left and right margins will switch for even page numbers. In addition, a quantity of 20 pt is added to and subtracted from the left margin of odd and even pages, respectively. This value may be changed with twosideshift=shift, which also sets the twoside option automatically. • With the verbose option, the calculated values of all the layout parameters are printed to the monitor and to the transcript file. 3.2. Page style 51 As you see, the geometry package is an enormous aid to setting the page layout, working fairly intuitively, automatically setting values for the unspecified parameters in a way that is normally what one would want anyway. There are many more aspects explained in the accompanying documentation, but the above synopsis should cover most requirements. 3.2.7 Single and double column pages The document class option twocolumn sets the entire document in two columns per page. The default is one column per page. Individual pages may be output in one or two columns with the declarations: \twocolumn[header text] Terminates the current page, starting a new one with two columns per page. The optional header text is written at the top of the page in one column with the width of the whole page. \onecolumn Terminates the current two-column page and continues with one column per page. ! ! ! The option twocolumn automatically changes certain page style parameters, such as indentation, compared with the one-column format. This does not occur with the command \twocolumn. These additional changes must be made with the corresponding \setlength declarations if they are desired. If the bulk of the document is in two-column format, the class option is to be preferred. An additional page style parameter is \columnwidth, the width of one column of text. For single column text, this is the same as \textwidth, but when twocolumn has been selected, LATEX calculates it from the values of \textwidth and \columnsep. The author should never change this parameter, but he or she may make use of it, for example to draw a rule the width of a column of text. The length \linewidth is even more general, always containing the text line width in the current environment, minipage, parbox. Within a single column, it is the same as \columnwidth. It too may never be changed. 3.2.8 Multicolumn text Package: multicol The commands \twocolumn and \onecolumn always start a new page, and when two-column text is terminated, the two columns are of unequal length. These problems are solved with the multicol package in the tools collection, written by Frank Mittelbach, which also allows up to 10 columns of text. Once this package has been loaded, one can switch the number of columns in the middle of a page with \begin{multicols}{num cols}[header text][pre space] Text set in num cols columns \end{multicols} 52 Chapter 3. Document Layout and Organization where the optional header text is written across all the columns before switching to multicolumns. Some automatic control for page breaking before and after switching to multicolumns is offered by the two lengths \premulticols and \postmulticols: if the remaining space on the current page is less than \premulticols, a new page is started before switching to multicolumns. Similarly, if at the end of the environment, there is less than \postmulticols on the page, a page break is inserted before continuing. The standard values of these lengths may be altered by the user with \setlength, or in the case of \premulticols may be overridden by the second optional argument pre space. The lengths \columnsep and \columnseprule that apply to twocolumn texts are also in effect for the multicols environment, to set the widths of the gap between columns and a possible separating rule, respectively. There is also a starred version \begin{multicols*}{num cols}. . . \end{multicols*} for which the columns on the last page are not balanced, with all the remaining space put into the final column. 3.3 Parts of the document Every document is subdivided into chapters, sections, subsections, and so on. There can be an appendix at the end and at the beginning a title page, table of contents, an abstract, etc. LATEX has a number of markup commands available to indicate these structures. In addition, sequential numbering and sub-numbering of headings take place automatically. Even a table of contents may be produced with a single command. The effects of some sectioning commands depend on the selected document class and not all commands are available in every class. 3.3.1 Title page A title page can be produced either unformatted with the environment \begin{titlepage} Title page text \end{titlepage} or with the commands \title{Title text} \author{Author names and addresses} \date{Date text} \maketitle in the preprogrammed LATEX style. In the standard LATEX layout for the title page, all entries are centered on the lines in which they appear. If the title is too long, it will be broken 3.3. Parts of the document 53 \title{% How to Write DVI Drivers} \author{% Helmut Kopka\thanks{Tel. [+49] 5556--401--451}\\ Max--Planck--Institut\\ f\"ur Aeronomie \and Phillip G. Hardy \thanks{Tel. [+1] 319--824--7134}\\ University\\of Iowa} How to Write DVI Drivers Helmut Kopka1 Max–Planck–Institut für Aeronomie Phillip G. Hardy2 University of Iowa January 15, 2004 \maketitle 1 Tel. [+49] 5556–401–451 2 Tel. [+1] 319–824–7134 Figure 3.2: Sample title page and the text that produced it up automatically. The author may select the break points himself with the \\ command, that is, by giving \title{...\\...\\...}. If there are several authors, their names may be separated with \and from one another, such as \author{G. Smith \and J. Jones}. These names will be printed next to each other in one line. The sequence \author{Author1\\Institute1\\Address1 \and Author2\\Institute2\\Address2} separately centers the entries, one per line, in each of the sets Author1, Institute1, Address1 and Author2, Institute2, Address2 and places the two blocks of centered entries beside each other on the title page. Instead of printing the author names next to each other, one may position them on top of one another by replacing \and with the \\ command. In this case, the vertical spacing may be adjusted with an optional length specification [space] following the \\. If the command \date is omitted, the current date is printed automatically below the author entries on the title page. On the other hand, the command \date{Date text} puts the text Date text in place of the current date. Any desired text may be inserted here, including line break commands \\ for more than one line of centered text. 54 Chapter 3. Document Layout and Organization The command \thanks{Footnote text} may be given at any point in the title, author, or date text. This puts a marker at that point where the command appears and writes footnote text as a footnote on the title page. The title page is created using the entries in \title, \author, \date, and \thanks when the command \maketitle is issued. The title page itself does not possess a page number and the first page of the following document is number 1. (For book, the page numbering is controlled by the special commands in Section 3.3.5.) A separate title page is only produced for document classes book and report. For article, the command \maketitle creates a title heading on the first page using the centered entries from the \title, \author, and, if present, \date and \thanks declarations. If the document class option titlepage has been given, the title appears on a separate page even for the article class. An example of a title page in the standard LATEX format is shown in Figure 3.2 on the previous page. Note that the current date appears automatically since the command \date is missing in the definition of the title page. This command may be used to put any desired text in place of the date. For the unformatted title page produced with the titlepage environment, the commands \title and \author are left out and the entire title page is designed according to the author’s specifications within the environment. To this end he or she may make use of all the structuring commands described in Chapter 4. In this case the printing of the title page is implemented at the end of the titlepage environment, so the command \maketitle is also left out. Exercise 3.8: Remove the declarations for changing the page format in Exercises 3.5–3.7. Add to your exercise text a title heading with the title ‘Exercises’, your name as author, and your address, together with a date entry in the form ‘place, date’. To do this, write the following commands after \begin{document}: \title{Exercises} \author{Your name\\Your address} \date{Your town, \today} \maketitle Make sure that you have selected document class article. After printing the document, change the document class command to \documentclass[titlepage]{article} to put the title information on to a title page instead of a title heading. Deactivate these commands by putting the comment character % at the beginning of each of the lines. In this way you avoid getting a title page in the following exercises but you can easily reactivate the commands simply by removing the % characters. 3.3. Parts of the document 3.3.2 55 Abstract The abstract is produced with the command \begin{abstract} Text for the abstract \end{abstract} In document class report, the abstract appears on a separate page without a page number; in article, it comes after the title heading on the first page, unless the document class option titlepage has been selected, in which case it is also printed on a separate page. An abstract is not possible in document class book. 3.3.3 Sections The following commands are available for producing automatic, sequential sectioning: \part \chapter \section \subsection \subsubsection \paragraph \subparagraph With the exception of \part, these commands form a sectioning hierarchy. In document classes book and report, the highest sectioning level is \chapter. The chapters are divided into sections using the \section command, which are further subdivided by means of \subsection, and so on. In document class article, the hierarchy begins with \section since \chapter is not available. The syntax of all these commands is \sec command[short title]{title} \sec command*{title} or In the first case, the section is given the next number in the sequence, which is then printed together with a heading using the text title. The text short title becomes the entry in the table of contents (Section 3.4) and the page head (provided that page style headings has been selected). If the optional short title is omitted, it is set equal to title; this is the normal situation unless title is too long to serve for the other entries. In the second (*-form) case, no section number is printed and no entry in the table of contents is made (however, see Section 3.4.3). The size of the title heading and the depth of the numbering depend on the position of the sectioning command within the hierarchy. For document class article, the \section command generates a single number (say 7), the \subsection command a double number with a period between the two parts (say 7.3), and so on. In document classes book and report, the chapter headings are given a single number with the \chapter command, the \section command creates the double number, and so on. Furthermore, the command \chapter always starts a new page and prints Chapter n over the chapter title, where 56 Chapter 3. Document Layout and Organization n is the current chapter number. At this point in the present book, we are in Chapter 3, Section 3.3, Subsection 3.3.3. For each sectioning command there is an internal counter that is incremented by one every time that command is called, and reset to zero on every call to the next higher sectioning command. These counters are not altered by the *-forms, a fact that can lead to difficulties if standard and *-forms of the commands are mixed such that the *-forms are higher in the hierarchy than the standard forms. There are no problems, however, if the *-forms are always lower than the standard forms. The sequence \section ... \subsection ... \subsubsection* ... numbers the headings for \section and \subsection while leaving the headings for \subsubsection without any numbering. The sectioning command \part is a special case and does not affect the numbering of the other commands. The automatic numbering of sections means that the numbers might not necessarily be known at the time of writing. The author may be writing them out of their final order, or might later introduce new sections or even remove some. If he or she wants to refer to a section number in the text, some mechanism other than typing the number explicitly will be needed. The LATEX cross-reference system, described in detail in Section 9.2.1, accomplishes this task with the two basic commands \label{name} \ref{name} the first of which assigns a keyword name to the section number, while the second may be used as reference in the text for printing that number. The keyword name may be any combination of letters, numbers, or symbols. For example, in this book the command \label{sec:xref} has been typed in at the start of Section 9.2.1, so that this sentence contains the input text at the start of Section \ref{sec:xref}. A second referencing command is \pageref for printing the page number where the corresponding \label is defined. The referencing commands may be used in many other situations for labeling items that are numbered automatically, such as figures, tables, equations. ! Every sectioning command is assigned a level number such that \section is always level 1, \subsection level 2, . . . \subparagraph level 5. In document class article, \part is level 0 while in book and report classes, \part is level −1 and \chapter becomes level 0. Section numbering is carried out down to the level given by the number secnumdepth. This limit is set to 2 for book and report, and to 3 for article. This means that for book and report, the section numbering extends only to the level of \subsection and for article to \subsubsection. In order to extend (or reduce) the level of the section numbering, it is necessary to change the value of secnumdepth. This is done with the command \setcounter{secnumdepth}{num} 3.3. Parts of the document 57 (The command \setcounter is explained in Section 8.1.) In article, num may take on values from 0 to 5, and in book and report from −1 to 5. It is possible to change the initial value of a sectioning command within a document with the command \setcounter{sec name}{num} where sec name is the name of the sectioning command without the preceding \ character. This procedure may be useful when individual sections are to be processed by LATEX as single files. For example, \setcounter{chapter}{2} sets the \chapter counter to 2. The counter will be incremented on the next call to \chapter which then produces Chapter 3. 3.3.4 Appendix An appendix is introduced with the declaration \appendix It has the effect of resetting the section counter for article and the chapter counter for book and report and changing the form of the numbering for these sectioning commands from numerals to capital letters A, B, . . . . Furthermore, the word ‘Chapter’ is replaced by ‘Appendix’ so that subsequent chapter headings are preceded by ‘Appendix A’, ‘Appendix B’, etc. The numbering of lower sectioning commands contains the letter in place of the chapter number, for example A.2.1. 3.3.5 Book structure To simplify the structuring of a book, the commands \frontmatter preface, table of contents \mainmatter main body of text \backmatter bibliography, index, colophon are provided in the book class. The \frontmatter command switches page numbering to Roman numerals and suppresses the numbering of chapters; \mainmatter resets the page numbering to 1 with Arabic numbers and reactivates the chapter numbering; this is once again turned off with \backmatter. Exercise 3.9: Insert at the beginning of your exercise text the command \section{Title A} and at some appropriate place near the middle \section{Title B}. Select some suitable text for Title A and Title B. Insert at appropriate places 58 Chapter 3. Document Layout and Organization some \subsection commands with reasonable subtitles. Remove the commands included from Exercise 3.3: \pagestyle{myheadings} \markright{Exercises} \pagenumbering{Roman} and print the results. Exercise 3.10: Include the additional command \chapter{Chapter title} with your own appropriate Chapter title before your first \section command. Change the document class command to \documentclass[twoside]{report} and call the page style command \pagestyle{headings} in the preamble. Note the twofold effect of the sectioning commands in the headings and in the page headlines. Compare the results with the table in Section 3.2.1. Exercise 3.11: Change the chapter command to \chapter[Short form]{Chapter title} by putting an abbreviated version of Chapter title for Short form. Now the page head contains the shortened title where the full chapter title previously appeared. 3.4 Table of contents 3.4.1 Automatic entries LATEX can prepare and print a table of contents automatically for the whole document. It will contain the section numbers and corresponding headings as given in the standard form of the sectioning commands, together with the page numbers on which they begin. The sectioning depth to which entries are made in the table of contents can be set in the preamble with the command \setcounter{tocdepth}{num} The value num has exactly the same meaning and effect as it does for the counter secnumdepth described above, by which the maximum level of automatic subsectioning is fixed. By default, the depth to which entries are included in the table of contents is the same as the standard level to which automatic sectioning is done: that is, to level \subsection for book and report and to level \subsubsection for article. 3.4.2 Printing the table of contents The table of contents is generated and printed with the command \tableofcontents 3.4. Table of contents 59 given at the location where the table of contents is to appear, which is normally after the title page and abstract. This leads to a paradox, for the information in the table of contents is to be printed near the beginning of the document, information that cannot be known until the end. LATEX solves this problem as follows: the first time the document is processed, no table of contents can be included but instead LATEX opens a new file with the same name as the source file but with the extension .toc; the entries for the table of contents are written to this file during the rest of the processing. The next time LATEX is run on this document, the \tableofcontents command causes the .toc file to be read and the table of contents is printed. As the processing continues, the .toc file is updated in case there have been major changes since the previous run. This means that the table of contents that is printed is always the one corresponding to the previous version of the document. For this reason, it may be necessary to run LATEX more than once on the final version. 3.4.3 ! Additional entries The *-form sectioning commands are not entered automatically in the table of contents. To insert them, or any other additional entry, the commands \addcontentsline{toc}{sec name}{entry text} \addtocontents{toc}{entry text} may be used. With the first command, the entries will conform to the format of the table of contents, whereby section headings are indented more than those for chapter but less than those for subsection. This is determined by the value of the argument sec name, which is the same as one of the sectioning commands without the \ character (for example, section). The entry text is inserted in the table of contents along with the page number. This command is most useful to enter unnumbered section headings into the table of contents. For example, \section*{Author addresses} \addcontentsline{toc}{section}{Author addresses} The \addtocontents command puts any desired command or text into the .toc file. This could be a formatting command, say \newpage, which takes effect when the table of contents is printed. 3.4.4 ! Other lists In addition to the table of contents, lists of figures and tables can also be generated and printed automatically by LATEX. The commands to produce these lists are \listoffigures reads and/or produces file.lof \listoftables reads and/or produces file.lot 60 Chapter 3. Document Layout and Organization The entries in these lists are made automatically by the \caption command in the figure and table environments (see Section 7.4). Additional entries are made with the same commands as for the table of contents, the general form of which is \addcontentsline{file}{format}{entry} \addtocontents{file}{entry} where file stands for one of the three types toc (table of contents), lof (list of figures), or lot (list of tables). The argument format is one of the sectioning commands for the table of contents, as described above, or figure for the list of figures, or table for the list of tables. The argument entry stands for the text that is to be inserted into the appropriate file. Exercise 3.12: In your exercise file, insert after the deactivated title page commands \pagenumbering{roman} \tableofcontents \newpage \pagenumbering{arabic} Process your exercise file twice with LATEX and print out the second results. Deactivate the above commands with % before doing the next run. Displayed Text 4 There are a variety of ways to display or emphasize the text: changing font style or font size, centering, indentation, marking the paragraphs, and so on. LATEX supplies us with commands for the most common forms of display. Many parts of this chapter violate the concept of logical markup, especially those dealing with selection of fonts. The author should not attempt to decorate the document with arbitrary switches of font size and style, but should pack his or her source text into a structure that indicates its purpose. The exercises in this book are an example of this. Rather than starting each one with the word ‘Exercise’ in bold face followed by an explicit number, and then shifting to a slanted font, we defined an exercise environment to do all that automatically. This not only ensures consistency, it also allows a change of style to be easily implemented, simply by redefining the environment. This is where the typographical font commands come into play. They should not appear in the main text at all, but rather in the preamble as part of the definitions of environments and commands. On the other hand, many of the topics in this chapter really do involve logical markup, such as the verse, quote, and quotation environments, lists, bibliographies, theorems, and tables. 4.1 Changing font In typography, a set of letters, numbers, and characters of a certain size and appearance is called a font. The standard font in LATEX for the main body of text is an upright, Roman one of medium weight, in the size specified in the \documentclass statement at the start. The three possible basic sizes are 10, 11, and 12 pt, depending on the size options 10pt (default), 11pt, and 12pt. (Recall, there are 72.27 points per inch or about 28.45 pt per cm.) The parenthesis characters ( ) extend the full height and depth of the font size. 61 62 Chapter 4. Displayed Text The differences in the visual appearance of the three standard sizes are greater than would be expected from the ratios of the numbers: This is an example of the 10 pt font. ( ) And this is the 11 pt font for comparison. ( ) And finally this is a sample of 12 pt font. ( ) 4.1.1 Emphasis The usual way to emphasize text in a typewritten manuscript is by underlining. The typesetter will transform underlined text into italics for the printed version. Switching from standard to emphasized text is carried out in LATEX with the command \emph or the declaration \em. The \em declaration functions just as the other font declarations described below: the change of font remains in effect until negated by another appropriate declaration (which can be \em itself), or until the end of the current environment (Section 2.2). An environment may also be created with a pair of curly braces {...}. The command \emph, on the other hand, operates only on the text in the following argument. This is easiest way to emphasize short pieces of text, as for example: This is the easiest way to \emph{emphasize} short ... The \em declaration is more appropriate for longer text that is enclosed in an environment, named or nameless. ...enclosed in an environment, {\em named or nameless.} Note carefully the difference between the declaration that remains in effect until the local environment is ended with the closing curly brace, and the command that operates on an argument enclosed in curly braces. Another more subtle difference is that the command \emph automatically inserts extra spacing at the end if necessary, the so-called italic correction, to improve the appearance at the interface between sloping and upright fonts. Both the declaration and the command switch to an emphasizing font. That means, if the current font is upright it switches to italics, whereas if the text is already slanted, an upright font is selected. Nested emphasis is possible and is simple to understand: The \emph{first}, second, and \emph{third font switch} The {\em first, {\em second, and {\em third font switch}}} both produce ‘The first, second, and third font switch’. 4.1.2 Choice of font size The following declarations are available in LATEX for changing the font size: 4.1. Changing font \tiny \scriptsize \footnotesize \small \normalsize \large smallest very small smaller small normal large \Large larger \LARGE even larger \huge still larger \Huge largest 63 all of which are relative to the standard size selected in the document class option. In this book, the standard size is 10 pt, which is then the size selected with \normalsize. The font size declarations behave as all other declarations: they make an immediate change that remains in effect until counteracted by another size declaration, or until the current environment comes to an end. If issued within curly braces {..}, the effect of the declaration extends only to the closing brace, as in a nameless environment: normal {\large large \Large larger} normal again normal large ! larger normal again Changing the font size with one of the above commands also automatically changes the interline spacing. For every font size, there is a corresponding natural line spacing \baselineskip. This may be altered at any time. If the natural line spacing is 12 pt, the command \setlength{\baselineskip}{15pt} will increase it to 15 pt. The value of \baselineskip that is effective at the end of the paragraph is used to make up the whole paragraph. This means that if there are several changes to \baselineskip within a paragraph, only the last value given will be taken into account. With every change in font size, \baselineskip is reset to its natural value for that size. Any previous setting with \setlength will be nullified. In order to create a change in the line spacing that is valid for all font sizes, one must make use of the factor \baselinestretch, which has a normal value of 1. The true interline spacing is really \baselinestretch×\baselineskip which maintains the same relative spacing for all font sizes. The user may change this spacing at any time with: \renewcommand{\baselinestretch}{factor} where factor is any decimal number. A value of 1.5 increases the interline spacing (baseline to baseline) by 50% over its natural size for all font sizes. The new value of \baselinestretch does not take effect until the next change in font size. In order to implement a new value in the current font size, it is necessary to switch to another size and back again immediately. If the present font size is \normalsize, the sequence \small\normalsize will do the trick. Any size command may be used in place of \small. 64 Chapter 4. Displayed Text 4.1.3 Font attributes The size of a font is only one of several attributes that may be used to describe it. With the New Font Selection Scheme (NFSS), which was introduced as part of LATEX 2ε , it is possible to select fonts strictly by these attributes, as described in Appendix A. However, for normal usage, there are some declarations and corresponding commands to simplify this procedure. For the Computer Modern fonts provided with TEX and LATEX, the following attributes and values exist: Family: for the general overall style. Traditional typographical families have names like Baskerville, Bodoni, Times Roman, Helvetica, and so on. The standard LATEX installation provides three families with declarations \rmfamily to switch (back) to a Roman font; \ttfamily to switch to a typewriter font; \sffamily to select a sans serif font. Shape: for the form of the font. The shape declarations available with the standard installation are \upshape \itshape \slshape \scshape to to to to switch (back) to an upright font; select an italic shape; choose a font that is slanted; switch to Caps and Small Caps. Series: for the width and/or weight (boldness) of the font. The declarations possible are \mdseries to switch (back) to medium weight; \bfseries to select a bold face font. These do not exhaust all the possible attribute settings, but they do cover the most standard ones, especially for the Computer Modern fonts. For other fonts, especially PostScript ones, additional attribute values exist. See Section A.1 for more details. These declarations are used just like any others, normally enclosed in a pair of curly braces {...}, such as {\scshape Romeo and Juliet} producing Romeo and Juliet. For longer sections of text, an environment is preferable: \begin{font style} . . . text in new font . . . \end{font style} This keeps better track of the beginning and end of the switch-over. For font style, any of the above font commands may be used, leaving off the initial \ character. Since changing any one attribute leaves the others as they were, all possible combinations may be obtained. (However, this does not mean 4.1. Changing font 65 that a font exists for each possible combination; if not, a substitution will be made.) If we select first a bold series with \bfseries, and then a slanted shape with \slshape, we obtain a bold, slanted font. normal and {\bfseries bold and {\slshape slanted} and back} again. produces: normal and bold and slanted and back again. Finally, the declaration \normalfont resets all the attributes (except size) back to their defaults: Roman, upright, medium weight. It is often useful to issue this command just to be sure of the font in effect. 4.1.4 Font commands For each of the font declarations listed above, there is a corresponding font command that sets its argument in a font with the specified attribute. Family: Shape: Series: Default: Emphasis: \textrm{text} \textup{text} \textsc{text} \textmd{text} \textnormal{text} \emph{text} \texttt{text} \textit{text} \textsf{text} \textsl{text} \textbf{text} Note that the \emph command is included here, corresponding to the declaration \em. The argument of \textnormal is set in the standard font selected with \normalfont. The use of such commands to change the font for short pieces of text, or single words, is much more logical than placing a declaration inside an implied environment. The previous example now becomes normal and \textbf{bold and \textsl{slanted} and back} again. to make: normal and bold and slanted and back again. As for the \emph command, these font commands automatically add any necessary italic correction between upright and slanted/italic fonts. The old two-letter TEX declarations such as \bf and \tt, which were part of LATEX 2.09, are still available but are now considered obsolete and should be avoided. They are listed for reference in Appendix F. 4.1.5 ! Additional fonts It is likely that your computing center or your TEX installation has even more fonts and sizes than those listed above. If so, they may be made available for use within a LATEX document either by referring to them by name, or by their attributes, if they have been set up for NFSS. To load a new font explicitly by name, the command 66 Chapter 4. Displayed Text \newfont{\fnt}{name scaled factor} \newfont{\fnt}{name at size} or is given, which assigns the font to the new command named \fnt. In the first case, factor is a number 1000 times the scaling factor that is to be used to magnify or reduce the font from its basic or design size. In the second case, the font is scaled to be of the size specified. To install a slanted, sans serif font of size 20.74 pt, as \sss, we load cmssi17 at 20.74pt with \newfont{\sss}{cmssi17 at 20.74pt} Now the declaration \sss switches directly to this font but without altering the baseline separation. Alternatively, the new font declaration can be made by attributes with (see Section A.3.2) \DeclareFixedFont{\sss}{OT1}{cmss}{m}{sl}{20.74} Indeed, if one wants to use the current encoding and \sffamily without knowing what they are, or without worrying so precisely what size must be stated, it is also possible to give \DeclareFixedFont{\sss}{\encodingdefault}{\sfdefault} {m}{sl}{20} (The defaults are explained in Section A.3.1.) 4.1.6 ! Character sets and symbols The individual character sets are each stored in their own files. The names of the 75 standard TEX fonts are listed in Section G.2.2, where many of them are also printed out. Each symbol within a character set is addressed by means of a number between 0 and 127 (or 255). The command \symbol{num} will produce that symbol with the internal identification number num in the current font. The symbol ¿ in the present font has the internal number 62 and can be printed with the command \symbol{62}. The identification number may also be given as an octal (prefix ’) or hexadecimal (prefix ") number. Thus the symbol commands \symbol{28}, \symbol{’34}, and \symbol{"1C} are all identical, producing ‘ø’. The \symbol command may also be used to generate symbols for which no other command has been defined: for example, {\ttfamily\symbol{’40} \symbol{’42} \symbol{’134}} produces " \ in typewriter font. Section G.2.2 presents the assignments of the identification numbers with the characters for the different symbol families. 4.2. Centering and indenting 4.2 Centering and indenting 4.2.1 Centered text 67 The environment \begin{center} line 1 \\ line 2 \\ . . . line n \end{center} centers the sections of text that are separated by the \\ command. (An optional additional line spacing may be inserted with \\[len].) If the text is too long for one line, it is split over several lines using uniform word spacing, filling the whole line width as best it can, except for the last line. Word division does not occur. Within an environment, the command \centering may be used to center the following text, again with \\ as the line divider. The effect of this declaration lasts until the end of that environment. A single line may be centered by typing its text as the argument of the TEX command \centerline{text}. 4.2.2 One-sided justification The environments \begin{flushleft} line 1 \\ line 2 \\ . . . line 2 \end{flushleft} \begin{flushright} line 1 \\ line 2 \\ . . . line 2 \end{flushright} produce text that is left (flushleft) or right (flushright) justified. If a section of text does not fit on to one line, it is spread over several with fixed word spacing, the same as for the center environment. Again, word division does not occur. The same results may be produced within an environment with the declarations \raggedright replacing the flushleft environment, and \raggedleft replacing the flushright environment. 4.2.3 Two-sided indentation A section of text may be displayed by indenting it by an equal amount on both sides, with the environments \begin{quote} text \begin{quotation} text \end{quote} \end{quotation} Additional vertical spacing is inserted above and below the displayed text to separate it visually from the normal text. The text to be displayed may be of any length; it can be part of a sentence, a whole paragraph, or several paragraphs. 68 Chapter 4. Displayed Text Paragraphs are separated as usual with an empty line, although no empty lines are needed at the beginning and end of the displayed text since additional vertical spacing is inserted here anyway. The difference between the above two forms is thus: In the quotation environment, paragraphs are marked by extra indentation of the first line, whereas in the quote environment, they are indicated with more vertical spacing between them. The present text is produced within the quotation environment, while the sample above was done with the quote environment. The quotation environment is only really meaningful when the regular text makes use of first-line indentation to show off new paragraphs. 4.2.4 Verse indentations For indenting rhymes, poetry, verses, etc. on both sides, the environment \begin{verse} poem \end{verse} is more appropriate. Stanzas are separated by blank lines while the individual lines of the stanza are divided by the \\ command. If a line is too long for the reduced text width, it will be left and right justified and continued on the next line, which is indented even further. The above indenting schemes may be nested inside one another. Within a quote environment there may be another quote, quotation, or verse environment. Each time, additional indentations are created on both sides of the text and vertical spacing is added above and below; these quantities however decrease as the depth of nesting increases. A maximum of six such nestings is allowed. Exercise 4.1: Put some appropriate sections of text in your exercise file into the quote and quotation environments, that is, enclose these sections within \begin{quote} . . . . . . . \end{quote} or \begin{quotation} . . . . . \end{quotation} commands. 4.3. Lists 69 Exercise 4.2: Make up a new file with the name poem.tex and type your favorite poem in the verse environment. Select 12pt as the standard font size and italic as the typeface. Put the title of the poem before the verse environment in a larger bold typeface, such as \Large\bfseries. Include the name of the poet right justified. Note: remember that you may include declarations to change the font style or size within an environment and that these remain in effect only until the end of that environment. Exercise 4.3: Make up another file with the name title.tex. Do you recall the titlepage environment for producing a free-form title page? If not, refer to Section 3.3.1. Create a title page with this environment using font sizes and styles of your choice, centering all the entries. Note: within the titlepage environment you may of course make use of the center environment, but it is also sufficient to give the \centering declaration instead, since this will remain in effect only until the end of the titlepage environment. Choose the individual line spacings with the command \\[len] using an appropriate value for the spacing len. Remember that vertical spacing before the first line of text must be entered with the *-form of the command \vspace*[len] (see Section 2.7.3). Experiment with different font sizes and styles for the various parts of the title page, such as title, author’s name, address, until you are satisfied with the results. Compare your own title page with that of Exercise 3.8. If your creation appeals to you more, include it in your standard exercise file by replacing the commands \title, \author, \date, and \maketitle with the titlepage environment and your own entries. 4.3 Lists There are three environments available for producing formatted lists: \begin{itemize} \begin{enumerate} \begin{description} list text list text list text \end{itemize} \end{enumerate} \end{description} In each of these environments, the list text is indented from the left margin and a label, or marker, is included. What type of label is used depends on the selected list environment. The command to produce the label is \item. 4.3.1 Sample itemize • The individual entries are indicated with a black dot, a so-called bullet, as the label. 70 Chapter 4. Displayed Text • The text in the entries may be of any length. The label appears at the beginning of the first line of text. • Successive entries are separated from one another by additional vertical spacing. The above text was produced as follows: \begin{itemize} \item The individual entries are indicated with a black dot, a so-called \emph{bullet}, as the label. \item The text in the entries may be of any length. The label appears at the beginning of the first line of text. \item Successive entries are separated from one another by additional vertical spacing. \end{itemize} 4.3.2 Sample enumerate 1. The labels consist of sequential numbers. 2. The numbering starts at 1 with every call to the enumerate environment. The above example was generated with the following text: \begin{enumerate} \item The labels consist of sequential numbers. \item The numbering starts at 1 with every call to the \texttt{enumerate} environment. \end{enumerate} 4.3.3 Sample description purpose This environment is appropriate when a number of words or expressions are to be defined. example A keyword is used as the label and the entry contains a clarification or explanation. other uses It may also be used as an author list in a bibliography. The above sample was created using the following: \begin{description} \item[purpose] This environment is appropriate when a number of words or expressions are to be defined. \item[example] A keyword is used as the label and the entry contains a clarification or explanation. \item[other uses] It may also be used as an author list in a bibliography. \end{description} 4.3. Lists 71 The \item[option] command contains an optional argument that appears in bold face as the label. 4.3.4 Nested lists The above lists may be included within one another, either mixed or of one type, to a depth of four levels. The type of label used depends on the depth of the nesting. The indentation is always relative to the left margin of the enclosing list. A fourfold nesting of the itemize environment appears as follows: • The label for the first level is a black dot, a bullet. – That of the second level is a long dash. ∗ That of the third level is an asterisk. · And the label for the fourth level is a simple dot. · At the same time, the vertical spacing is decreased with increasing depth. ∗ Back to the third level. – Back to the second level. • And here we are at the first level of itemize once again. Similarly for the enumerate environment, where the style of the numbering changes with the nesting level: 1. The numbering at the first level is with Arabic numerals followed by a period. (a) At the second level, it is with lower case letters in parentheses. i. The third level is numbered with lower case Roman numerals with a period. A. At the fourth level, capital letters are used. B. The label style can be changed, as described in the next section. ii. Back to the third level. (b) Back to the second level. 2. And the first level of enumerate again. An example of a nested list with mixed types: • The itemize label at the first level is a bullet. 1. The numbering is with Arabic numerals since this is the first level of the enumerate environment. 72 Chapter 4. Displayed Text – This is the third level of the nesting, but the second itemize level. (a) And this is the fourth level of the overall nesting, but only the second of the enumerate environment. (b) Thus the numbering is with lower case letters in parentheses. – The label at this level is a long dash. 2. Every list should contain at least two points. • Blank lines ahead of an \item command have no effect. The above mixed list was produced with the following text: \begin{itemize} \item The \texttt{itemize} label at the first level is a ... \begin{enumerate} \item The numbering is with Arabic numerals since this ... \begin{itemize} \item This is the third level of the nesting, but the ... \begin{enumerate} \item And this is the fourth level of the overall ... \item Thus the numbering is with lower case letters ... \end{enumerate} \item The label at this level is a long dash. \end{itemize} \item Every list should contain at least two points. \end{enumerate} \item Blank lines ahead of an \verb+\item+ command ... \end{itemize} Exercise 4.4: Produce a nested list using the itemize and enumerate environments as in the above example, but with a different sequence of these commands. Exercise 4.5: Prepare a list of conference participants with their place of residence using the description environment, where the name of the participant appears as the argument in the \item command. Note: for all three types of lists, any text before the first \item command will yield an error message on processing. 4.3.5 Changing label style The labels, or markers, used in the itemize and enumerate environments can be easily changed by means of the optional argument in the \item command. With \item[+] the label becomes +, and with \item[2.1:] it is 2.1:. The optional argument takes precedence over the standard 4.3. Lists 73 label. For the enumerate environment, this means that the corresponding counter is not automatically incremented and the user must do the numbering manually. The optional label appears right justified within the area reserved for the label. The width of this area is the amount of indentation at that level less the separation between label and text; this means that the left edge of the label area is flush with the left margin of the enclosing level. It is also possible to change the standard labels for all or part of the document. The labels are generated with the internal commands \labelitemi , \labelitemii , \labelitemiii , \labelitemiv \labelenumi , \labelenumii , \labelenumiii , \labelenumiv The endings i, ii, iii, and iv refer to the four possible levels. These commands may be altered with \renewcommand. For example, to change the label of the third level of the itemize environment from ∗ to +, give \renewcommand{\labelitemiii}{+} Similarly the standard labels for the enumerate environment may be changed. However, here there is an additional complication that there is a counter for each enumerate level, named enumi, enumii, enumiii, and enumiv. As explained in Section 8.1.4, the value of a counter can be printed using one of the commands \arabic, \roman, \Roman, \alph, or \Alph, where the style of each command should be obvious from its name. That is, \Roman{xyz} prints the current value of the counter xyz in upper case Roman numerals, whereas \alph{xyz} prints it as a lower case letter (with a corresponding to 1 and z to 26). These counters, together with the counter style commands, must be used in the redefinitions of the label commands. For example, to change the second-level label to Arabic numerals followed by ‘.)’, it is necessary to give \renewcommand{\labelenumii}{\arabic{enumii}.)} which redefines \labelenumii to the value of counter enumii printed in Arabic, plus the characters ‘.)’. In this way, all the numbering levels may be changed. It is even possible to include more than one counter: \renewcommand{\labelenumii}{\Alph{enumi}.\arabic{enumii}} which will produce for every call to \item at level two the value of the counter enumi as a capital letter followed by the value of counter enumii as a number: that is, in the form A.1, A.2, . . . , B.1, B.2, . . . and so on. If the new standard labels are to apply to the whole document, the redefining commands should be included in the preamble. Otherwise, they are valid only within the environment in which they appear. 74 Chapter 4. Displayed Text Exercise 4.6: Change the standard labels for the itemize environment into a long dash — (written ---) for the first level, to a medium dash – (--) for the second level, and to a hyphen - for the third level. Exercise 4.7: Change the standard labels for the enumerate environment for the first level to (I), (II), . . . , and for the second level to the Roman numerals of the first level followed by the number for the second level in the form I–1:, I–2:, . . . , II–1:, II–2:, . . . . Package: enumerate An alternative method of customizing the enumeration labels is with the enumerate package in the tools collection (Section B.5.4). Once this package has been loaded, the enumerate environment accepts an optional argument specifying the text of the label. The characters A a I i 1 represent the number in alphabetical, Roman, Arabic styles. If these characters appear elsewhere in the label text, they must be in {}. For example, \begin{enumerate}[{Case} A] \item Witness tells the truth \item Witness is lying \end{enumerate} 4.4 =⇒ Case A Witness tells the truth Case B Witness is lying Generalized lists Lists such as those in the three environments itemize, enumerate, and description can be formed in a quite general way. The type of label and its width, the depth of indentation, spacings for paragraphs and labels, and so on, may be wholly or partially set by the user by means of the list environment: \begin{list}{stnd lbl}{list decl} item list \end{list} Here item list consists of the text for the listed entries, each of which begins with an \item command that generates the corresponding label. The stnd lbl contains the definition of the label to be produced by the \item command when the optional argument is missing (see below). The list parameters described in Section 4.4.2 are set by list decl to whatever new values the user wishes. 4.4.1 Standard label The first argument in the list environment defines the stnd lbl, that is, the label that is produced by the \item command when it appears without an argument. In the case of an unchanging label, such as for the itemize environment, this is simply the desired symbol. If this is to be a mathematical symbol, it must be given as $symbol name$, enclosed in $ signs. For example, to select ⇒ as the label, stnd lbl must be defined to be $\Rightarrow$. 4.4. Generalized lists 75 However, the label is often required to contain a sequential numeration. For this purpose, a counter must be created with the \newcounter{name} command, where name is its designation. This command must appear before the first application of the counter in a list environment. Suppose a counter named marker has been defined for this use, then the argument stnd lbl could be any of the commands for printing counters described in Section 4.3.5: for example, \arabic{marker} produces a running Arabic number. Even more complex labels can be made up in this way. If the sequential labels are to be A–I, A–II, . . . , stnd lbl is set to A--\Roman{marker}. Before a counter can function properly within the standard label, it must be associated with that list by including in the list decl the command \usecounter{counter}, where counter is the name of the counter to be assigned (marker in the above example). ! The standard label is actually generated by the command \makelabel{label}, which is called by the \item command. The user can redefine \makelabel with the aid of the \renewcommand in the list declaration: \renewcommand{\makelabel}{new definition} If the standard label is defined in this manner, the corresponding entry in the list environment is left blank. This is because \makelabel is the more general command and overrides the other definition. 4.4.2 List style parameters There are a number of style parameters used for formatting lists that are set by LATEX to certain standard values. These values may be altered by the user in the list decl for that particular list. The assignment is made in the usual way with the \setlength command. However, if the assignment is made outside the list environment, in most cases it will simply be ignored. This is because there are preset default values for each parameter at each level that can only be overridden by list decl. The style parameters are listed below and are also illustrated in Figure 4.1 on the next page, which is based on one taken from Lamport (1985, 1994). \topsep is the vertical spacing in addition to \parskip that is inserted between the list and the enclosing text above and below. Its default value is set at each list level and cannot be globally redefined outside the list decl. \partopsep is the vertical spacing in addition to \topsep + \parskip that is inserted above and below the list when a blank line precedes the first or follows the last \item entry. It may be redefined globally, but only for the first and second levels. 76 Chapter 4. Displayed Text Preceding text 6 \topsep + \parskip [+ \partopsep] \labelsep Label  ? - - \rightmargin   \labelwidth - \itemindent \leftmargin \listparindent   - Item 1 Paragraph 1 6\parsep ? Item 1 Paragraph 2 6\itemsep + \parsep ? Label Item 2 6 \topsep + \parskip [+ \partopsep] ? Following text Figure 4.1: The list parameters \parsep is the vertical spacing between paragraphs of a single \item. Its default value is reset at each level, as for \topsep. \itemsep is the vertical spacing in addition to \parsep that is inserted between two \item entries. As for \topsep and \parsep, its default value is reset at each level and cannot be globally changed. \leftmargin is the distance from the left edge of the current environment to the left margin of the list text. There are default values for it at each level that may be globally redefined, as described in Section 4.4.6. \rightmargin is the distance from the right edge of the current environment to the right margin of the list text. Its standard value is 0 pt, which can only be altered in list decl. \listparindent is the indentation depth of the first line of a paragraph within an \item with respect to the left margin of the list text. It is 4.4. Generalized lists 77 normally set to 0 pt so that no indentation occurs. This can only be changed in list decl. \labelwidth is the width of the box reserved for the label. The text of the label is printed right justified within this space. A new default value may be set globally which then applies to all list levels. \labelsep is the spacing between the label box and the list text. A new value may be assigned globally, but it is only effective at the first level. \itemindent is the distance by which the label and the first line of text in an \item are indented to the right. It is normally set to 0 pt and so has no effect. This value can only be redefined in list decl. When changing the vertical spacings from their standard values, it is recommended that a rubber length (Section 2.4.2) be used. The label created by the \item command normally appears right justified within a box of width \labelwidth. It is possible to make it left justified, as in the following list of parameters, by putting \hfill at the end of the definition of the standard label or in the \makelabel command. 4.4.3 Example of a user’s list List of Figures: Figure 1: Page format with head, body, and foot, showing the meaning of the various elements involved. Figure 2: Format of a general list showing its elements. Figure 3: A demonstration of some of the possibilities for drawing pictures with LATEX. This list was produced with the following input: \newcounter{fig} \begin{list}{\bfseries\upshape Figure \arabic{fig}:} {\usecounter{fig} \setlength{\labelwidth}{2cm}\setlength{\leftmargin}{2.6cm} \setlength{\labelsep}{0.5cm}\setlength{\rightmargin}{1cm} \setlength{\parsep}{0.5ex plus0.2ex minus0.1ex} \setlength{\itemsep}{0ex plus0.2ex} \slshape} \item Page format with head, body, and foot, showing the meaning of the various elements involved. \item Format of a general list showing its elements. \item A demonstration of some of the possibilities for drawing pictures with \LaTeX. \end{list} 78 Chapter 4. Displayed Text The command \newcounter{fig} sets up the counter fig. The standard label is defined to be the word Figure in upright, bold face, followed by the running Arabic number, terminated by :. This label is printed for each \item command. The list declaration contains \usecounter{fig} as its first command, which makes the counter fig operational within the list. The width of the label box (\labelwidth) is set to 2.0 cm, the left margin of the list text (\leftmargin) to 2.6 cm, the distance between the label and the text (\labelsep) to 0.5 cm, and the right edge of the list (\rightmargin) is set to be 1 cm from that of the enclosing text. The vertical spacing between paragraphs within an item (\parsep) is 0.5 ex but can be stretched an extra 0.2 ex or shrunk by 0.1 ex. The additional spacing between items (\itemsep) is 0 ex, stretchable to 0.2 ex. Standard values are used for all the other list parameters. The last command in the list declaration is \slshape, which sets the list text in a slanted typeface. Note: If \upshape were not given in the label definition, the text of each \item would also be slanted, as Figure 1:. 4.4.4 Lists as new environments If a particular type of list is employed several times within a document, it can become tiresome typing the same stnd lbl and list decl into the list environment every time. LATEX offers the possibility of defining a given list as an environment under its own name. This is achieved by means of the \newenvironment command. For example, the list in the above example can be stored so that it may be called at any time with the name figlist: \newenvironment{figlist}{\begin{list} {\bfseries\upshape Figure \arabic{fig}:} {\usecounter{fig} ... {0ex plus0.2ex}\slshape}} {\end{list}} It can then be called with \begin{figlist} item list \end{figlist} so that it behaves as a predefined list environment. Exercise 4.8: Define a new environment with the name sample that produces a list in which every call to \item prints labels Sample A, Sample B, and so on. The labels are to be left justified within a box of width 20mm, and the distance between the label box and the item text is to be 2mm, with a total left margin of 22mm. The right edge of the text is to be moved in 5mm from that of the enclosing text. The extra vertical spacing between two items is to be 1ex plus0.5ex minus0.4ex in addition to the normal paragraph spacing. Secondary paragraphs within an 4.4. Generalized lists 79 item are to be indented by 1em. The normal paragraph separation should be 0ex, expandable to 0.5ex. ! LATEX itself makes frequent use of the list environment to define a number of other structures. For example, the quote environment is defined as \newenvironment{quote}{\begin{list}{} {setlength{\rightmargin}{\leftmargin}} \item[]}{\end{list}} This environment is thus a list in which the value of \rightmargin is set to the current value of \leftmargin which has a default value of 2.5 em. The list itself consists of a single \item call with an empty label, a call that is automatically included in the definition of quote with the entry \item[]. In the same way, LATEX defines the quotation and verse environments internally as special list environments. The left margins and the vertical spacings around the structures are left as the standard values for the list environment, and are therefore changed only when the standard values themselves are altered. Finally, as an example of a possible user-defined special list we offer \newenvironment{lquote}{\begin{list}{}{}\item[]}{\end{list}} which creates an lquote environment that does nothing more than indent its enclosed text by the amount \leftmargin, with the right edge flush with that of the normal text, since \rightmargin has the standard value of 0 pt. 4.4.5 ! Trivial lists LATEX also contains a trivlist environment, with syntax \begin{trivlist} enclosed text \end{trivlist} in which the arguments stnd lbl and list decl are omitted. This is the same as a list environment for which the label is empty, \leftmargin, \labelwidth, and \itemindent are all assigned the value 0 pt, while \listparindent is set equal to \parindent and \parsep to \parskip. LATEX uses this environment to create further structures. For example, the call to the center environment generates internally the sequence \begin{trivlist} \centering \item[] enclosed text \end{trivlist} The environments flushleft and flushright are similarly defined. 4.4.6 Nested lists Lists can be nested within one another with the list environments itemize, enumerate, and description, to a maximum depth of six. At each level, the new left margin is indented by the amount \leftmargin relative to that of the next higher one. ! As mentioned earlier, it is only possible to change the standard values of a limited number of the list parameters with declarations in the preamble. One exception is the indentations of the left margins for the different nesting levels. 80 Chapter 4. Displayed Text These are set internally by the parameters \leftmarginn, where n stands for i, ii, iii, iv, v, or vi. These values can be changed by the user; for example, by declaring \setlength{\leftmarginiv}{12mm}, the left margin of the fourthlevel list is shifted 12 mm from that of the third. These declarations must be made outside of the list environments and not in the list decl. At each level of list nesting, the internal macro \@listn (n being i to vi) is called. This sets the value of \leftmargin equal to that of the corresponding \leftmarginn, unless \leftmargin is explicitly declared in the list environment. That is, there does not exist a single standard value for \leftmargin externally, but rather six different ones. The parameter \leftmargin has meaning only within a list environment. 4.5 Theorem-like declarations In scientific literature one often has text structures like Theorem 1 (Balzano–Weierstrass) Every infinite set of bounded points possesses at least one maximum point. or Axiom 4.1 The natural numbers form a set S of distinct elements. For any two elements a, b, they are either identical, a = b, or different from one another, a ≠ b. Similar structures frequently appear with names such as Definition, Corollary, Declaration, Lemma, instead of Theorem or Axiom. What they have in common is that a keyword and a running number are printed in bold face and the corresponding text in italic. Of course, these could be generated by the user by explicitly giving the type styles and appropriate number, but if a new structure of that type is later inserted in the middle of the text, the user would have the tedious job of renumbering all the following occurrences. With the command \newtheorem{struct type}{struct title}[in counter] LATEX will keep track of the numbering automatically. Here struct type is the user’s arbitrary designation for the structure, while struct title is the word that is printed in bold face followed by the running number (for example, Theorem). If the optional argument in counter is missing, the numbering is carried out sequentially throughout the entire document. However, if the name of an existing counter, such as chapter, is given for in counter, the numbering is reset every time that counter is augmented, and both are printed together, as in Axiom 4.1 above. The predefined structures are called with the command \begin{struct type}[extra title] text \end{struct type} 4.6. Tabulator stops 81 which also increments the necessary counter and generates the proper number. The above examples were produced with \newtheorem{theorem}{Theorem} \newtheorem{axiom}{Axiom}[chapter] . . . . . . . . . . . . . . . . \begin{theorem}[Balzano--Weierstrass] Every .... \end{theorem} \begin{axiom} The natural numbers form ........... \end{axiom} The optional extra title also appears in bold face within parentheses ( ) following the running number. Occasionally a structure is not numbered on its own but together with another structure. This can be included in the definition with another optional argument \newtheorem{struct type}[num like]{struct name} where num like is the name of an existing theorem structure that shares the same counter. Thus by defining \newtheorem{subthrm}[theorem] {Sub-Theorem}, the two structures theorem and subthrm will be numbered as a single series: Theorem 1, Sub-Theorem 2, Sub-Theorem 3, Theorem 4, and so on. For more powerful theorem tools, see the AMS amsthm package (Section 12.3.1) and the theorem package in the tools collection (Section B.5.4). 4.6 Tabulator stops 4.6.1 Basics On a typewriter it is possible to set tabulator stops at various positions within a line; then by pressing the tab key the print head or carriage jumps to the next tab location. A similar possibility exists in LATEX with the tabbing environment: \begin{tabbing} lines \end{tabbing} One can think of the set tab stops as being numbered from left to right. At the beginning of the tabbing environment, no tabs are set, except for the left border, which is called the zeroth tab stop. The stops can be set at any spot within a line with the command \=, and a line is terminated by the \\ command: Here is the \=first tab stop, followed by\= the second\\ sets the first tab stop after the blank following the word the, and the second immediately after the word by. After the tab stops have been set in this way, one can jump to each of the stops in the subsequent lines, starting from the left margin, with the command \>. A new line is started with the usual \\ command. 82 Chapter 4. Displayed Text Example: Type Quality Paper med. Leather good Card bad 4.6.2 Color Price white low brown high gray med. \begin{tabbing} Type\qquad\= Quality\quad\= Color\quad\= Price\\[0.8ex] Paper \> med. \> white \> low\\ Leather \> good \> brown \> high\\ Card \> bad \> gray \> med. \end{tabbing} Sample line It is often advantageous or even necessary to set the tab stops in a sample line that is not actually printed. It could contain, for example, the widest entries in the various columns that appear later, or the smallest intercolumn spacing between stops. The sample line may also contain \hspace commands to force the distance between stops to be a predetermined amount. To suppress the printing of the sample line, it is ended with the command \kill instead of the \\ terminator. \hspace*{3cm}\=sample column \=\hspace{4cm}\= \kill In addition to the left border, the above statement sets three tab stops: Left border 3cm 1st tab stop 2nd tab stop ? ? -sample column 4cm 3rd tab stop ? - An \hspace command at the beginning of a sample line must be of the *-form, otherwise the inserted spacing will be deleted at the line margin. 4.6.3 Tab stops and the left margin The left border of each line of the tabbing environment is at first identical with the left margin of the enclosing environment, and is designated the zeroth stop. By activating the ‘tab key’ \> at the start of a line, one sets the following text beginning at the first tab stop. However, the command \+ has the same effect, putting the left border permanently at the first stop, for all subsequent lines. With \+\+ at the beginning or end of a line, all the next lines will start two stops further along. There can be as many \+ commands in all as there are tab stops set on the line. The command \- has the opposite effect: it shifts the left border for the following lines one stop to the left. It is not possible to set this border to be to the left of the zeroth stop. The effect of the \+ commands may be overridden for a single line by putting \< at the start for each tab to be removed. This line then starts so many tabs to the left of the present border. With the next \\ command, the new line begins at the current left border determined by the total number of \+ and \- commands. 4.6. Tabulator stops 4.6.4 83 Further tabbing commands Tab stops can be reset or added in every line. The command \= will add a stop if there have been sufficient \> commands to have jumped to the last stop, otherwise it will reset the next stop. For example: Old column 1 Old column 2 Left column Middle col Extra col New col 1 New col 2 Old col 3 Column 1 Column 2 Column 3 Old column 1 \= Old column 2\\ Left column \> Middle col \= Extra col\\ New col 1 \= New col 2 \> Old col 3\\ Column 1\> Column 2 \> Column 3 \end{tabbing} Occasionally it is desirable to be able to reset the tab stops and then to reuse the original ones later. The command \pushtabs accomplishes this by storing the current tabs and removing them from the active line. All the tab stops can then be set once again. The stored stops can be reactivated with the command \poptabs. The \pushtabs command may be given as many times as needed, but there must be the same number of \poptabs commands within any one tabbing environment. It is possible to position text on a tab stop with left text \’ right text, where left text goes just before the current tab (or left border) with a bit of spacing, while right text starts exactly at the stop. The amount of spacing between the left text and the tab stop is determined by the tabbing parameter \tabbingsep. This may be changed by the user with the \setlength command as usual. Text may be right justified up against the right border of a line with the command \‘ text. There must not be any more \> or \= commands in the remainder of the line. The commands \=, \‘, and \’ function as accent commands outside of the tabbing environment (Section 2.5.7). If these accents are actually needed within tabbing, they must be produced with \a=, \a‘, and \a’ instead. For example, to produce ó, ò, or ō inside a tabbing environment, one must give \a’o, \a‘o, or \a=o. The command \- also has another meaning outside of the tabbing environment (suggested word division) but since lines are not broken automatically within this environment, there is no need for an alternative form. Here is an example illustrating all the tabbing commands: 84 Chapter 4. Displayed Text Apples: consumed by: people horses and sheep reasonably juicy Grapefruits: a delicacy (see also: melons pumpkins) Horses feed on apples 4.6.5 \begin{tabbing} Grapefruits: \= \kill Apples: \> consumed by: \= people\+\+\\ horses \\ and \’ sheep\-\\ reasonably juicy\-\\ Grapefruits: \> a delicacy\\ \pushtabs (see also: \= melons\\ \> pumpkins)\\ \poptabs Horses \> feed on \> apples \end{tabbing} Remarks on tabbing TEX treats the tabbing environment like a normal paragraph, breaking a page if necessary between two lines within the environment. However, the commands \newpage and \clearpage are not allowed within it, and the command \pagebreak is simply ignored. If the user wishes to force a page break within the tabbing environment, there is a trick that he or she may employ: specify a very large interline spacing at the end of the line where the break should occur (for example, \\[10cm]). This forces the break and the spacing disappears at the start of the new page. Each line of text is effectively within a { } pair, so that any size or font declarations remain in force only for that one line. The text need not be put explicitly inside a pair of curly braces. It is not possible to nest tabbing environments within one another. Beware: the tab jump command \> always moves to the next logical tab stop. This could actually be a move backwards if the previous text is longer than the space available between the last two stops. This is in contrast to the way the tabulator works on a typewriter. There is no automatic line breaking within the tabbing environment. Each line continues until terminated by a \\ command. The text could extend beyond the right margin of the page. The user must take care that this does not happen. The commands \hfill, \hrulefill, and \dotfill have no effect inside a tabbing environment, since no stretching takes place here. Exercise 4.9: Generate the following table with the tabbing environment. $900 000.00 $450 000.00 $350 000.00 $100 000.00 2003 approved: $350 000.00 Deficiency: $100 000.00 2004 $300 000.00 $150 000.00 2005 $250 000.00 Surplus: $150 000.00 Project: Total Requirements of which 2003 2004 2005 = = = = 4.7. Boxes tentative Commitments 85 2004 = $100 000.00 for deficiency 2003 2005 = $ 50 000.00 2004 + $100 000.00 excess for 2003 in 2004 2003 = $100 000.00 2004 = $150 000.00 signed: H. André Hint: the first line in the tabbing environment should read Project: \=Total Requirements\= = \$900\,000.00 \+\\ What is the effect of the \+ command at the end of this line? How do you arrange, using these tab stops, for the years 2003, 2004, and 2005 in the second to fourth lines all to be positioned before the second tab stop? Which command should be at the end of the second line just before the \\terminator? Lines 1–4 and 8–12 all use the same set of tab stops, even though there are additional stops set in the eighth line. With \$1\=00\,000.00 one can align the entry \$\>50\,000.00 in the ninth line to match the decimal places of the lines above. Lines 5–7 have their own tab stops. Use the save and recall feature to store the preset tab stops and to bring them back. The left border of lines 5–7 correspond to the first stop of the first group. What command is at the end of the fourth line to ensure that the left border is reset to one stop earlier? How is the left border of the second-to-last line reset? The last line contains ‘signed: H. André’ right justified. With what tabbing command was this produced? Watch out for the accent é in this entry within the tabbing environment! 4.7 Boxes A box is a piece of text that TEX treats as a unit, like a single character. A box (along with the text within it) can be moved left, right, up, or down. Since the box is a unit, TEX cannot break it up again, even it was originally made up of smaller individual boxes. It is, however, possible to put those smaller boxes together as one pleases when constructing the overall box. This is exactly what TEX does internally when it carries out the formatting: the individual characters are packed in character boxes, which are put together into line boxes horizontally with rubber lengths inserted between the words. The line boxes are stacked vertically into paragraph boxes, again with rubber lengths separating them. These then go into the page body box, which with the head and foot boxes constitutes the page box. LATEX offers the user a choice of three box types: LR boxes, paragraph boxes, and rule boxes. The LR (left–right) box contains material that is ordered horizontally from left to right in a single line. A paragraph box will have its contents made into vertically stacked lines. A rule box is a rectangle filled solidly with black, usually for drawing horizontal and vertical lines. 86 Chapter 4. Displayed Text 4.7.1 LR boxes To create LR boxes containing single line text the commands \mbox{text} \fbox{text} and and \makebox[width][pos]{text} \framebox[width][pos]{text} are available. The two commands at the left produce an LR box with a width exactly equal to that of the text given between the braces { }. The \fbox command is the same as \mbox except that the text is also framed. With the two commands at the right, the width is predetermined by the optional length argument width. The other optional argument pos specifies how the text is positioned within the box. With no value given, the text is centered. Otherwise pos may be l r s to left justify the text, to right justify it, to stretch it to fill up the full width. Thus \makebox[3.5cm]{centered text} creates a box of width 3.5 cm in which the text is centered, as centered text , filled with white space, while with \framebox[3.5cm][r]{right justified} the text is right justified inside a framed box of width 3.5 cm: right justified . One may also give \framebox[3.5cm][s]{stretched\dotfill text} to fill up the box, as stretched . . . . . . . text , in which case some rubber length (Section 2.4.2) or other filler (page 30) must be added where the stretching is to occur. If the text has a natural width that is larger than that specified in width, it will stick out of the box on the left, right, or both sides, depending on the choice of pos. For example, \framebox[2mm]{centered} produces centered . The above application may appear rather silly for \framebox, but it can indeed be very useful for \makebox. A width specification of 0 pt for \makebox can generate a centered, left, or right justified positioning of text in diagrams made with the picture environment (see Chapter 13 for examples). It may also be used to cause two pieces of text to overlap, as \makebox[0pt][l]{/}S prints a slash through an S, as / S. Note: Length specifications must always contain a dimensional unit, even when they are zero. Thus 0pt must be given for the width, not 0. It is also possible to specify the width of an LR box relative to its natural dimensions (those produced by the simple \mbox command): \width is the natural width of the box, \height is the distance from baseline to top, \depth is the distance from baseline to bottom, \totalheight is \height plus \depth. 4.7. Boxes 87 To make a framed box such that the width is six times the total height, containing centered text, \framebox[6\totalheight]{Text} Text Note: These special length parameters only have meaning within the width specification of an LR box, or within the height specification of a paragraph box, as shown below. In any other context, they will produce an error message. If a set piece of text is to appear in several places within the document, it can be stored by first giving the command \newsavebox{\boxname} to create a box with the name \boxname. This name must conform to LATEX command name syntax (letters only) with an initial \. The name must not conflict with any existing LATEX command names. After such a box has been initiated, the commands \sbox{\boxname}{text} or \savebox{\boxname}[width][pos]{text} will store the contents text for future use. The optional arguments width and pos have the same meanings as for \makebox and \framebox. Now with the command \usebox{\boxname} the stored contents are inserted into the document text wherever desired, as a single unit. The contents of an LR box may also be stored with the environment \begin{lrbox}{boxname} text \end{lrbox} This is equivalent to \sbox{\boxname}{text}. Its advantage is that it allows text within a user-defined environment (Section 8.4) to be stored for future use with \usebox. 4.7.2 Vertical shifting of LR boxes The command \raisebox{lift}[height][depth]{text} produces an \mbox with contents text, raised above the current baseline by an amount lift. The optional arguments tell LATEX to treat the box as though its extension above the baseline were height and that below were depth. Without these arguments, the box has its natural size determined by text and lift. Note that lift, height, and depth are lengths (Section 2.4.1). If lift is negative, the box is lowered below the baseline. For example: 88 Chapter 4. Displayed Text Baseline \raisebox{1ex}{high} and \raisebox{-1ex}{low} and back again high produces: Baseline and and back again. low The values for height and depth can be totally different from the actual ones of the text. Their effect is to determine how far away the previous and next lines of text should be from the current line, based on the heights and depths of all the boxes (characters are also boxes) in the line. By raising a box but specifying height to be the regular character size, the raised box will overprint the line above, and similarly for depth when a box is lowered. 4.7.3 Parboxes and minipages Whole paragraphs can be put into separate vertical boxes (or parboxes in the LATEX jargon) with the command \parbox[pos]{width}{text} or with the environment \begin{minipage}[pos]{width} text \end{minipage} Both produce a vertical box of width width, in which the lines of text are stacked on top of each other as in normal paragraph mode. The optional positioning argument pos can take on the values b t to align the bottom edge of the box with the current baseline, to align the top line of text with the current baseline. Without any positioning argument, the parbox is centered vertically on the baseline of the external line of text. The positioning argument is only meaningful when the \parbox command or the minipage environment occurs within a line of text, for otherwise the current line and its baseline have no meaning. If the parbox is immediately preceded by a blank line, it begins a new paragraph. In this case, the vertical positioning of the parbox is made with reference to the following elements of the paragraph. These could be further parboxes. If the paragraph consists of only a single parbox or minipage, the positioning argument is meaningless and has no effect. Examples: \parbox{3.5cm}{\sloppy This is a 3.5 cm wide parbox. It is vertically centered on the} \hfill CURRENT LINE \hfill \parbox{5.5cm}{Narrow pages are hard to format. They usually produce many warning messages on the monitor. The command \texttt{\symbol{92}sloppy} can stop this.} 4.7. Boxes 89 Narrow pages are hard to format. This is a 3.5 cm wide They usually produce many warning parbox. It is vertically CURRENT LINE messages on the monitor. The comcentered on the mand \sloppy can stop this. \begin{minipage}[b]{4.3cm} The minipage environment creates a vertical box like the parbox command. The bottom line of this minipage is aligned with the \end{minipage}\hfill \parbox{3.0cm}{middle of this narrow parbox, which in turn is aligned with} \hfill \begin{minipage}[t]{3.8cm} the top line of the right hand minipage. It is recommended that the user experiment with the positioning arguments to get used to their effects. \end{minipage} The minipage environment creates a vertical box like the parbox command. The bottom line of this minipage is middle of this narrow parbox, which in aligned with the turn is aligned with the top line of the right hand minipage. It is recommended that the user experiment with the positioning arguments to get used to their effects. In Section 4.7.7 we demonstrate how parboxes can be vertically stacked in any desired manner relative to one another. The \parbox command produces a vertical box containing the text just like the minipage environment. However, the latter is more general. The text in a \parbox may not contain any of the centering, list, or other environments described in Sections 4.2–4.5. These may, on the other hand, appear within a minipage environment. That is, a minipage can include centered or indented text, as well as lists and tabbings. 4.7.4 ! Problems with vertical placement Vertical positioning of minipages and parboxes can often lead to unexpected results, which can be explained by showing more graphically how a box is treated by LATEX. Suppose we want to place two parboxes of different heights side by side, aligned on their first lines, and the two together set on the current line of text at the bottom. The ‘obvious’ way of doing this is \begin{minipage}[b]{..} \parbox[t]{..}{..} \hfill \end{minipage} \parbox[t]{..}{..} 90 Chapter 4. Displayed Text which does not work, for it produces instead the following results: Current line •• The boxes are made • visible here by framing them, • and by marking •• of text. the baselines (the vertical alignment points) with black dots. The reason for this is that each parbox or minipage is treated externally as a single character with its own height and depth above and below the baseline. As far as the outer minipage is concerned, it contains only two ‘characters’ on the same line, and that line is both the top and bottom one. Thus the bottom line of the outer minipage is indeed aligned with the line of text, but that bottom line is simultaneously the top line. The solution is to add a dummy second line to the outer box, as \parbox[t]{..}{..} \hfill \parbox[t]{..}{..} \\ \mbox{} The dummy line may not be entirely empty, hence the \mbox. • The boxes are made • visible here by framing them, Current line •• • • and by marking • the baselines (the vertical alignment points) with black dots. • of text. A similar problem occurs if two boxes are to be aligned with their bottom lines, and the pair aligned at the top with the current line of text. Here there are two possibilities to add a dummy first line. \mbox{} \\ aligns with the very top, or \mbox{} \\[-\baselineskip] aligns with the first text line. An example of the first case is shown on page 176. Dummy lines are also needed for the solution of Exercise 4.10 on page 93. 4.7.5 Paragraph boxes of specific height The complete syntax of the \parbox command and minipage environment includes two more optional arguments: \parbox[pos][height][inner pos]{width}{text} \begin{minipage}[pos][height][inner pos]{width} text \end{minipage} In both cases, height is a length specifying the height of the box; the parameters \height, \width, \depth, and \totalheight may be employed within the height argument in the same way as in the width argument of \makebox and \framebox (page 86). 4.7. Boxes 91 The optional argument inner pos states how the text is to be positioned internally, something that is only meaningful if height has been given. Its possible values are: t b c s to to to to push the text to the top of the box, shove it to the bottom, center it vertically, stretch it to fill up the whole box. In the last case, rubber lengths (Section 2.4.2) should be present where the vertical stretching is to take place. Note the difference between the external positioning argument pos and the internal one inner pos: the former states how the box is to be aligned with the surrounding text, while the latter determines how the contents are placed within the box itself. Example: \begin{minipage}[t][2cm][t]{3cm} This is a minipage of height 2˜cm with the text at the top. \end{minipage}\hrulefill \parbox[t][2cm][c]{3cm}{In this parbox, the text is centered on the same height.}\hrulefill \begin{minipage}[t][2cm][b]{3cm} In this third paragraph box, the text is at the bottom. \end{minipage} This is a minipage of height 2 cm with the text at the top. In this parbox, the text is centered on the same height. In this third paragraph box, the text is at the bottom. The \hrulefill commands between the boxes show where the baselines are. All three boxes are the same size and differ only in their values of inner pos. 4.7.6 Rule boxes A rule box is a basically a filled-in black rectangle. The syntax for the general command is: \rule[lift]{width}{height} which produces a solid rectangle of width width and height height, raised above the baseline by an amount lift. Thus \rule{8mm}{3mm} generates . Without the optional argument lift, the rectangle is set on the baseline of the current line of text. 92 Chapter 4. Displayed Text The parameters lift, width, and height are all lengths (Section 2.4.1). If lift has a negative value, the rectangle is set below the baseline. It is also possible to have a rule box of zero width. This creates an invisible line with the given height. Such a construction is called a strut and is used to force a horizontal box to have a desired height or depth that is different from that of its contents. For this purpose, \vspace is inappropriate because it adds additional vertical space to that which is already there. For example: \fbox{Text} produces Text . In order to print Text , one has to tell TEX that the box contents extend above and below the baseline by the desired amounts. This was done with \fbox{\rule[-2mm] {0cm}{6mm}Text}. What this says is that the text to be framed consists of ‘an invisible bar beginning 2 mm below the baseline, 6 mm long, followed by the word Text’. The vertical bar indeed remains unseen, but it determines the upper and lower edges of the frame. 4.7.7 Nested boxes The box commands described above may be nested to any desired level. Including an LR box within a parbox or a minipage causes no obvious conceptual difficulties. The opposite, a parbox within an LR box, is also possible, and is easy to visualize if one keeps in mind that every box is a unit, treated by LATEX as a single character of the corresponding size. A parbox inside an \fbox command has the effect that the entire parbox is framed. The present structure was made with \fbox{\fbox{\parbox{10cm}{A parbox...}}} This is a parbox of width 10 cm inside a framebox inside a second framebox, which thus produces the double framing effect. Enclosing a parbox inside a \raisebox allows vertical displacements of any desired amount. The two boxes here both have positioning [b], but the one at the right has been produced with: abcdefghi jklmnopqr \raisebox{1cm}{\begin{minipage}[b]{2.5cm} stuvwxyz a b c d e ... x y z\\ baseline \underline{baseline} \end{minipage} } which displaces it upwards by 1 cm. baseline A very useful structure is one in which minipage environments are positioned relative to one another inside an enclosing minipage. The positioning argument of the outside minipage can be used to align its 4.7. Boxes 93 contents as a unit with the neighboring text or boxes. An example of this is given in Exercise 4.10. Finally, vertical boxes such as \parbox commands and minipage environments may be saved as the text in an \sbox or \savebox command, to be recalled later with \usebox, as described in Section 4.7.1. 4.7.8 ! Box style parameters There are two style parameters for the frame boxes \fbox and \framebox that may be reset by the user: \fboxrule determines the thickness of the frame lines, \fboxsep sets the amount of spacing between the frame and enclosed text. New values are assigned to these length parameters in the usual LATEX manner with the command \setlength: the line thickness for all the following \framebox and \fbox commands is set to 0.5 mm with \setlength{\fboxrule}{0.5mm}. The scope of these settings also obeys the usual rule: if they are found in the preamble then they apply to the entire document; if they are within an environment then they are valid only until the end of that environment. These parameters do not influence the \framebox command that is employed within the picture environment (Section 13.1.4) and which has different syntax and functionality from those of the normal \framebox command. Exercise 4.10: How can the following nested structure be generated? (Note: font size is \footnotesize) The first line of this 3.5 cm wide minipage or parbox is aligned with the first line of the neighboring minipage or parbox. This 4.5 cm wide minipage or parbox is positioned so that its top line is at the same level as that of the box on the left, while its bottom line is even with that of the box on the right. The naı̈ve notion that this arrangement may be achieved with the positioning arguments set to t, t, and b is incorrect. Why? What would this selection really produce? The true solution involves the nesting of two of the three structures in an enclosing minipage, which is then separately aligned with the third one. Note: there are two variants for the solution, depending on whether the left and middle structures are first enclosed in a minipage, or the middle and right ones. Try to work out both solutions. Incidentally, the third minipage is 3 cm wide. Note: the problems of correctly aligning two side-by-side boxes as a pair on a line of text (Section 4.7.4) arises here once more. It will be necessary to add a dummy line to get the vertical alignment correct. Exercise 4.11: Produce the framed structure shown below and store it with the command \sbox{\warning}{structure}. You will first have to create a box named \warning with the \newsavebox{\warning} command. Print this warning at various places in your exercise file by giving \usebox{\warning}. 94 Chapter 4. Displayed Text Vertical placement of minipages and parboxes can lead to surprising results which may be corrected by the use of dummy lines. Note: the parbox width is 10 cm. There should be no difficulty producing the framed structure if one follows the previous example for the double framed box. Watch out when writing \sbox{\warning}{structure} that you have the correct number of closing braces at the end. Next, change the values for the line thickness (\fboxrule) and frame spacing (\fboxsep) and print your results once more. 4.7.9 Further framed boxes Package: fancybox The fancybox package, by Timothy van Zandt, allows additional framed boxes of various styles. These all make use of the length \fboxsep to set the distance between frame and text, the same as for \fbox and \framebox. Depending on the box type, additional new lengths are also applicable. They may be changed with \setlength to modify the box appearance. These new framed boxes are: \shadowbox{text} The width of the shadow is given by the length \shadowsize, default 4 pt. Multiline text must be placed in a minipage environment, the same as for \fbox. \doublebox{text} The width of the inner frame is 0.75\fboxrule, that of the outer frame 1.5\fboxrule, and the spacing between the frames is 1.5\fboxrule plus 0.5 pt. ' \ovalbox{text} The thickness of the frame is that of \thinlines (Section 13.1.4), the diameter of the corners is set with the command \cornersize{frac}, to frac times the smaller of the box width or height, or with \cornersize*{size} to the length size. The default is frac=.5. & ' \Ovalbox{text} The frame thickness is set by \thicklines, but otherwise is the same as \ovalbox. & $ % $ % 4.8. Tables 95 This package also allows all pages to be boxed as part of the page style. This is done by issuing \fancypage{cmds1}{cmds2}, where cmds1 and cmds2 are commands setting box parameters, terminated by one of the box commands \fbox, \shadowbox, and so on. The first set, cmds1, form a box with the head and footlines outside, while the second set draw a box including them. Normally one would only specify one set, leaving the other blank, such as: \fancypage{\setlength{\fboxsep}{5pt} \setlength{\shadowsize}{3pt}\shadowbox}{} for a shadow box on each page excluding head and footlines. There is also the command \thisfancypage{cmds1}{cmds2} to box just the current page. 4.8 Tables With the box elements and tabbing environment from the previous sections it would be possible to produce all sorts of framed and unframed tables. However, LATEX offers the user far more convenient ways to build such complicated structures. 4.8.1 Constructing tables The environments tabular, tabular*, and array are the basic tools with which tables and matrices can be constructed. The syntax for these environments is \begin{array}[pos]{cols} \begin{tabular}[pos]{cols} \begin{tabular*}{width}[pos]{cols} rows rows rows \end{array} \end{tabular} \end{tabular*} The array environment can only be applied in mathematical mode (see Chapter 5). It is described here only because its syntax and the meaning of its arguments are exactly the same as those of the tabular environment. All three environments actually create a minipage. The meaning of the arguments is as follows: pos Vertical positioning argument (see also the explanation of this argument for parboxes in Section 4.7.3). It can take on the values t the top line of the table is aligned with the baseline of the current external line of text; b the bottom line of the table is aligned with the external baseline; with no positioning argument given, the table is centered on the external baseline. 96 Chapter 4. Displayed Text width This argument applies only to the tabular* environment and determines its overall width. In this case, the cols argument must contain the @-expression (see below) @{\extracolsep{\fill}} somewhere after the first entry. For the other two environments, the total width is fixed by the textual content. cols The column formatting argument. There must be an entry for every column, as well as possible extra entries for the left and right borders of the table or for the intercolumn spacings. The possible column formatting symbols are l the column contents are left justified; r the column contents are right justified; c the column contents are centered; p{wth} the text in this column is set into lines of width wth, and the top line is aligned with the other columns. In fact, the text is set in a parbox with the command \parbox[t]{wth}{column text}; *{num}{cols} the column format contained in cols is reproduced num times, so that *{5}{|c}| is the same as |c|c|c|c|c|. The available formatting symbols for the left and right borders and for the intercolumn spacing are | draws a vertical line; || draws two vertical lines next to each other; @{text} this entry is referred to as an @-expression, and inserts text in every line of the table between the two columns where it appears. An @-expression removes the intercolumn spacing that is automatically put between each pair of columns. If white space is needed between the inserted text and the next column, this must be explicitly included with \hspace{ } within the text of the @-expression. If the intercolumn spacing between two particular columns is to be something other than the standard, this may be easily achieved by placing @{\hspace{wth}} between the appropriate columns in the formatting argument. This replaces the standard intercolumn spacing with the width wth. An \extracolsep{wth} within an @-expression will put extra spacing of amount wth between all the following columns, until countermanded by another \extracolsep command. In contrast to the standard spacing, this additional spacing is not removed by later @-expressions. In the tabular* environment, there must be a command @{\extracolsep\fill} somewhere in the column format so that all the subsequent intercolumn spacings can stretch out to fill the predefined table width. 4.8. Tables 97 If the left or right borders of the table do not consist of a vertical line, spacing is added there of an amount equal to half the normal intercolumn spacing. If this spacing is not wanted, it may be suppressed by including an empty @-expression @{} at the beginning or end of the column format. rows contain the actual entries in the table, each horizontal row being terminated with a \\ command. These rows consist of a sequence of column entries separated from each other by the & symbol. Thus each row in the table contains the same number of column entries as in the column definition cols. Some entries may be empty. The individual column entries are treated by LATEX as though they were enclosed in braces { }, so that any changes in type style or size are restricted to that one column. \hline This command may only appear before the first row or immediately after a \\ row termination. It draws a horizontal line the full width of the table below the row that was just ended, or at the top of the table if it comes at the beginning. Two \hline commands together draw two horizontal lines with a little space between them. \cline{m − n} This command draws a horizontal line from the left side of column m to the right side of column n. Like \hline, it may only be given just after a \\ row termination and there may be more than one after another. The command \cline{1-3} \cline{5-7} draws two horizontal lines from column 1 to 3 and from column 5 to 7, below the row that was just ended. In each case, the full column widths are underlined. \multicolumn{num}{col}{text} This command combines the following num columns into a single column with their total width including intercolumn spacings. The argument col contains exactly one of the positioning symbols l, r, or c, with possible @-expressions and vertical lines |. A value of 1 may be given for num when the positioning argument is to be changed for that column in one particular row. In this context, a ‘column’ starts with a positioning symbol l, r, or c, and includes everything up to but excluding the next one. The first column also includes everything before the first positioning symbol. Thus |c@{}rl| contains three columns: the first is |c@{}, the second r, and the third l|. The \multicolumn command may only come at the start of a row or right after a column separation symbol &. \vline This command draws a vertical line with the height of the row at the location where it appears. In this way, vertical lines that do not extend the whole height of the table may be inserted within a column. 98 ! Chapter 4. Displayed Text If a p-type column contains \raggedright or \centering, the \\ forces a new line within the column entry and not the end of the whole row. If this occurs in the last column, then \\ cannot be used to terminate the row; instead one must use \tabularnewline to end such a row. Since a table is a vertical box of the same sort as parbox and minipage, it may be positioned horizontally with other boxes or text (see examples in Section 4.7.3). In particular, the table must be enclosed within \begin{center} table \end{center} in order to center it on the page. 4.8.2 ! Table style parameters There are a number of style parameters used in generating tables which LATEX sets to standard values. These may be altered by the user, either globally within the preamble or locally inside an environment. They should not be changed within the tabular environment itself. \tabcolsep is half the width of the spacing that is inserted between columns in the tabular and tabular* environments; \arraycolsep is the corresponding half intercolumn spacing for the array environment; \arrayrulewidth is the thickness of the vertical and horizontal lines within a table; \doublerulesep is the separation between the lines of a double rule. Changes in these parameters can be made with the \setlength command as usual. For example, to make the line thickness to be 0.5 mm, give \setlength {\arrayrulewidth}{0.5mm}. Furthermore, the parameter \arraystretch can be used to change the distance between the rows of a table. This is a multiplying factor, with a standard value of 1. A value of 1.5 means that the inter-row spacing is increased by 50%. A new value is set by redefining the parameter with the command \renewcommand{\arraystretch}{factor} 4.8.3 Table examples Creating tables is much easier in practice than it would seem from the above list of formatting possibilities. This is best illustrated with a few examples. The simplest table consists of a row of columns in which the text entries are either centered or justified to one side. The column widths, the spacing between the columns, and thus the entire width of the table are automatically calculated. 4.8. Tables Position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Club Amesville Rockets Borden Comets Clarkson Chargers Daysdon Bombers Edgartown Devils Freeburg Fighters Gadsby Tigers Harrisville Hotshots Idleton Shovers Jamestown Hornets Kingston Cowboys Lonsdale Stompers Marsdon Heroes Norburg Flames Ollison Champions Petersville Lancers Quincy Giants Ralston Regulars 99 Games W T L Goals Points 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 19 18 17 14 16 15 15 12 13 11 13 12 9 10 8 6 7 3 13 9 7 10 6 7 7 11 9 11 6 8 13 8 9 8 5 11 1 6 9 9 11 11 11 10 11 11 14 13 11 15 16 19 21 19 66:31 65:37 70:44 66:50 63:53 64:47 52:37 62:58 49:51 48:47 54:45 50:57 50:42 50:68 42:49 31:77 40:89 37:74 51:15 45:21 41:25 38:28 38:28 37:29 37:29 35:31 35:31 33:33 32:34 32:34 31:35 28:38 25:41 20:46 19:47 17:49 The above table is made up of eight columns, the first of which is right justified, the second left justified, the third centered, the next three right justified again, and the last two centered. The column formatting argument in the tabular environment thus appears as {rlcrrrcc} The text to produce this table is \begin{tabular}{rlcrrrcc} Position & Club & Games & 1 & Amesville Rockets & 2 & Borden Comets & ... & ..... & 17 & Quincy Giants & 18 & Ralston Regulars & \end{tabular} W & T & 33 & 19 33 & 18 .. & .. 33 & 7 33 & 3 L & & & & & & Goals 13 & 1 9 & 6 .. & .. 5 & 21 11 & 19 & & & & & & Points\\[0.5ex] 66:31 & 51:15 \\ 65:37 & 45:21 \\ ... & ... \\ 40:89 & 19:47 \\ 37:74 & 17:49 In each row, the individual columns are separated from one another by the symbol & and the row itself is terminated with the \\ command. The [0.5ex] at the end of the first row adds extra vertical spacing between the first two rows. The last row does not need the termination symbol since it is ended automatically by the \end{tabular} command. The columns may be separated by vertical rules by including the symbol | in the column formatting argument. Changing the first line to \begin{tabular}{r|l||c|rrr|c|c} 100 Chapter 4. Displayed Text results in Position Club 1 2 .. . 17 18 Amesville Rockets Borden Comets .. . Quincy Giants Ralston Regulars Games W T L Goals Points 33 33 19 18 13 9 1 6 66:31 65:37 33 33 7 3 5 11 21 19 40:89 37:74 51:15 45:21 .. . 19:47 17:49 The same symbol | before the first or after the last column format generates a vertical line on the outside edge of the table. Two symbols || produce a double vertical line. Horizontal lines over the whole width of the table are created with the command \hline. They may only appear right after a row termination \\ or at the very beginning of the table. Two such commands \hline\hline draw a double horizontal line. \begin{tabular}{|r|l||c|rrr|c|c|} \hline Position & Club & Games & W & T & L & Goals & Points\\ \hline\hline 1 & Amesville Rockets & 33 & 19 & 13 & 1 & 66:31 & 51:15 \\ \hline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 & Ralston Regulars & 33 & 3 & 11 & 19 & 37:74 & 17:49 \\ \hline \end{tabular} The table now appears as Position 1 2 .. . 17 18 Club Amesville Rockets Borden Comets .. . Quincy Giants Ralston Regulars Games W T L Goals Points 33 33 19 18 13 9 1 6 66:31 65:37 33 33 7 3 5 11 21 19 40:89 37:74 51:15 45:21 .. . 19:47 17:49 In this case, the row termination \\ must be given for the last row too because of the presence of \hline at the end of the table. In this example, all rows contain the same entry in the third column, that is, 33. Such a common entry can be automatically inserted in the column format as an @-expression of the form @{text}, which places text between the neighboring columns. This could be accomplished for our example by changing the column format to {rl@{ 33 }rrrcc} or {|r|l||@{ 33 }|rrr|c|c|} so that the text ‘ 33 ’, blanks included, appears between the second and third columns in every row. This produces the same table with slightly different row entries: for example, the fourth row would now be given as 4.8. Tables 4 ! & Daysdon Bombers & 14 & 10 & 101 9 & 66:50 & 38:28 \\ The column format now consists of only seven column definitions, rlrrrcc. The previous third column c has been removed, and so each row contains one less column separation symbol &. The new third column, the number of games won, begins with the second & and is separated from the club name by the contents of @{ 33 }, which is entered automatically without any additional & symbol. The last two columns give the relations between goals and points won and lost as a centered entry of the form m:n. The colons ‘:’ are only coincidentally ordered exactly over one another since two-digit numbers appear in every case on both sides of the colon. If one entry had been 9:101, the colon would have been shifted slightly to the left as the entire entry was centered. A vertical alignment of the ‘:’ independent of the number of digits can also be achieved using an @-expression of the form r@{:}l in the column format. This means that a colon is placed in every row between a right and a left justified column. The column formatting argument in the example now becomes {rl@{ 33 }rrrr@{:}lr@{:}l} or {|r|l||@{ 33 }|rrr|r@{:}l|r@{:}l|} and the row entry is 4 & Daysdon Bombers & 14 & 10 & ! 9 & 66 & 50 & 38 & 28 \\ Each of the former c columns has been replaced by the two columns in r@{:}l. An @-expression inserts its text between the neighboring columns, removing the intercolumn spacing that would normally be there. Thus the r column is justified flush right with the ‘:’ and the following l column flush left. The same method can be employed when a column consists of numbers with decimal points and a varying number of digits. The entries for the goal and point relationships are now made up of two columns positioned about the ‘:’ symbol. This causes no problems for entering the number of goals won and lost or for the number of plus and minus points, since each entry has its own column. The column headings, however, are the words ‘Goals’ and ‘Points’, stretching over two columns each and without the colon. This is accomplished with the \multicolumn command, which merges selected columns in a particular row and redefines the column format. The first row of the unframed soccer table is then Position& Club & W & T & L & \multicolumn{2}{c}{Goals} & \multicolumn{2}{c}{Points}\\[0.5ex] Here \multicolumn{2}{c}{Goals} means that the next two columns are to be combined into a centered column, containing the text ‘Goals’. For the framed table, the new formatting argument in the \multicolumn commands must be {c|} since the vertical line symbol | was also removed when the old columns were combined. In deciding what belongs to a given 102 Chapter 4. Displayed Text column, use the rule that a column ‘owns’ everything up to but excluding the next r, l, or c. The table of final results for our soccer league 2002/03 is to have the following title: \begin{tabular}{|r|l||rrr|r@{:}l|r@{:}l||c|}\hline \multicolumn{10}{|c|}{\bfseries 1st Regional Soccer League --Final Results 2002/03}\\ \hline &\itshape Club &\itshape W &\itshape T &\itshape L & \multicolumn{2}{c|}{\itshape Goals} & \multicolumn{2}{c||}{\itshape Points} & \itshape Remarks \\ \hline\hline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1st Regional Soccer League — Final Results 2002/03 Club W T L Goals Points Remarks 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Amesville Rockets Borden Comets Clarkson Chargers Daysdon Bombers Edgartown Devils Freeburg Fighters Gadsby Tigers Harrisville Hotshots Idleton Shovers Jamestown Hornets Kingston Cowboys Lonsdale Stompers Marsdon Heroes Norburg Flames Ollison Champions Petersville Lancers Quincy Giants Ralston Regulars 19 18 17 14 16 15 15 12 13 11 13 12 9 10 8 6 7 3 13 9 7 10 6 7 7 11 9 11 6 8 13 8 9 8 5 11 1 6 9 9 11 11 11 10 11 11 14 13 11 15 16 19 21 19 66:31 65:37 70:44 66:50 63:53 64:47 52:37 62:58 49:51 48:47 54:45 50:57 50:42 50:68 42:49 31:77 40:89 37:74 51:15 45:21 41:25 38:28 38:28 37:29 37:29 35:31 35:31 33:33 32:34 32:34 31:35 28:38 25:41 20:46 19:47 17:49 League Champs Trophy Winners Candidates for National League Medium Teams Disbanding Demoted The horizontal lines for positions 3–5, 7–14, and 17 were made with the command \cline{1-9} while all the others used \hline: 11 ! & Kingston Cowboys & 13 & 6 & 14 & 54&45 & 32&34 & Medium Teams \\ \cline{1-9} The last two rows of the table deserve a comment. The remark ‘Demoted’ is vertically placed in the middle of the two rows. This is accomplished by typing 18 & Ralston Regulars & 3 & 11 & 19 & 37&74 & 17&49 & \raisebox{1.5ex}[0pt]{Demoted}\\ \hline 4.8. Tables 103 The \raisebox command lifts the text ‘Demoted’ by 1.5 ex. If the optional argument [0pt] had been left out, this lifting of the box would have increased the total height of the last row by 1.5 ex. This would have resulted in correspondingly more vertical spacing between the horizontal line of row 17 and the text of row 18. This additional spacing is suppressed by the optional argument height = [0pt]. (See Section 4.7.2 for a description of the \raisebox command.) Occasionally one wants to increase the vertical spacing between horizontal lines and enclosed text. The soccer table would look better if the heading were thus: 1st Regional Soccer League — Final Results 2002/03 Club W T L Goals Points Remarks This is done by inserting an invisible vertical rule, a strut (Section 4.7.6), into the heading text: \multicolumn{10}{|c|}{\rule[-3mm]{0mm}{8mm}\bfseries 1st Regional Soccer League --- Final Results 2002/03}\\ \hline The included rule has a width of 0 mm, which makes it invisible, extends 3 mm below the baseline, and is 8 mm high. It thus stretches 5 mm (8 − 3) above the baseline. It effectively pushes the horizontal lines away from the baseline in both directions. If a row consists of more than one column, it is sufficient to include a strut in only one of them since the size of the whole row is determined by the largest column. Exercise 4.12: Produce your own table for the final results of your favorite team sport in the same manner as for the soccer results above. Watch out that the colons ‘:’ are properly aligned for the goals and points relationships. Exercise 4.13: Generate the following timetable. 6.15–7.15 pm Day Subj. Mon. UNIX Tues. Wed. Fri. LATEX UNIX LATEX Teacher Room Dr. Smith Comp. Ctr Miss Baker Conf. Room Dr. Smith Comp. Ctr Miss Baker Conf. Room 7.20–8.20 pm Subj. Fortran Fortran C C++ Teacher Room Ms. Clarke Hall A Ms. Clarke Conf. Room Dr. Jones Hall B Ms. Clarke Conf. Room 8.30–9.30 pm Subj. Math. Math. ComSci. Teacher Room Mr. Mills Hall A Mr. Mills Hall A Dr. Jones Hall B canceled 104 Chapter 4. Displayed Text The entries ‘Day’ and ‘Subj.’ are raised in the same way as ‘Demoted’ was in the soccer table. To simplify its application, one can introduce a user-defined command with \newcommand{\rb}[1]{\raisebox{1.5ex}[0pt]{#1}} (see Section 8.3.2) so that \rb{entry} behaves the same as \raisebox{1.5ex}[0pt]{entry}. This can be used, for example, as \rb{ Mon.} or \rb{UNIX} to elevate the entries by the necessary amount. In all the above examples, the entries in the individual columns are each a single line. Some tables contain certain columns with several lines of text that are somewhat separated from the rest of the row: Model Description FBD 360 Desktop: XP3600+ Processor, 512 MB DDR-RAM, 80 GB hard disk, 16x DVD drive, 32x CDRW drive, 64 MB TV output, Windows XP, 15” monitor 999.00 FBD 480 Desktop DeLuxe: same as FBD 360 but with XP4800+ Processor, 48x CDRW drive, 17” monitor 1399.00 FBT 240 Laptop: XP2400+, 512 MB RAM, 40 GB hard disk, 56 kb modem, 32x speed DVD/CD-RW drive, 2x USB, 15” display, Windows XP, Infrared interface 1299.00 Price The above table is made up of three columns, the first left justified, the third right justified. The middle column contains several lines of text with a line width of 7.5 cm. This is generated with the column formatting symbol p{width}. The whole column formatting argument in this example is {lp{7.5cm}r}. \begin{tabular}{lp{7.5cm}r} \bfseries Model & Description & \bfseries Price \\[1ex] FBD 360 &\small{\bfseries Desktop}: XP3600+ Processor, 512˜MB DDR-RAM, 80˜GB hard disk, 16x DVD drive, 32x CDRW drive, 64˜MB TV˜output, Windows˜XP, 15’’ monitor & 999.00\\ . . . . . . . . . . . . 15’’ display, Windows˜XP, Infrared interface& 1299.00 \end{tabular} The text for the middle column is simply typed in, being broken up into lines of width 8.0 cm automatically. The column is separated from the others with the & symbol in the usual way. Warning: The line termination command \\ is ambiguous within a p column, for it can either start a whole new row, or if \raggedright or \centering have been given, it ends a line of text within that column entry. In this case, if this is the last column in the row, the only way to 4.8. Tables 105 terminate the row is with \tabularnewline which always starts a new row. Exercise 4.14: Produce the following table. Course and Date Brief Description Prerequisites Introduction to LSEDIT March 14 – 16 Logging on — explanation of the VMS file system — explanation and intensive application of the VMS editor LSEDIT — user modifications none Introduction to LATEX March 21 – 25 Word processors and formatting programs — text and commands — environments — document and page styles — displayed text — math equations — simple user-defined structures LSEDIT The final example describes a blank form produced as a framed table. The difficulty here is to set the heights and widths of the empty boxes, since these are normally determined automatically by the text entries. The example shows how this may be accomplished with the help of struts and \hspace commands. Budget Plan 2003–2004 Project Year Investment Costs Operating Costs Industrial Contracts Signature Nr. Name 2003 2004 2005 € US $ € US $ € US $ Authorization \newsavebox{\k}\newsavebox{\kkk} \sbox{\k}{\framebox[4mm]{\rule{0mm}{3mm}}} \sbox{\kkk}{\usebox{\k}\usebox{\k}\usebox{\k}} \begin{tabular} {|l|c|c|c|}\hline \multicolumn{4}{|c|}{\rule[-0.3cm]{0mm}{0.8cm}\bfseries Budget Plan 2003--2004}\\ \hline\hline \rule[-0.4cm]{0mm}{1cm}Project & \multicolumn{3}{l|}{Nr. \usebox{\kkk}\hspace{0.5cm} \vline\hspace{0.5cm}Name\usebox{\kkk}\usebox{\kkk}\usebox{\kkk} \usebox{\kk}}\\ \hline 106 Chapter 4. Displayed Text \multicolumn{1}{|r|}{Year} & 2003 & 2004 & 2005 \\ \cline{2-4} & \euro\ \vline\ US \$ & \euro\ \vline\ US \$ & \euro\ \vline\ US \$ \\ \hline Investment & \hspace{2.5cm}& \hspace{2.5cm}& \hspace{2.5cm} \\ Costs & & & \\ \hline Operating & & & \\ Costs & & & \\ \hline Industrial& & & \\ Contracts & & & \\ \hline \multicolumn{4}{|l|}{\rule[-1.0cm]{0mm}{1.3cm}Signature \hspace{5cm}\vline˜Authorization} \\ \hline \end{tabular} The first three lines are only indirectly related to the table constructo be drawn when the tion. They arrange for three empty boxes command \usebox{\kkk} is given (see Section 4.7.1). Except for the command \hspace{2.5cm} to set the column widths of the last three columns and the command \vline to draw a vertical line within a column, this example contains nothing new that was not in the previous examples. It is only necessary to give a brief explanation of the last row in the table: The command \multicolumn{4}{|l|} merges all four table columns into one, in which the text is set flush with the left margin. This text consists first of a strut \rule[-12mm]{0mm}{15mm} that says the height of the last row begins 12 mm below the baseline and is a total of 15 mm high. Then, beginning at the left margin, comes the word Signature, followed 5 cm later by \vline, a vertical line. The word Authorization is separated from the vertical line by a blank space (˜). The above examples clearly illustrate how the column widths and row heights are automatically determined for tables. These sizes, however, may be influenced by struts and \hspace commands. In addition, the commands described in Section 4.8.2 permit the intercolumn and interrow spacings as well as line thickness to be altered. For example, \setlength{\tabcolsep}{5mm} inserts 5 mm of spacing before and after every column; that is, it produces an intercolumn spacing of 10 mm. Section 4.8.2 gives more information about the use of these table style parameters. 4.8.4 Extension packages for tables As powerful as the tabular environment is, it does have limitations. For this reason, there are a number of tools packages (Section B.5.4) that add additional features for constructing tables. 4.8. Tables Package: array 107 The array package extends the normal functionality of the tabular and array environments by adding several column formatting arguments, and by allowing the user to be able to define his or her own such arguments. m{wth} produces a column of width wth which is aligned vertically in the middle. (The standard p{wth} aligns the text with the top line.) b{wth} is like p and m but aligns the text on the bottom line. >{decl} inserts decl before the next column; thus >{\bfseries} sets the entire column in bold face without having to type \bfseries in each row. <{decl} inserts decl after the last column; to have a centered column in math mode, give >{$}c<{$}. !{decl} inserts decl between two columns without removing the normal intercolumn spacing, as for @{decl}. With \newcolumntype{type}{decl} one can define new column specifiers for multiple applications. For example, to have C defined as a centered math column, give \newcolumntype{C}{>{$}c<{$}} The height of all rows can be increased by setting \extrarowheight to some value with \setlength; this is useful to prevent horizontal lines from being too close to the text below them. With \firsthline and \lasthline, horizontal lines can be issued before the first and after the last rows respectively without interfering with the vertical alignment of the table. Package: The dcolumn package loads the array package and defines a column dcolumn specifier D to align a column of numbers on a decimal point. Its syntax is D{in char}{out char}{number} where in char is the input character for the decimal point (say .), out char is the character that is output (say \cdot), and number is the maximum number of decimal places. If number is negative, the column is centered on the decimal point, otherwise it is right justified. Later versions allow number to specify the number of digits on both sides of the decimal point, for example as 3.2. Package: The tabularx package loads the array package and defines an tabularx environment tabularx which makes a table of a desired total width, like tabular*, but in which the columns expand, not the intercolumn spacings. The column specifier X is used to indicate the expandable columns, and is equivalent to p{wth} where wth is adjusted to the necessary size. For example, \begin{tabularx}{10cm}{c X l X} ... \end{tabularx} produces a table of width 10 cm with columns 2 and 4 expandable. 108 Chapter 4. Displayed Text Package: delarray The delarray package loads the array package and redefines the array environment so that it may be enclosed in braces that are automatically adjusted in size, as with the \left and \right commands of Section 5.4.1. The braces surround the column specifier. For example, " # a b \begin{array}[{cc}] a & b \\ c & d \end{array} ⇒ c d Package: longtable The longtable package produces tables extending over several pages. It does not require the array package, but does recognize its extra features if loaded. The longtable environment takes the same column formatting argument as tabular and array, but has additional row entries at the start to determine: • those rows that appear at the start of the table, terminated by \endfirsthead; this often includes the main \caption; • those at the top of every continuation page, terminated by \endhead; these normally include an additional \caption and the column headers; • those at the bottom of each page, terminated by \endfoot; • and those rows at the end of the table, terminated by \endlastfoot. An example of a long table is: \begin{longtable}{|l|c|r|} \caption[Short title]{Demonstration of a long table}\\ \hline Left & Center & Right \\ \hline \endfirsthead \caption[]{\emph{continued}}\\ \hline Left & Center & Right \\ \hline \endhead \hline \multicolumn{3}{r}{\emph{continued on next page}} \endfoot \hline\endlastfoot Twenty-two & fifty & A hundred and eighty \\ 22 & 50 & 180 \\ . . . . . . \end{longtable} The \caption command normally may only appear within table and figure environments (Section 7.4) but may also be used within longtable which never goes into a table environment; in a continued row, \caption must have an empty optional argument [] to prevent multiple entries in the list of tables. A \newpage command forces a new page within the long table. Up to four LATEX runs may be needed to get the column widths right. 4.8. Tables 109 Primary Energy Consumption Energy Source Total Consumption (in million tons of BCUa ) of which (percentages) petroleum bituminous coal brown coal natural gas nuclear energy otherb 1975 1980 1986 347.7 390.2 385.0 52.1 19.1 9.9 14.2 2.0 2.7 47.6 19.8 10.0 16.5 3.7 2.3 43.2 20.0 8.6 15.1 10.1 3.0 a BCU = Bituminous Coal Unit (1 ton BCU corresponds to the heating equivalent of 1 ton of bituminous coal = 8140 kwh) b Wind, water, solar energy, etc. Source: Energy Balance Study Group, Essen 1987. 4.8.5 Floating tables In Chapter 7 we explain how figures and tables can be made to float, that is, to be moved to the top or bottom of a page, or to a separate page altogether. The reason for doing this is that the author does not know in advance where the page breaks will occur, and so does not know if there is enough room on the current page for such a large object. The float mechanism allows the material to be saved and then placed later at an appropriate location. It also allows for table and figure captions and automatic numbering. Table material is made to float with the environment: \begin{table} head text table foot text \end{table} where table stands for the entire table as defined in a tabular environment, head text for whatever text appears above the table, and foot text for that below. Widths, spacing, and positioning of the texts relative to the table are all matters for the user to arrange. Independently of the enclosed text, everything that appears between \begin{table} and \end{table} is normally placed at the start of the current page. If a table already occupies the top of the page, an attempt is made to place it at the page bottom, if there is enough space for it. Otherwise, it will be placed on the next page, where further tables may be accumulated. The surrounding text is printed as though the table were not there. For further details about floats in general, including automatic sequential numbering, see Chapter 7. The table at the top of this page was generated within the text at this location with the following (excluding the footnotes, which are described later in Section 4.10.4): 110 Chapter 4. Displayed Text \begin{table} {\bfseries Primary Energy Consumption}\\[1ex] \begin{tabular*}{118mm}{@{}ll...rr@{}} . . . . . . . . . . . . . . . . . . . . \end{tabular*}\\[0.5ex] \emph{Source:} Energy Balance Study Group, . . . \end{table} There are a number of formatting parameters that may be used in connection with the table environment, which are described together with those for figures in Section 7.3. Exercise 4.15: Complete the above text for the table on the previous page (without the footnotes). Pay attention to the following questions (check the explanations for the @-expressions in Section 4.8.1): 1. What is the effect of the @{} entries at the beginning and end of the formatting definition? 2. The tabular* environment generates a table with a given width, here 118 mm. What would be the effect of @{extracolsep{\fill}} at the beginning of the formatting definition? 3. Where in the formatting definition should @{extracolsep{\fill}} and the countermanding @{\hspace{1em}}@{\extracolsep{1em}} appear in order to format the table as it is printed here? How would the table appear if only @{\extracolsep{1em}} were given as countermand? 4.9 Printing literal text Occasionally it is necessary to print text exactly as it is typed, with all special characters, blanks, and line breaks appearing literally, unformatted, and in a typewriter font. Lines of computer code or samples of LATEX input text are examples of such literal text. This is accomplished with the environments \begin{verbatim} \begin{verbatim*} text text \end{verbatim} \end{verbatim*} A new line is inserted before and after these environments. With the *-form, blanks are printed with the symbol to make them visible. As an example, on page 115 some input text is printed to demonstrate the use of footnotes in forbidden modes. This was done with \begin{verbatim} \addtocounter{footnote}{-1}\footnotetext{Small insects} \stepcounter{footnote}\footnotetext{Large mammals} \end{verbatim} Literal text may also be printed within a line using the commands \verb and \verb*, as for example 4.9. Printing literal text \verb=\emph{words of text}= \verb*=\emph{words of text}= 111 \emph{words of text} \emph{words of text} where the first character after \verb or \verb* (here =) is the delimiter, such that all text up to the next occurrence of that character is printed literally. This character may not appear in the literal text, obviously. In contrast to the behavior in the verbatim environment, the literal text must be all on one line in the input text, otherwise an error message is printed. This is to indicate that you just might have forgotten to repeat the delimiting character. Important: neither the verbatim environment nor the \verb command may be used in an argument of any other command! Exercise 4.16: Reproduce some input lines from this book as literal text. 4.9.1 Extension packages for literal text Package: alltt The standard package alltt (Section B.5.3, page 392) provides an alltt environment that also prints its contents literally in a typewriter font, except that the characters \ { } retain their normal meaning. Thus LATEX commands can be included within the literal text. For example, \begin{alltt} Underlining \underline{typewriter} text is also possible. Note that dollar ($) and percent (%) signs are treated \emph{literally}. \end{alltt} Underlining typewriter text is also possible. Note that dollar ($) and percent (%) signs are treated literally. The standard package shortvrb (Section B.5.3, page 393) offers a shorthand for the \verb command. After issuing \MakeShortVerb{\|}, one can print short literal text with |text|. The counter command \DeleteShortVerb{\|} then restores the original meaning to |. Any character may be temporarily turned into a literal switch this way. Package: One problem with the verbatim environment is that the entire litverbatim eral text is input and stored before processing, something that can lead to memory overflows. The verbatim package in the tools collection (Section B.5.4, page 396) re-implements the environment to avoid this problem. A minor drawback is that there must not be any other text on the same line as the \end{verbatim}. The verbatim package offers two other extra features. It provides a comment environment that simply ignores its contents, as though each line started with a % sign (Section 4.11). And it adds a command \verbatiminput{filename} to input the specified file as literal text. This is useful for listing actual computer programs rather than copying them into the LATEX file. Package: shortvrb 112 Chapter 4. Displayed Text 4.9.2 Email and Internet addresses Package: url Email and Internet addresses present some special problems that are solved with the url package by Donald Arseneau. These addresses are best listed in a typewriter font, often contain special symbols, and should never be hyphenated, since the hyphen could be interpreted as part of the address. The obvious solution would be to use the \verb command, which fulfills all these conditions. However, if the address does not fit on the current line, it will stick out into the right margin. Using \texttt instead will allow the words in the address to be broken over two lines, but at the price of inserting an ambiguous hyphen. Inserting the address with the \url command allows it to be broken at non-letters between words, without a hyphen. Moreover, its argument is treated literally, so all special characters are printed as given, just as with \verb. In fact, the argument of the \url command may either be enclosed in curly braces as usual, or delimited by some arbitrary character, just as with \verb. An Internet address may be given as \url{http://address.edu/home/page/} or an email address might be given as \url=fred.smith@general.services.gov= An Internet address is given as http://address.edu/home/ page/ or an email address might be given as fred.smith@ general.services.gov The \url command is to be preferred for another reason: it conforms to logical markup indicating the purpose of its argument. In fact, the hyperref package of Section 10.2.4 will even turn the argument into an active link, something it does not do for \verb arguments. The printed appearance of the address can be controlled by specifying \urlstyle{style}, where style is one of tt (default), rm, sf, or same, for typewriter, Roman, sans serif, or unchanged font, respectively. A fixed address can be predefined with, e.g., \urldef{\myurl}\url{myname@mydomain.uk} Now \myurl is used to print myname@mydomain.uk. There is also a \path command for giving directory/folder names, with the same syntax as \url. As logical markup, it has a different significance; for example, the hyperref package does not turn it into a link. For further information on advanced uses of this package, see the comments at the end of the file url.sty. 4.10 Footnotes and marginal notes 4.10.1 Standard footnotes Footnotes are generated with the command \footnote{footnote text} 4.10. Footnotes and marginal notes 113 which comes immediately after the word requiring an explanation in a footnote. The text footnote text appears as a footnote in a smaller typeface at the bottom of the page. The first line of the footnote is indented and is given the same footnote marker as that inserted in the main text. The first footnote on a page is separated from the rest of the page text by means of a short horizontal line. The standard footnote marker is a small, raised number1 , which is sequentially numbered. This footnote is produced with: ... raised number\footnote{The usual method of marking footnotes in a typewritten ... same page.}, which is ... The footnote numbering is incremented throughout the whole document for the article class, whereas it is reset to 1 for each new chapter in the report and book classes. The \footnote command may only be given within the normal paragraph mode, and not within math or LR modes. In practice, this means it may not appear within an LR box (Section 4.7.1) or a parbox (Section 4.7.3). However, it may be used within a minipage environment, in which case the footnote text is printed beneath the minipage and not at the bottom of the actual page.2 The \footnote command must immediately follow the word that is to receive the note, without any intervening blanks or spacing. A footnote at the end of a sentence can be given after the period, as in the last example above: ... of the actual page.\footnote{With nested ... wrong place.} 4.10.2 Non-standard footnotes If the user wishes the footnote numbering to be reset to 1 for each \section command with the article class, this may be achieved with \setcounter{footnote}{0} just before or after a \section command. The internal footnote counter has the name footnote. Each call to \footnote increments this counter by one and prints the new value in Arabic numbering as the footnote marker. A different style of marker can be implemented with the command \renewcommand{\thefootnote}{\number style{footnote}} 1 The usual method of marking footnotes in a typewritten manuscript with *, **, etc., could also be done; however, since the page breaks are not known at the time of typing the text, there would be a problem of avoiding duplication of the symbols on the same page. 2 With nested minipages, the footnote comes after the next \end{minipage} command, which could be at the wrong place. 114 Chapter 4. Displayed Text where number style is one of the counter print commands described in Section 4.3.5: \arabic, \roman, \Roman, \alph, or \Alph. However, for the counter footnote, there is an additional counter print command available, \fnsymbol, which prints the counter values 1–9 as one of nine symbols: * † ‡ § ¶ k ** †† ‡‡ It is up to the user to see that the footnote counter is reset to zero sometime before the tenth \footnote call. An optional argument may be added to the \footnote command \footnote[num]{footnote text} where num is a positive integer that is used instead of the value of the footnote counter for the marker. In this case, the footnote counter is not incremented. For example∗∗ , \renewcommand{\thefootnote}{\fnsymbol{footnote}} For example\footnote[7]{The 7th symbol ... marker.}, \renewcommand{\thefootnote}{\arabic{footnote}} where the last line is necessary to restore the footnote marker style to its standard form. Otherwise, all future footnotes would be marked with symbols and not with numbers. 4.10.3 Footnotes in forbidden modes A footnote marker can be inserted in the text with the command \footnotemark[num] even where the \footnote command is normally not allowed, that is, in LR boxes, tables, and math mode. The marker is either the optional argument num or, if it is omitted, the incremented value of the footnote counter. The footnote itself is not generated. This must be done external to the forbidden mode with the command \footnotetext[num]{footnote text} If the optional argument has been used for the footnote marker, the same num must be given as the option for the text command. Similarly, if no option was used for the marker, none may appear with the text. The footnote will be generated with the value of num or with that of the footnote counter. This counter is incremented by a call to \footnotemark without an optional argument. The corresponding \footnotetext command, on the other hand, does not alter the counter. ∗∗ The 7th symbol appears as the footnote marker. 4.10. Footnotes and marginal notes 115 If there are a number of \footnotemark commands without optional arguments appearing before the next \footnotetext command, it is necessary to adjust the counter with the command \addtocounter{footnote}{dif } where dif is a negative number saying how many times the counter must be set back. Then before every \footnotetext command, the counter must be incremented by one. This can be done either with the command \addtocounter, with dif =1, or with the command \stepcounter{footnote} which adds 1 to the given counter. For example: mosquitoes3 and elephants4 For example: \fbox{mosquitoes\footnotemark\ and elephants\footnotemark} generates the footnote markers 3 and 4 . Now the counter has the value 4. In order for the first \footnotetext outside the framed box to operate with the correct counter value, it must first be decremented by one. The two footnote texts are made with \addtocounter{footnote}{-1}\footnotetext{Small insects} \stepcounter{footnote}\footnotetext{Large mammals} immediately following the \fbox{} command. The footnote counter now has the same value as it did on leaving the \fbox. 4.10.4 Footnotes in minipages As mentioned in Section 4.10.1, footnote commands are allowed inside the minipage environment. However, the footnote appears underneath the minipage, not below the main page. Footnote commands within a minipagea have a different marker style. The footnote comes after the next \end{minipage} command.b Minipage footnotes have a counter separate from that of the main page, called mpfootnote, counting independently of footnote. a The \begin{minipage}{6cm} Footnote commands within a minipage\footnote{The marker is a raised lower-case letter.} have a different... \end{minipage} marker is a raised lower-case letter. out for nested minipages. b Watch ! Footnotes within a tabular environment can normally only be generated with the commands described above: \footnotemark within the table and 3 Small 4 Large insects mammals 116 Chapter 4. Displayed Text \footnotetext outside the environment. However, if the tabular environment is inside a minipage, normal \footnote commands may also be used inside the table. The footnote appears below the table where the minipage comes to an end. Exercise 4.17: Produce a number of footnotes in your standard exercise file by inserting them where you think fit and by selecting some appropriate footnote text. Exercise 4.18: Redefine the command \thefootnote so that the footnote markers become the symbols illustrated in Section 4.10.2. Add the redefinition to the preamble of your standard exercise file. Exercise 4.19: Complete Exercise 4.15 so that the footnotes a and b appear as in the table on page 109. 4.10.5 Marginal notes Notes in the page margin are produced with the command \marginpar{note text} which puts the text note text into the margin beginning at the level of the This line where the command is given. The marginal note appearing here was is a generated with margin- ... The marginal note \marginpar{This\\ is a\\ margin-\\al note} al note appearing here ... The text is normally enclosed in a parbox of width 1.9 cm (0.75 in). Such a narrow box causes great difficulties with line breaking, which is why the lines are manually broken with the \\ command in the above example. Such a box is far more appropriate for marginal notes in the =⇒ form of a single symbol, such as the arrow shown here. Another common use for the marginal note is to draw attention to certain text passages by marking them with a vertical bar in the margin. This is often done to indicate changes in a text, for comparison with earlier versions after updated single sheets have been redistributed. The example marking this paragraph was made by including \marginpar{\rule[-17.5mm]{1mm}{20mm}} in the first line. The width of the marginal note can be changed with a style parameter described in the next section. The user must watch out that the total page width does not become too big for the printer. By default, marginal notes appear in the right-hand margin of the page, or in the outer margin when the twoside option has been selected. ‘Outer’ means the right margin for odd pages, and left for even ones. With the twocolumn option, they are placed in the outside margins: left for the left column and right for the right one. 4.10. Footnotes and marginal notes 117 This leads to a problem for marginal markings such as the arrow illustrated on the previous page. On this page, it must point in the opposite direction. In fact, its direction depends on which side of the ⇐= page it is to appear, and that in turns depends on the page number or column. Since these are not known at the time of writing (and may even change with later revisions) it is necessary to have another solution. This is provided by the extended syntax of the \marginpar command \marginpar[left text]{right text} This form of the command contains two versions of the marginal text, left text to go into the left margin, and right text for the right margin, depending on which one is selected. Both the arrows on this and the previous page were generated with the same command \marginpar[\hfill$\Longrightarrow$]{$\Longleftarrow$} (The mathematical arrow commands are explained in Section 5.3.5.) ! =⇒ Without the \hfill command in the above \marginpar example, the arrow in the left margin appears as it does at the side of this paragraph, too far over to the left. The reason for this is that the \marginpar command sets its contents flush with the left edge of the narrow margin box, made visible here with a frame. This left edge is aligned with the main text only when the note is put on the right side; however, in the left margin, it is displaced from the main text. The \hfill command has the effect of setting the contents flush with the right edge of the margin box, which is then properly aligned with the main text. A similar device was used to make the first marginal note in this section. The actual command given was \marginpar[\flushright This\\ is a\\ margin-\\al note] {This\\ is a\\ margin-\\al note} Here \flushright (Section 4.2.2) is equivalent to putting an \hfill on each line. The standard positioning of the marginal notes can be switched with =⇒ the command \reversemarginpar. Once this command has been given, marginal notes will appear in the left margin, or in the ‘inner’ margin for the twoside option. The command \normalmarginpar restores normal behavior. These commands have no effect with the twocolumn option. If the note appears at the bottom of a page, it will extend downwards below the last line of regular text. For this reason, and because of the difficulties with line breaking for narrow columns, marginal notes should be kept short, limited to a few words or a symbol. 4.10.6 Style parameters for footnotes and marginal notes ! There are two footnote style parameters that may be changed as needed, either in the preamble or locally within an environment. \footnotesep The vertical spacing between two footnotes. This is a length that can be changed with the \setlength command. 118 Chapter 4. Displayed Text \footnoterule The command that draws a horizontal line between the page text and the footnotes. It should not add any net vertical spacing. It may be changed, for example, by \renewcommand{\footnoterule} {\rule{wth}{hght}\vspace{-hght}} A value of 0 cm for the hght produces an invisible line of zero thickness. The following style parameters may be changed to redefine how marginal notes appear: \marginparwidth determines the width of the margin box; \marginparsep sets the separation between the margin box and the main text; \marginparpush is the smallest vertical distance between two marginal notes. These parameters are all lengths and are assigned new values as usual with the \setlength command. 4.11 Comments within text All computer languages provide a means of inserting comments into the code. These are explanatory notes, documentation, history of development, or alternative text or code that has been temporarily deactivated. Comment lines are completely ignored during processing. They are only intended for human readers inspecting the source text. In LATEX, the comment character is the percent sign %. When this character appears in the text, it and the rest of the line are ignored. If a comment is several lines long, each line must be prefixed with %. As for other single character commands, the percent sign itself is printed with the command \%, as explained in Section 2.5.4. The comment character % is also useful for experimenting with text or definitions of user commands or formatting parameters, to try alternatives without deleting the old versions. By ‘commenting out’ selective lines, one can play around with variations without losing them. Large sections of text may be more effectively commented out with the comment environment from the verbatim package (page 111). Finally, the % character has an important role to play in suppressing implied blanks at the end of a line. This is especially desirable in user definitions where unexpected blanks can creep in between otherwise invisible declarations with arguments. See Section 8.5.2. Exercise 4.20: Comment out the changes from Exercise 4.18 in your preamble. These commands may be reactivated later by removing the % character. Mathematical Formulas 5 Mathematics is the soul of TEX. It was because the setting of mathematical formulas is so complicated in normal printing, not to mention on a typewriter, that Donald Knuth invented his text formatting system. On the other hand, the soul of LATEX is logical markup. Nevertheless, all the power of TEX’s math setting is also available in LATEX, offering an unbeatable combination. In this chapter, we confine ourselves to the elements of mathematical typesetting available in standard LATEX. The simplifications and additional elements provided by AMS-LATEX are reserved for Chapter 12. Mathematical formulas are produced by typing special descriptive text. This means that LATEX must be informed that the following text is to be interpreted as a mathematical formula, and it must also be told when the math text has come to an end and normal text recommences. The processing of math text is carried out by switching to math mode. Mathematical environments serve this purpose. 5.1 Mathematical environments Mathematical formulas may occur within a line of text, as (a + b)2 = a2 + 2ab + b2 , or separated from the main text as Z∞ f (x) dx ≈ 0 n X wi exi f (xi ) i=1 These two types are distinguished by referring to them as text and displayed formulas respectively. Text formulas, or equations, are generated with the environment \begin{math} formula text \end{math} Since text formulas are often very short, sometimes consisting of only a single character, a shorthand version is available as \( formula text \). 119 120 Chapter 5. Mathematical Formulas However, most authors prefer the very short form $formula text $ which is actually the TEX method. All three are essentially the same, and there is no reason not to use the $ sign. The contents of the formula, formula text, consist of math constructs, which are described in the following sections. Displayed formulas, or equations, are produced in the environments \begin{displaymath} \begin{equation} formula text formula text \end{displaymath} \end{equation} The difference between these two is that the equation environment automatically adds a sequential equation number. The displaymath environment may be given with the shorthand forms \[ . . . \] or $$. . . $$. By default displayed formulas are centered horizontally with the equation number, if it is present, set flush with the right margin. By selecting the document class option fleqn (Section 3.1.1), the formulas are set left justified with an adjustable indentation. This option remains valid for the entire document whereas the amount of indentation may be changed at will with \setlength{\mathindent}{indent}, where indent is a length specification. Moreover, the document class option leqno sets the equation numbers flush with the left margin throughout the whole document. Finally, multiline formulas can be created with the environments \begin{eqnarray} \begin{eqnarray*} formula text formula text \end{eqnarray} \end{eqnarray*} where the standard form adds a sequential equation number for each line and the *-form is without equation numbers. 5.2 Main elements of math mode 5.2.1 Constants and variables Numbers that appear within formulas are called constants, whereas simple variables are represented by single letters. The universal practice in mathematical typesetting is to put constants in Roman typeface and variables in italics. LATEX adheres to this rule automatically in math mode. Blanks are totally ignored and are included in the input text simply to improve the appearance for the writer. Spacing between constants, variables, and operators like +, −, = are set automatically by LATEX. For example $z=2a+3y$, $ z = 2 a + 3 y $ both produce z = 2a + 3y. Mathematical symbols that are available on the keyboard are + - = < > / : ! ’ | [ ] ( ) all of which may be used directly in formulas. The curly braces { } serve the purpose of logically combining parts of the formula and therefore 5.2. Main elements of math mode 121 cannot act as printable characters. To include braces in a formula, the same commands \{ and \} are used as in normal text. M(s) < M(t) < |M| = m y 00 = c{f [y 0 , y(x)] + g(x)} $M(s) 0. These are given by Cardan’s formula as y1 = u + v, y2 = − ip u+v + 3(u − v), 2 2 y3 = − u+v ip − 3(u − v) 2 2 where r u= 3 q −q + q2 + p 3 , r v= 3 q −q − q2 + p 3 Note: the spacings between the parts of the displayed equations are made with the spacing commands \quad and \qquad. Exercise 5.3: Select the option fleqn in the document class command and include the specification \setlength{\mathindent}{2cm} in the preamble. Redo the three y equations above, each as a separate displayed formula, using the equation environment instead of displaymath or \[. . . \] brackets. Exercise 5.4: Create the following text: Each of the measurements x1 < x2 < · · · < xr occurs p1 , p2 , . . . , pr times. The mean value and standard deviation are then v u X r u1 r 1 X x= pi xi , s=t pi (xi − x)2 n i=1 n i=1 where n = p1 + p2 + · · · + pr . Exercise 5.5: Although this equation looks very complicated, it should not present any great difficulties: p Z p Z p (ax + b)3 2 (ax + b)3 dx √ dx = + 2b ax + b + b2 x 3 x ax + b The same applies to 5.3 R8 −1 (dx/ √ 3 x) = 32 (82/3 + 12/3 ) = 15/2. Mathematical symbols There is a very wide range of symbols used in mathematical text, of which only a few are directly available from the keyboard. LATEX provides many of the mathematical symbols that are commonly used. They are called with the symbol name prefixed with the \ character. The names themselves are derived from their mathematical meanings. 5.3. Mathematical symbols 5.3.1 125 Greek letters Lower case letters α β γ δ  ε ζ η \alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta θ ϑ ι κ λ µ ν ξ \theta \vartheta \iota \kappa \lambda \mu \nu \xi o π $ ρ % σ ς o \pi \varpi \rho \varrho \sigma \varsigma τ υ φ ϕ χ ψ ω \tau \upsilon \phi \varphi \chi \psi \omega Ψ Ω \Psi \Omega Upper case letters Γ ∆ Θ \Gamma \Delta \Theta Λ Ξ Π \Lambda \Xi \Pi Σ Υ Φ \Sigma \Upsilon \Phi The Greek letters are made simply by putting the command character \ before the name of the letter. Upper case (capital) letters are distinguished by capitalizing the first letter of the name. Greek letters that do not appear in the above list are identical with some corresponding Latin letter. For example, upper case ρ is the same as Latin P and so needs no special symbol. LATEX normally sets the upper case Greek letters in Roman (upright) type within a mathematical formula. If they need to be in italics, this can be brought about with the math alphabet command \mathnormal: $\mathnormal{\Gamma\Pi\Phi}$ appears as Γ ΠΦ. Greek letters may only be used in math mode. If they are needed in normal text, the command must be enclosed in $. . . $ signs. 5.3.2 Calligraphic letters The following 26 calligraphic letters may also be used in math formulas: A, B, C, D, E, F , G, H , I, J, K, L, M, N , O, P, Q, R, S, T, U, V, W, X, Y, Z These are called with the math alphabet command \mathcal: $\mathcal{A, B, C,...,Z}$ 5.3.3 Binary operators Two mathematical quantities combined with one another to make a new quantity are said to be joined by a binary operation. The symbols that are available for use as binary operators are 126 Chapter 5. Mathematical Formulas ± ∓ × ÷ · ∗ ? † ‡ q \pm \mp \times \div \cdot \ast \star \dagger \ddagger \amalg \cap \cup \uplus \sqcap \sqcup \vee \wedge \oplus \ominus ⊗ \otimes ∩ ∪ ] u t ∨ ∧ ⊕ ◦ •  / . ô õ \circ \bullet \diamond \lhd \rhd \unlhd \unrhd \oslash \odot  ♦ 4 5 / . \ o \bigcirc \Box \Diamond \bigtriangleup \bigtriangledown \triangleleft \triangleright \setminus \wr Package: latexsym amsfonts The underlined symbol names in the above and following tables are only available if one of the packages latexsym (Section B.5.3) or amsfonts (Section 12.4.4) has been loaded. 5.3.4 Relations and their negations When two mathematical quantities are compared, they are connected by a relation. The different types of relational symbols for the various comparisons are ≤  ⊂ ⊆ ä v ∈ ` î \le \leq \ll \subset \subseteq \sqsubset \sqsubseteq \in \vdash \models ≥  ⊃ ⊇ å w 3 a ⊥ \ge \geq \gg \supset \supseteq \sqsupset \sqsupseteq \ni \dashv \perp ≠ . = ≈ › ≡ ∝ ≺  k \neq \doteq \approx \cong \equiv \propto \prec \preceq \parallel \| ∼ '  ^ _ ö   | \sim \simeq \asymp \smile \frown \bowtie \succ \succeq \mid | A number of the above symbols may be called by more than one name. For example, ≤ may be produced with either \le or \leq. The opposite, or negated, meaning of the relation is indicated in mathematics with a slash / through the symbol: = and 6= mean equals and not equals. One may put a slash through any of the above symbols by prefixing its name with \not. Thus \not\in yields 6∈. The same is true for the keyboard characters: \not=, \not>, and \not< produce 6=, 6>, and 6<. For \not= there is also the special command \neq producing ≠ which is a symbol on its own and not the combined 6=. The following symbols may be negated in this manner. Note that the last two, \not\in and \notin, are not exactly the same: 6∈ and ∉. The latter form is the preferred one. 5.3. Mathematical symbols 6< 6 ≤ 6≺ 6  6 ⊂ 6 ⊆ 6 v 6 ∈ 5.3.5 \not< \not\le \not\prec \not\preceq \not\subset \not\subseteq \not\sqsubseteq \not\in 6> 6 ≥ 6 6  6 ⊃ 6 ⊇ 6 w ∉ \not> \not\ge \not\succ \not\succeq \not\supset \not\supseteq \not\sqsupseteq \notin 6= 6 ≡ 6∼ 6 ' 6 ≈ 6 › 6  127 \not= \not\equiv \not\sim \not\simeq \not\approx \not\cong \not\asymp Arrows and pointers Mathematical manuscripts often contain arrow symbols, also called pointers. The following arrow symbols are available: ← \leftarrow \gets ⇐ \Leftarrow → \rightarrow \to ⇒ \Rightarrow ↔ \leftrightarrow a \Leftrightarrow 7→ \mapsto ←- \hookleftarrow ( \leftharpoonup ) \leftharpoondown z \rightleftharpoons ←− \longleftarrow ⇐= \Longleftarrow −→ \longrightarrow =⇒ \Longrightarrow ←→ \longleftrightarrow ⇐⇒ \Longleftrightarrow 7−→ \longmapsto ,→ \hookrightarrow * \rightharpoonup + \rightharpoondown Ž \leadsto ↑ \uparrow ⇑ \Uparrow ↓ \downarrow ⇓ x \Downarrow y ~ \updownarrow  \Updownarrow % \nearrow & \searrow . \swarrow - \nwarrow Here again the symbols → and ← may also be referred to under the names \to and \gets. Furthermore, the command \Longleftrightarrow may be substituted by \iff, although the latter ( ⇐⇒ ) has a little more spacing on either side than the former (⇐⇒). 5.3.6 Various other symbols The above lists by no means exhaust the complete repertoire of mathematical symbols. However, the following are additional characters that standard LATEX does make available. (Even more symbols are possible with the AMS symbol fonts and amssymb package, Section 12.4.4.) ℵ  ı  ` ℘ < = ’ \aleph \hbar \imath \jmath \ell \wp \Re \Im \mho 0 \prime ∅ \emptyset ∇ \nabla √ \surd ∂ \partial > \top ⊥ \bot ` \vdash a \dashv ∀ ∃ ¬ [ \ ] k ∠ \ \forall \exists \neg \flat \natural \sharp \| \angle \backslash  ♦ 4 ♣ ♦ ♥ ♠ ö ∞ \Box \Diamond \triangle \clubsuit \diamondsuit \heartsuit \spadesuit \Join \infty 128 Chapter 5. Mathematical Formulas 5.3.7 Symbols with two sizes The following symbols are printed in different sizes depending on whether they appear in text or displayed formulas: P X Y ` a N \bigotimes \bigsqcup L M \bigoplus _ \bigvee U ] \biguplus ^ \bigwedge S \oint F G \prod W \coprod V I Q \bigodot O [ \int H K \ Z R J T \sum \bigcap \bigcup The symbols \int and \sum have already been introduced in Section 5.2.5. There it was shown how these symbols may take on upper and lower limits; in the same way, all the above symbols may also be assigned upper and lower limits using the shifting commands ˆ and _. The positioning of the limits varies for some symbols depending on whether they occur in text or displayed formulas. As indicated in Section 5.2.5, the command \limits forces the limits to be written above and below the symbol where they would otherwise be placed beside it. Similarly the complementary command \nolimits sets them beside the symbol when the standard positioning is above and below. I∞ I∞ \[ \ointˆ\infty_0 0 n Y ν=0 5.3.8 \oint\limitsˆ\infty_0 \] 0 Yn ν=0 \[ \prodˆn_{\nu=0} \prod\nolimitsˆn_{\nu=0} \] Function names The universal standard for mathematical formulas is to set variable names in italics but the names of functions in Roman. If one were simply to write the function names sin or log in math mode, LATEX would interpret these as variables s i n and l o g and write them as sin and log. In order to tell LATEX that a function name is wanted, it is necessary to enter a command consisting of the backslash \ plus the function name. The following names are recognized by LATEX: \arccos \arcsin \arctan \arg \cos \cosh \cot \coth \csc \deg \det \dim \exp \gcd \hom \inf \ker \lg \lim \liminf \limsup \ln \log \max \min \Pr \sec \sin \sinh \sup \tan \tanh 5.3. Mathematical symbols 129 Some of these functions may also appear with limits attached to them. This is easily achieved by means of the subscript command after the name of the function: \lim_{x\to\infty} yields limx→∞ in text formulas and lim in displayed formulas x→∞ The following function names may accept a limit with the lowering (index) command _: \det \Pr \gcd \sup \inf \lim \liminf \limsup \max \min Finally, there are the function commands \bmod and \pmod{arg}, both of which produce the function mod in one of two forms: $ a \bmod b $ $ y \pmod{a+b} $ ⇒ ⇒ a mod b y (mod a + b). With AMS-LATEX (Section 12.2.5) it is possible to define additional function names. 5.3.9 Mathematical accents The following mathematical accents are available within math mode: â \hat{a} ǎ \check{a} ȧ \dot{a} ă \breve{a} á \acute{a} ä \ddot{a} à \grave{a} ã \tilde{a} å \mathring{a} ā \bar{a} ~ \vec{a} a The letters i and j should be printed without their dots when they are given an accent. To accomplish this, type the symbols \imath and \jmath instead of the letters, as in $\vec{\imath} + \tilde{\jmath}$: ~ ı + ̃ There are wider versions of \hat and \tilde available with the names \widehat and \widetilde. In this way, these accents may be placed over parts of a formula: d 1Æ − x = −y Ç xyz $\widehat{1-x}=\widehat{-y}$ $\widetilde{xyz}$ Exercise 5.6: The union of two sets A and B is the set of all elements that are in at least one of the two sets, and is designated as A ∪ B. This operation is commutative A ∪ B = B ∪ A and associative (A ∪ B) ∪ C = A ∪ (B ∪ C). If A ⊆ B, then A ∪ B = B. It then follows that A ∪ A = A, A ∪ {∅} = A and J ∪ A = J. Exercise 5.7: Applying l’Hôpital’s rule, one has lim x→0 πx π cos ln sin π x π tan x π / cos2 x cos2 π x sin π x = lim cos = lim = lim = lim =1 x 2 x→0 x→0 tan π x x→0 π / cos π x x→0 cos2 x ln sin x sin x 130 Chapter 5. Mathematical Formulas Exercise 5.8: The gamma function Γ (x) is defined as Γ (x) ≡ lim n→∞ n−1 Y ν=0 n! nx−1 n! nx−1 = lim ≡ n→∞ x(x + 1)(x + 2) · · · (x + n − 1) x+ν Z∞ e−t t x−1 dt 0 The integral definition is valid only for x > 0 (2nd Euler integral). Exercise 5.9: Remove the option fleqn from the document class command in Exercise 5.3 and redo the output. Exercise 5.10: ~ = xα, ~ ~ = βαx, ~ ~ = αx ~ + βx, ~ αx αβx (α + β)x ~y ~ =y ~x ~ but x ~×y ~ = −y ~ × x, ~ x ~y ~ = 0 for x ~ ⊥ y, ~ x ~ + y) ~ = αx ~ + αy. ~ α(x ~×y ~ = 0, for x ~ k y. ~ x Exercise 5.11: Reproduce Equations 5.1 and 5.2 from the next section. 5.4 Additional elements The math elements described in the previous sections already permit the construction of very complex formulas, such as √ lim x→0 √ √ 1 1+x−1 ( 1 + x − 1)( 1 + x + 1) 1 √ = = lim √ = lim x→0 x→0 2 x 1+x+1 x( 1 + x + 1) ∂2U ∂2U + =0 ∂x 2 ∂y 2 I(z) = sin( =⇒ UM = 1 4π I Σ 1 ∂U 1 ds − r ∂n 4π I Σ ∂ r1 ∂n U ds (5.1) (5.2) ∞ ∞ X (−1)n π 2n π (−1)n π 2n+1 π 2 X z ) z4n+1 − cos( z2 ) z4n+3 2 1 · 3 · · · (4n + 1) 2 1 · 3 · · · (4n + 3) n=0 n=0 (5.3) By reading the formulas from left to right there should be no difficulty in reconstructing the text that produced them. For example, the last equation is generated with \begin{equation} I(z) = \sin( \frac{\pi}{2} zˆ2 ) \sum_{n=0}ˆ\infty \frac{ (-1)ˆn \piˆ{2n} }{1 \cdot 3 \cdots (4n+1) } zˆ{4n+1} -\cos( \frac{\pi}{2} zˆ2 ) \sum_{n=0}ˆ\infty \frac{ (-1)ˆn \piˆ{2n+1} }{ 1 \cdot 3 \cdots (4n+3) } zˆ{4n+3} \end{equation} The above examples were made using the equation environment instead of the displaymath environment or its abbreviated form \[. . . \], which has the effect of adding the equation numbers automatically. In the document classes book and report, equations are sequentially numbered within the chapter, the number being preceded by the chapter number and set within parentheses ( ), as illustrated above. For document class 5.4. Additional elements 131 article, the equations are numbered sequentially throughout the entire document. By default the equation number appears right justified and vertically centered with the equation. If there is not enough room for it on the same line, it is printed right justified below the equation. If the document class option leqno has been selected, the equation numbers are set left justified for the entire document. The automatic numbering of equations means that the author may not know at the time of writing just what the equation number is. The LATEX cross-reference system described in Section 9.2.1 has already been explained for referring to section numbers (Section 3.3.3) and may also be used for equation numbers. By including a command \label{name} within the equation environment, one can print the unknown equation number in the text with the command \ref{name}, where name is a keyword consisting of any combination of letters, numbers, or symbols. Examining Equation 5.3 more closely, one notices that the two parentheses pairs ( ) in cos() and sin() could be somewhat larger. Furthermore, this equation just fills the line width, and if it were any longer, it would have to be broken at some appropriate spot and the parts positioned in a meaningful way relative to one another. None of the math elements described so far can accomplish these requirements. Even something so simple as including some normal text within a formula has not yet been mentioned. The rest of this section addresses these problems. Finally, there are times when one is not happy with the sizes that TEX 1 has chosen, as for example in the last integral of Equation 5.2 where ∂ r 1 would be more desirable than ∂ r . This and other formatting aids, such as adjusting horizontal spacing between parts of formulas, are dealt with in Section 5.5. 5.4.1 Automatic sizing of bracket symbols Mathematics often contains bracketing symbols, usually in pairs that enclose part of the formula. When printed, these bracket symbols should be the same size as the included partial formula. LATEX provides a pair of commands \left lbrack sub form \right rbrack to accomplish this. The command \left is placed immediately before the opening (left hand) bracket symbol lbrack while \right comes just before the closing (right hand) symbol rbrack. 132 Chapter 5. Mathematical Formulas \[ \left[ \int + \int \right]_{x=0}ˆ{x=1} \] The pair of brackets [ ] is adjusted to the size of the enclosed formula, as are the raised exponent and lowered index as well. Z x=1 Z + x=0 The commands \left and \right must appear as a pair. For every \left command there must be a corresponding \right command somewhere afterwards. The pairs may be nested. The first \left is paired with the last \right; the following \left with the second last \right, and so on. There must be the same number of \right as \left commands in a nesting. The corresponding bracket symbols lbrack and rbrack may be perfectly arbitrary and do not need to be a logical pair. This set of brackets is admittedly unusual but " permissible. a ~+y ~ +z ~= x \[ \vec{x} + \vec{y} + \vec{z} = b \left( ... \right[ \] Sometimes a formula contains only a single opening or closing bracket without a corresponding counterpart. However, the \left. . . \right commands must still be given as a pair, but with a period ‘.’ as an invisible bracket symbol.    −1 0 y=   +1 x<0 x=0 x>0 : : : \[ y = \left\{ \begin{array} {r@{\quad:\quad}l} -1 & x<0 \\ 0 & x=0 \\ +1 & x>0 \end{array} \right. \] The array environment in the above example is described in Section 4.8.1 and produces a table in math mode. The \left. . . \right commands may be applied to a total of 22 different symbols. These are ( [ { | / ( [ \{ | / ) ] } k \ ) ] \} \| \backslash b d h ↑ ↓ x y \lfloor \lceil \langle \uparrow \downarrow \updownarrow c e i ⇑ ⇓ ~  \rfloor \rceil \rangle \Uparrow \Downarrow \Updownarrow For example, \left|. . . \right| produces two vertical bars adjusted in height to contain the enclosed formula text.  Exercise 5.12: In Equation 5.3, generate cos π π cos( z2 ) and sin( z2 ). 2 2 π 2 z 2   and sin π 2 z 2  instead of 5.4. Additional elements 5.4.2 133 Ordinary text within a formula It is often necessary to include some normal text within a formula, for example single words such as and, or, if, and so on. In this case one must switch to LR mode (Section 4.7.1) while staying in math mode. This is carried out with the command \mbox{normal text} given inside the formula, together with horizontal spacing commands such as \quad or \hspace. For example: Xn = Xk \[ if and only if Yn = Yk and Zn = Zk X_n = X_k \qquad\mbox{if and only if}\qquad Y_n = Y_k \quad\mbox{and}\quad Z_n = Z_k \] In order to set a longer piece of text beside a displayed formula, as in some of the above examples, it is more appropriate to put both the formula and the text in their own parboxes or minipages, placed side by side with the proper vertical positioning. On the other hand, if letters from text fonts are required as mathematical symbols, they should be entered with the math alphabet commands: \mathrm \mathsf \mathtt \mathit \mathbf \mathcal We have already met \mathcal in Section 5.3.2 on calligraphic letters. All these commands function the same way: they set their argument in the corresponding font. B0 (x) Tij $\mathbf{B}ˆ0(x)$ \quad $\mathsf{T}ˆi_j$ The command \mathnormal in Section 5.3.1 also belongs to this group. The difference between it and \mathit is that it sets its argument in the regular math italic font, while the latter uses the normal text italic. The letters are the same, but the spacing is different. $\mathnormal{differ} \ne \mathit{differ}$ dif f er 6= differ All the math alphabet commands set their text in math mode, which means that spaces are ignored as usual. This is not the case for text placed in an \mbox. 5.4.3 Matrices and arrays a11 .. . an1 a12 .. . an2 ··· .. . ··· a1n .. . ann Structures like the one at the left are the basis for matrices, determinants, system of equations, and so on. They will all be referred to here as arrays. 134 Chapter 5. Mathematical Formulas Arrays are produced by means of the array environment, whose syntax and construction are described in Section 4.8.1 on tables. The array environment generates a table in math mode, that is, the column entries are interpreted as formula text. For example: a11 x1 + a12 x2 + · · · + a1n xn = b1 a22 x1 + a22 x2 + · · · + a2n xn = b2 ....................................... an1 x1 + an2 x2 + · · · + ann xn = bn \[ ! \begin{array}{*{3}{c@{\:+\:}}c@{\;=\;}c} a_{11}x_1 & a_{12}x_2 & \cdots & a_{1n}x_n & b_1 \\ a_{22}x_1 & a_{22}x_2 & \cdots & a_{2n}x_n & b_2 \\ \multicolumn{5}{c}{\dotfill} \\ a_{n1}x_1 & a_{n2}x_2 & \cdots & a_{nn}x_n & b_n \end{array} \] As a reminder of the table construction elements (Section 4.8.1): @{t} inserts the contents of t between the adjacent columns. In the above example, this is \:+\: and \;+\;. The commands \: and \; have not yet been introduced but they produce small horizontal spacing in math mode (Section 5.5.1). *{3}{c@{\:+\:}} is an abbreviation for three repetitions of the column definition c@{\:+\:}. c defines the column to be one of centered text. \multicolumn{5}{c} says that the next five columns are to be merged and replaced by one with centered text. The command \dotfill fills the column with dots. It is possible to nest array environments:      x11 x21 x12 x22 y z      \[ \left( \begin{array}{c} \left| \begin{array}{cc} x_{11} & x_{12} \\ x_{21} & x_{22} \end{array} \right| \\ y \\ z \end{array} \right) \] The outermost array consists of one column with centered text (c). The first entry in this column is also an array, with two centered columns. This array is surrounded left and right by vertical lines with adjusted sizes. The array environment is structurally the same as a vertical box. This means that it is treated as a single character within the surrounding environment, so that it may be coupled with other symbols and construction elements. (1,2,...,n) X p1

Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.6
Linearized                      : No
Has XFA                         : No
XMP Toolkit                     : Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:08:04
Create Date                     : 2004:01:15 10:14Z
Modify Date                     : 2011:04:12 13:50:55+01:00
Metadata Date                   : 2011:04:12 13:50:55+01:00
Producer                        : pdfTeX-1.0b-pdfcrypt; modified using iText 2.1.7 by 1T3XT
Format                          : application/pdf
Document ID                     : uuid:0b21e8d4-34c2-454f-8672-b3641aba8915
Instance ID                     : uuid:ddd987b5-4a46-466e-9a26-9aa354d3817c
Page Count                      : 658
EXIF Metadata provided by EXIF.tools

Navigation menu