LaTeX/Useful Measurement Macros
From Wikibooks, the open-content textbooks collection
A list of macros and their values
Contents |
[edit] Units
First, we introduce the LaTeX measurement units. You can choose from a variety of units.
| pt | a point is 1/72.27 inch, that means about 0.0138 inch or 0.3515 mm. |
| bp | a big point is 1/72 inch, that means about 0.0139 inch or 0.3527 mm. |
| mm | a millimeter |
| cm | a centimeter |
| in | inch |
| ex | roughly the height of an 'x' in the current font |
| em | roughly the width of an 'M' (note the uppercase) of the current font |
[edit] Length 'macros'
Some length commands 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
[edit] Length manipulation macros
You can change the values of the variables defining the page layout with two commands. With this one you can set a new value:
\setlength{parameter}{length}
with this other one, you can add a value to the existing one:
\addtolength{parameter}{length}
You can create your own length with the command:
\newlength{parameter}
You may also set a length from the size of a text with one of these commands:
\settowidth{parameter}{some text} \settoheight{parameter}{some text}
When using these commands, you may to duplicate the text that you want to use as reference if you plan to also display it. But LaTeX also provides a set of commands to avoid this duplication:
\newsavebox{boxname} \savebox{boxname}{some text} \usebox{boxname}
You may wish to look at the example below to see how you can use these. The command \newsavebox creates a placeholder for storing a text; the command \savebox stores the specified text in this placeholder, and does not display anything in the document; and \usebox recalls the content of the placeholder into the document.
See LaTeX/Page_Layout for samples using these.
[edit] Samples
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 \newlength{\mytitleheight} \newsavebox{\mytitletext} % Create the reference text for measures \savebox{\mytitletext}{% \Large\bfseries This is our title% } \settoheight{\mytitleheight}{\usebox{\mytitletext}} % Now creates the actual object in our document \framebox[\textwidth][l]{% \includegraphics[height=\mytitleheight]{my_image}% \hspace{2mm}% \usebox{\mytitletext}% }