LaTeX Document Structure
LaTeX Document Structure
LaTeX Document Structure
LaTeX/Document Structure
< LaTeX
\begin{document} 7. Linguistics
... Special Pages
\end{document}
1. Indexing
2. Glossary
3. Bibliography
You would put your text where the dots are. The reason for marking off Management
the beginning of your text is that LaTeX allows you to insert extra setup 4. More
specifications before it (where the blank line is in the example above: Bibliographies
we'll be using this soon). The reason for marking off the end of your Special Documents
text is to provide a place for LaTeX to be programmed to do extra stuff 1. Scientific Reports
automatically at the end of the document, like making an index. (Bachelor Report,
Master Thesis,
A useful side-effect of marking the end of the document text is that you
Dissertation)
can store comments or temporary text underneath the
2. Letters
\end{document} in the knowledge that LaTeX will never try to
3. Presentations
typeset them: 4. Teacher's Corner
5. Curriculum Vitae
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Creating Graphics
\end{document}
1. Introducing
...
Procedural
Graphics
2. MetaPost
Preamble [edit]
3. Picture
4. PGF/TikZ
Document classes [edit] 5. PSTricks
6. Xy-pic
When processing an input file, LaTeX needs to know the type of
7. Creating 3D
document the author wants to create. This is specified with the graphics
\documentclass command. It is recommended to put this
Programming
declaration at the very beginning.
1. Macros
2. Plain TeX
3. Creating
\documentclass[options]{class} Packages
4. Themes
Miscellaneous
Here, class specifies the type of document to be created. The 1. Modular
LaTeX distribution provides additional classes for other documents, Documents
including letters and slides. It is also possible to create your own, as is 2. Collaborative
Writing of LaTeX
often done by journal publishers, who simply provide you with their own
Documents
class file, which tells LaTeX how to format your content. But we'll be
3. Export To Other
happy with the standard article class for now. The options
Formats
parameter customizes the behavior of the document class. The options
Help and
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Help and
have to be separated by commas.
Recommendations
Example: an input file for a LaTeX document could start with the line 1. FAQ
2. Tips and Tricks
Appendices
\documentclass[11pt,twoside,a4paper]{article}
1. Authors
2. Links
3. Package
which instructs LaTeX to typeset the document as an article with a Reference
base font size of 11 points, and to produce a layout suitable for double 4. Sample LaTeX
documents
sided printing on A4 paper.
5. Index
Here are some document classes that can be used with LaTeX: 6. Command
Glossary
Document Classes
For articles in scientific journals, presentations, short edit this box • edit the
article
reports, program documentation, invitations, ... TOC
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
document with it [1]
letter For writing letters.
beamer For writing presentations (see LaTeX/Presentations).
The standard document classes that are a part of LaTeX are built to be fairly generic, which is why
they have a lot of options in common. Other classes may have different options (or none at all).
Normally, third party classes come with some documentation to let you know. The most common
options for the standard document classes are listed in the following table:
For example, if you want a report to be in 12pt type on A4, but printed one-sided in draft mode,
you would use:
\documentclass[12pt,a4paper,oneside,draft]{report}
Packages [edit]
While writing your document, you will probably find that there are some areas where basic LaTeX
cannot solve your problem. If you want to include graphics, colored text or source code from a file
into your document, you need to enhance the capabilities of LaTeX. Such enhancements are
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
called packages. Some packages come with the LaTeX base distribution. Others are provided
separately. Modern TeX distributions come with a large number of packages pre-installed. The
command to use a package is pretty simple: \usepackage :
\usepackage[options]{package}
command, where package is the name of the package and options is a list of keywords that trigger
special features in the package. For example, to use the color package, which lets you typeset in
colors, you would type:
\documentclass{report}
\usepackage{color}
\begin{document}
...
\end{document}
\usepackage[option1,option2,option3]{''package_name''}
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
The document environment [edit]
At the beginning of most documents there will be information about the document itself, such as
the title and date, and also information about the authors, such as name, address, email etc. All of
this type of information within LaTeX is collectively referred to as top matter. Although never
explicitly specified (there is no \topmatter command) you are likely to encounter the term within
LaTeX documentation.
A simple example:
\documentclass[11pt,a4paper]{report}
\begin{document}
\title{How to Structure a LaTeX Document}
\author{Andrew Roberts}
\date{December 2004}
\maketitle
\end{document}
The \title , \author , and \date commands are self-explanatory. You put the title, author
name, and date in curly braces after the relevant command. The title and author are usually
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
compulsory (at least if you want LaTeX to write the title automatically); if you omit the \date
command, LaTeX uses today's date by default. You always finish the top matter with the
\maketitle command, which tells LaTeX that it's complete and it can typeset the title according
to the information you have provided and the class (style) you are using. If you omit
\maketitle , the title will never be typeset.
Using this approach, you can only create a title with a fixed layout. If you want to create your title
freely, see the Title Creation section.
Abstract [edit]
As most research papers have an abstract, there are predefined commands for telling LaTeX
which part of the content makes up the abstract. This should appear in its logical order, therefore,
after the top matter, but before the main sections of the body. This command is available for the
document classes article and report, but not book.
\documentclass{article}
\begin{document}
\begin{abstract}
Your abstract goes here...
...
\end{abstract}
...
\end{document}
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
By default, LaTeX will use the word "Abstract" as a title for your abstract. If you want to change it
into anything else, e.g. "Executive Summary", add the following line before you begin the abstract
environment:
\renewcommand{\abstractname}{Executive Summary}
The commands for inserting sections are fairly intuitive. Of course, certain commands are
appropriate to different document classes. For example, a book has chapters but an article
doesn't. Here are some of the structure commands found in simple.tex.
\chapter{Introduction}
This chapter's content...
\section{Structure}
This section's content...
\subsection{Top Matter}
This subsection's content...
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
\subsubsection{Article Information}
This subsubsection's content...
Notice that you do not need to specify section numbers; LaTeX will sort that out for you. Also, for
sections, you do not need to use \begin and \end commands to indicate which content
belongs to a given block.
LaTeX provides 7 levels of depth for defining sections (see table below). Each section in this table
is a subsection of the one above it.
All the titles of the sections are added automatically to the table of contents (if you decide to insert
one). But if you make manual styling changes to your heading, for example a very long title, or
some special line-breaks or unusual font-play, this would appear in the Table of Contents as well,
which you almost certainly don't want. LaTeX allows you to give an optional extra version of the
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
heading text which only gets used in the Table of Contents and any running heads, if they are in
effect. This optional alternative heading goes in [square brackets] before the curly braces:
Numbering of the sections is performed automatically by LaTeX, so don't bother adding them
explicitly, just insert the heading you want between the curly braces. Parts get roman numerals
(Part I, Part II, etc.); chapters and sections get decimal numbering like this document, and
appendices (which are just a special case of chapters, and share the same structure) are lettered
(A, B, C, etc.).
You can change the depth to which section numbering occurs, so you can turn it off selectively. By
default it is set to 3. If you only want parts, chapters, and sections numbered, not subsections or
subsubsections etc., you can change the value of the secnumdepth counter using the
\setcounter command, giving the depth level you wish. For example, if you want to change it to
"1":
\setcounter{secnumdepth}{1}
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
A related counter is tocdepth, which specifies what depth to take the Table of Contents to. It can
be reset in exactly the same way as secnumdepth. For example:
\setcounter{tocdepth}{3}
To get an unnumbered section heading which does not go into the Table of Contents, follow the
command name with an asterisk before the opening curly brace:
\subsection*{Introduction}
All the divisional commands from \part* to \subparagraph* have this "starred" version which
can be used on special occasions for an unnumbered heading when the setting of secnumdepth
would normally mean it would be numbered.
If you want the unnumbered section to be in the table of contents anyway, use package
unnumberedtotoc [1]. It provides the command
\addsec{Introduction}
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
which will take care of a proper header as well. \addpart and addchap are also available.
KOMA classes provide those commands by default.
If you don't want to use package unnumberedtotoc, you have to do everything by hand using
\addcontentsline and \markright{} (or even \markboth{}{} ).
\section*{Introduction}
\markright{}
\addcontentsline{toc}{section}{Introduction}
Note that if you use PDF bookmarks you will need to add a phantom section so that hyperlinks will
lead to the correct place in the document. The \phantomsection command is defined in the
hyperref package, and is Commonly used like this:
\phantomsection
\addcontentsline{toc}{section}{Introduction}
\section*{Introduction}
For chapters you will also need to clear the page (this will also correct page numbering in the
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
ToC):
See Counters.
Paragraphs of text come after section headings. Simply type the text and leave a blank line
between paragraphs. The blank line means "start a new paragraph here": it does not mean you
get a blank line in the typeset output. For formatting paragraph indents and spacing between
paragraphs, refer to the Paragraph Formatting section.
All auto-numbered headings get entered in the Table of Contents (ToC) automatically. You don't
have to print a ToC, but if you want to, just add the command \tableofcontents at the point
where you want it printed (usually after the Abstract or Summary).
Entries for the ToC are recorded each time you process your document, and reproduced the next
time you process it, so you need to re-run LaTeX one extra time to ensure that all ToC
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
pagenumber references are correctly calculated. We've already seen how to use the optional
argument to the sectioning commands to add text to the ToC which is slightly different from the one
printed in the body of the document. It is also possible to add extra lines to the ToC, to force extra
or unnumbered section headings to be included.
The commands \listoffigures and \listoftables work in exactly the same way as
\tableofcontents to automatically list all your tables and figures. If you use them, they
normally go after the \tableofcontents command. The \tableofcontents command
normally shows only numbered section headings, and only down to the level defined by the
tocdepth counter, but you can add extra entries with the \addcontentsline command. For
example if you use an unnumbered section heading command to start a preliminary piece of text
like a Foreword or Preface, you can write:
\subsection*{Preface}
\addcontentsline{toc}{subsection}{Preface}
This will format an unnumbered ToC entry for "Preface" in the "subsection" style. You can use the
same mechanism to add lines to the List of Figures or List of Tables by substituting lof or lot for
toc . If the hyperref package is used and the link does not point to the correct chapter, the
command \phantomsection in combination with \clearpage or \cleardoublepage can be
used (see also Labels and Cross-referencing):
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
To change the title of the TOC, you have to paste this command
\renewcommand{\contentsname}{<New table of contents title>} in your document
preamble. The List of Figures (LoF) and List of Tables (LoT) names can be changed by replacing
the \contentsname with \listfigurename for LoF and \listtablename for LoT.
Depth [edit]
The default ToC will list headings of level 3 and above. To change how deep the table of contents
displays automatically the following command can be used in the preamble:
\setcounter{tocdepth}{4}
This will make the table of contents include everything down to paragraphs. The levels are defined
above on this page. Note that this solution does not permit changing the depth dynamically.
You can change the depth of specific section type, which could be useful for PDF bookmarks (if
you are using the hyperref package) :
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
\makeatletter
\renewcommand*{\toclevel@chapter}{-1} % Put chapter depth at the
same level as \part.
\chapter{Epilogue}
\renewcommand*{\toclevel@chapter}{0} % Put chapter depth back to its
default value.
\makeatother
In order to further tune the display or the numbering of the table of contents, for instance if the
appendix should be less detailed, you can make use of the tocvsec2 package (CTAN , doc ).
The standard LaTeX book class follows the same layout described above with some additions. By
default a book will be two-sided, i.e. left and right margins will change according to the page
number parity. Furthermore current chapter and section will be printed in the header.
If you do not make use of chapters, it is barely useful to use the book class.
Additionally the class provides macros to change the formatting of some places of the document.
We will give you some advice on how to use them properly.[2]
\begin{document}
\frontmatter
\maketitle
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
% Introductory chapters
\chapter{Preface}
% ...
\mainmatter
\chapter{First chapter}
% ...
\appendix
\chapter{First Appendix}
\backmatter
\chapter{Last note}
The frontmatter chapters will not be numbered. Page numbers will be printed in roman
numerals. Frontmatter is not supposed to have sections, so they will be numbered 0.n
because there is no chapter numbering. Check the Counters chapter for a fix.
The mainmatter chapters works as usual. The command resets the page numbering. Page
numbers will be printed in arabic numerals.
The \appendix macro can be used to indicate that following sections or chapters are to be
numbered as appendices. Appendices can be used for the article class too:
\appendix
\section{First Appendix}
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Only use the \appendix macro once for all appendices.
The backmatter behaves like the frontmatter. It has the same issue with section numbering.
As a general rule you should avoid mixing the command order. Nonetheless all commands are
optional, so you might consider using only a few.
Note that the special content like the table of contents is considered as an unnumbered chapter.
Frontmatter
1. Half-title
2. Empty
3. Title page
4. Information (copyright notice, ISBN, etc.)
5. Dedication if any, else empty
6. Table of contents
7. List of figures (can be in the backmatter too)
8. Preface chapter
Mainmatter
1. Main topic
Appendix
1. Bibliography
2. Glossary / Index
Comprehensive papers often feature special pages at the end, like indices, glossaries and
bibliographies. Since this is quite a complex topic, we will give you details in the dedicated part
Special Pages.
Bibliography [edit]
Any good research paper will have a complete list of references. LaTeX has two ways of inserting
your references into a document:
you can embed them within the document itself. It's simpler, but it can be time-consuming if you
are writing several papers about similar subjects so that you often have to cite the same books.
you can store them in an external BibTeX file and then link them via a command to your
current document and use a Bibtex style to define how they appear. This way you can create
a small database of the references you might use and simply link them, letting LaTeX work for
you.
To learn how to add a bibliography to your document, see the Bibliography Management section.
1. ↑ unnumberedtotoc
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
2. ↑ http://tex.stackexchange.com/questions/20538/what-is-the-right-order-when-using-frontmatter-
tableofcontents-mainmatter
Category: LaTeX
Text is available under the Creative Commons Attribution-ShareAlike License.; additional terms may apply. By using this site, you
agree to the Terms of Use and Privacy Policy.
Privacy policy About Wikibooks Disclaimers Developers Cookie statement Mobile view
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com