LaTeX/Lengths
| Getting Started
Common Elements
Mechanics Technical Texts
Special Pages Special Documents Creating Graphics Programming Miscellaneous Help and Recommendations Appendices |
In TeX, a length is
- a floating point number followed by a unit, optionally followed by a stretching value;
|
3.5pt plus 1pt minus 2pt |
- a floating point factor followed by a macro that expands to a length.
|
1.7\textwidth |
Contents |
Units [edit]
First, we introduce the LaTeX measurement units. All LaTeX units are two-letter abbreviations. You can choose from a variety of units. Here are the most common ones.[1]
| Abbreviation | Definition | Value in points (pt) |
|---|---|---|
| pt | a point is 1/72.27 inch, that means about 0.0138 inch or 0.3515 mm. | 1 |
| mm | a millimeter | 2.84 |
| cm | a centimeter | 28.4 |
| in | inch | 72.27 |
| ex | roughly the height of an 'x' in the current font | undefined, depends on the font used |
| em | roughly the width of an 'M' (uppercase) in the current font | undefined, depends on the font used |
And here are some less common units.[2]
| Abbreviation | Definition | Value in points (pt) |
|---|---|---|
| bp | a big point is 1/72 inch, that means about 0.0139 inch or 0.3527 mm. | 1.00375 |
| pc | pica | 12 |
| dd | didôt (1157 didôt = 1238 points) | 1.07 |
| cc | cîcero (12 didôt) | 12.84 |
| sp | scaled point (65536sp per point) | 0.000015 |
Box lengths [edit]
A box in TeX is characterized by three lengths:
- depth
- height
- width
See Boxes.
Length manipulation [edit]
You can change the values of the variables defining the page layout with two commands. With this one you can set a new value for an existing length variable:
|
\setlength{\mylength}{length} |
with this other one, you can add a value to the existing one:
|
\addtolength{\mylength}{length} |
You can create your own length with the command, and you must create a new length before you attempt to set it:
|
\newlength{\mylength} |
You may also set a length from the size of a text with one of these commands:
|
\settowidth{\mylength}{some text} |
When using these commands, you may duplicate the text that you want to use as reference if you plan to also display it. But LaTeX also provides \savebox to avoid this duplication. You may wish to look at the example below to see how you can use these. See Boxes for more details.
You can also define stretched values. A stretching value is a length preceded by plus or minus to specify to what extent tex is authorized to change the length. Example:
|
\setlength{\parskip}{10pt plus 5pt minus 3pt} |
It means that tex will try to use a length of 10pt; if it is underfull, it will raise the length up to a maximum of 15pt; if it is overfull, it will lower the length up to a minimum of 7pt.
Note that it is not mandatory to specify both the plus and the minus values, but if you do, latxpar must be placed before minus.
To print a length, you can use the \the command:
|
\the\textwidth |
plainTeX [edit]
To create a new length:
|
\newdimen\mylength |
To set a length:
|
\mylength=1.5in |
To view, it is the same as with LaTeX, using the command \the.
LaTeX default lengths [edit]
Common length macros are:
- \baselineskip
- The normal vertical distance between lines in a paragraph.
- \baselinestretch
- Multiplies \baselineskip.
- \columnsep
- The distance between columns.
- \columnwidth
- The width of the column.
- \evensidemargin
- The margin for 'even' pages (think of a printed booklet).
- \linewidth
- The width of a line in the local environment.
- \oddsidemargin
- The margin for 'odd' pages (think of a printed booklet).
- \paperwidth
- The width of the page.
- \paperheight
- The height of the page.
- \parindent
- The normal paragraph indentation.
- \parskip
- The extra vertical space between paragraphs.
- \tabcolsep
- The default separation between columns in a tabular environment.
- \textheight
- The height of text on the page.
- \textwidth
- The width of the text on the page.
- \topmargin
- The size of the top margin.
- \unitlength
- Units of length in picture environment.
Fixed-length spaces [edit]
To insert a fixed-length space, use:
|
\hspace{length} |
\hspace stands for horizontal space, \vspace for vertical space.
If such a space should be kept even if it falls at the end or the start of a line, use \hspace* instead.
If the space should be preserved at the top or at the bottom of a page, use the starred version of the command, \vspace*, instead of \vspace. If you want to add space at the beginning of the document, without anything else written before, then you may use
|
{ \vspace*{length} } |
It's important you use the \vspace* command instead of \vspace, otherwise LaTeX can silently ignore the extra space.
TeX features some macros for fixed-length spacing.
- \smallskip
- Inserts a small space in vertical mode (between two paragraphs).
- \medskip
- Inserts a medium space in vertical mode (between two paragraphs).
- \bigskip
- Inserts a big space in vertical mode (between two paragraphs).
The vertical mode is during the process of assembling boxes "vertically", like paragraphs to build a page. The horizontal mode is during the process of assembling boxes "horizontally", like letters to build a word or words to build a paragraph.
The fact they are vertical mode commands mean they will be ignored (or fail) in horizontal mode such as in the middle of a paragraph. The first token next the a double linebreak is still in vertical mode if it does not expand to characters.
|
% WRONG! |
|
|
This is a common error! Anyway, these commands should never be used in regular documents. |
Rubber/Stretching lengths [edit]
The command:
|
\stretch{factor} |
generates a special rubber space where factor is a number, possibly a float. It stretches until all the remaining space on a line is filled up. If two \hspace{\stretch{factor}} commands are issued on the same line, they grow according to the stretch factor.
|
x \hspace{ \stretch{1} } x \hspace{ \stretch{3} } x |
x x x |
The same way, you can stretch vertically:
|
\maketitle |
You can also use \fill instead of \stretch{1}.
The \stretch command, in connection with \pagebreak, can be used to typeset text on the last line of a page, or to center text vertically on a page.
There are 'shortcut commands' for stretching with factor 1 (i.e. with \stretch{1} or \fill): \hfill and \vfill.
Example:
|
\maketitle |
Fill the rest of the line [edit]
Several macros allow filling the rest of the line -- or stretching parts of the line -- in different manners.
- \hfill will produce spaces.
- \dotfill will produce dots.
- \hrulefill will produce a rule.
Examples [edit]
Resize an image to take exactly half the text width :
|
\includegraphics[width=0.5\textwidth]{mygraphic} |
Make distance between items larger (inside an itemize environment) :
|
\addtolength{\itemsep}{0.5\baselineskip} |
Use of \savebox to resize an image to the height of the text:
|
% Create the holders we will need for our work |
References [edit]
- ↑ http://www.uz.ac.zw/science/maths/latex/ltx-86.html
- ↑ http://www.uz.ac.zw/science/maths/latex/ltx-86.html
See also [edit]
- University of Cambridge > Engineering Department > computing help > LaTeX > Squeezing Space in LaTeX