# Document structure

## Counters and Length parameters

• Counters :- LATEX maintains many counter variables (e.g. page, part, equation, footnote, chapter, paragraph, section, subsection, subsubsection, enumi, etc). You can set these counters yourself. Some examples:-
\setcounter{page}{0}


• Length Parameters :- LATEX accepts the following units of length: in, cm, mm, pt (there are 72.27 pts to an inch), em (width of an M), ex (height of an x). These units can be used to set the values of length variables using \setlength. For example,
\setlength{\parindent}{0in}

sets to zero the amount by which the first line of a paragraph is indented. Other useful length parameters are:-
parskip:-
determines the gap between paragraphs.
baselineskip:-
determines the usual distance from the bottom of one line to the bottom of the next. You can adjust this to produce double spacing, but a better way, which takes a stretch factor as argument is to use \linespread. For instance before \begin{document} you can do
\linespread{1.6}

to get doublespacing through your document. The setspace package offers more options.

## Document and page organisation

• Document classes: The standard classes are article, book, letter, report, slides. The differences between these are often minor. A book can have chapters. In a report sections begin at 0 whereas in an article they begin at 1. Just about all our handouts are articles.

• Big Documents :- It's best to split your document into smaller files and have a master file looking like this
 \documentclass[dvips,12pt]{book}
\usepackage{a4,color,graphics,palatino,fancyhdr}
\begin{document}
\pagestyle{empty}
\tableofcontents
\listoffigures
\pagestyle{fancy}
\input{chapter1}
\input{chapter2}
\input{fig2}
\input{chapter3}
\input{chapter4}
\appendix
\input{appendices}
\end{document}

on which you can run latex just as if the master file contained all the text of chapter1.tex etc. The advantage of this is that once you have a chapter correct, you can comment out the corresponding input' line and avoid unnecessary processing. Remember to take out the \begin{document} and \end{document} lines from the component files.

• Page Size :- You can choose the margin sizes yourself by changing the following dimensions before the \begin{document} line.
\setlength{\topmargin}{-0.4in}
\setlength{\topskip}{0.3in}    % between header and text
\setlength{\textheight}{9.5in} % height of main text
\setlength{\textwidth}{6in}    % width of text
\setlength{\oddsidemargin}{0.75in} % odd page left margin
\setlength{\evensidemargin}{0.75in} % even page left margin


Note that a margin width of 0cm gives you a margin 4cm wide. Rather than set absolute sizes you can modify the default sizes using commands like the following -

\addtolength{\evensidemargin}{-1cm}

Better support for control of page layout is provided by the geometry package. To see the current values of these dimensions, use the layout package, which defines a \layout command.

For A3 output, add \usepackage{a3} to your latex source file (foo.tex say), run latex on it, convert the resulting file to Postscript using
dvips -t a3 foo.dvi -ofoo.ps'' then print using lp -oa3 foo.ps''.

• Title Pages :- The title page of this document was created by the following LATEX commands.
\title{Advanced \LaTeX}
\author{Tim Love}
\date{\today}
\maketitle


• Contents :- Use \tableofcontents to create a contents list at that point in the document. LATEX will pick out the sections, subsections, etc for you. You'll have to run LATEX at least twice though.

• Page numbers and Headings :- These are determined by the argument given in pagestyle{}.

plain :-
the page numbers are put at the bottom of the page. The top of the page is empty. This is the default mode.

empty :-
this suppresses page numbering altogether, except on the title page it you're using \maketitle. The workaround in this case is to do
\maketitle
\thispagestyle{empty}

with no gap between the two lines.

this puts the page numbers at the top and adds a header whose contents depend on the document style.

fancyhdr is a popular package that adds useful page headers when the command \pagestyle{fancy} is used. This handout uses it.

Long section titles can cause trouble in headers. The section commands let you specify an extra, shorter title for use in the header and contents page. Section 2.3 was specified as follows

\subsection[Pagebreaks, footnotes, etc]
{Pagebreaks, space, footnotes, references, boxes, etc}


• Sectioning :- To start a chapter called Life in a book, just use \chapter{Life}. Similar commands to start a part, section or subsection also exist in most document classes (articles don't have chapters or parts though).

If you use the *-form of the command then the sections will not be numbered, neither will it appear in the table of contents.

A title will only be numbered if its 'depth' isn't more than secnumdepth and will only appear in the contents page if the 'depth' isn't more than the value of tocdepth. So, for example, doing

\setcounter{tocdepth}{2}
\setcounter{secnumdepth}{3}

will cause section 1.4.3 to be numbered, but it won't appear in the contents.

## Pagebreaks, space, footnotes, references, boxes, etc

• Page Breaks :- you can force a page break using \newpage.
• Preventing line breaks :- If there's a word that you don't want broken, put it in an mbox. E.g.,
One shouldn't try to break up \mbox\emph{relationships}


• Space :-
You can create vertical space \vspace{.5cm} between lines
or horizontal space \hspace{1.5cm} between words.
The arguments to these commands can be negative.

creates

You can create vertical space between lines or horizontal space        be-

tween words. The arguments to these commands can be negative.

\vspace* will create space even at the top of a page. It's sometimes useful to create stretchable space. The following creates space that pushes the letters to the edge of the page
\noindent A\hspace{\stretch{1}} B\\
C\hspace{\stretch{1}} D


A                                                                  B
C                                                                  D


• Footnotes :-
Do them like this\footnote{I told you so.}

Do them like this1 The footnotes are numbered by default. If you want to use symbols (stars, daggers etc) then you need to redefine how the footnote counter is displayed.
\def\thefootnote{\fnsymbol{footnote}}


• Margin notes :-
Do them like this\marginpar{margin note}

Do them like this

• Cross References :- At the end of this source file is the line \label{THE_END}.

The last page (page \pageref{THE_END}) is in section\ref{THE_END} produces something like


The last page (page 6) is in section 3


You'll have to run LATEX at least twice to pick up forward references like these.

• Boxed Text :- For short pieces of text, use \fbox
   Help. I'm \fbox{trapped}

Help. I'm

• Comments :- Anything to the right of a % character is ignored by LATEX .

• Rules :- The \rule takes 2 arguments; a width and a height, so
\rule{\textwidth}{1pt}` produces

• © Cambridge University, Engineering Department, Trumpington Street, Cambridge CB2 1PZ, UK (map)
Tel: +44 1223 332600, Fax: +44 1223 332662
Contact: helpdesk