Complete guide to LaTeX measurement units, lengths, and spacing. Learn how to use points, ems, centimeters, and other units for precise document formatting.
Understanding LaTeX lengths and units is essential for precise document formatting. This guide covers all measurement units, how to use them effectively, and practical examples for common formatting tasks.
Key concept: LaTeX uses different units for different purposes. Understanding when to use each unit type will help you create professional, consistent documents.Related topics: Single vs double-sided documents | Spacing | Headers & footers
\documentclass{article}\usepackage[margin=1in]{geometry}\begin{document}% Setting margins\newgeometry{left=2cm, right=2cm, top=3cm, bottom=3cm}% Horizontal spacingThis text\hspace{2cm}has 2cm space.% Vertical spacingThis is the first line.\vspace{1in}This line is 1 inch below.% Paragraph indentation\setlength{\parindent}{0.5in}This paragraph is indented by half an inch.% Line spacing\setlength{\baselineskip}{14pt}This text has 14pt baseline skip.\end{document}
\documentclass{article}\begin{document}% Get current valuesThe current font size is \the\fontdimen6\font pt.% Text width measurementsText width: \the\textwidthLine height: \the\baselineskipParagraph indent: \the\parindent% Using lengths in calculations\newlength{\mywidth}\setlength{\mywidth}{0.5\textwidth}This box is half text width: \fbox{\parbox{\mywidth}{Content here}}\end{document}
\documentclass{article}\usepackage{geometry}% Absolute measurements\geometry{ paperwidth=210mm, % A4 width paperheight=297mm, % A4 height left=25mm, % Left margin right=25mm, % Right margin top=30mm, % Top margin bottom=30mm % Bottom margin}% Relative to paper size\geometry{ width=0.8\paperwidth, % 80% of paper width height=0.9\paperheight % 90% of paper height}\begin{document}Current page dimensions:\begin{itemize}\item Paper width: \the\paperwidth\item Paper height: \the\paperheight\item Text width: \the\textwidth\item Text height: \the\textheight\end{itemize}\end{document}
\documentclass{article}\begin{document}% Em-based spacing (scales with font size){\normalsize Normal text with \hspace{2em} 2em space.}{\large Large text with \hspace{2em} 2em space.}{\huge Huge text with \hspace{2em} 2em space.}% Ex-based spacing (scales with x-height)Baseline text\vspace{2ex}Text with 2ex vertical space above.% Comparison of units\begin{tabular}{ll}2cm space: & Text\hspace{2cm}continues \\2em space: & Text\hspace{2em}continues \\2ex space: & Text\hspace{2ex}continues \\\end{tabular}\end{document}
\documentclass{article}\usepackage{calc}\begin{document}% Define custom lengths\newlength{\sidebarwidth}\newlength{\mainwidth}% Calculate widths\setlength{\sidebarwidth}{0.25\textwidth}\setlength{\mainwidth}{\textwidth - \sidebarwidth - 1cm}% Use in layout\noindent\begin{minipage}{\sidebarwidth}\textbf{Sidebar}\\Content here\end{minipage}%\hspace{1cm}%\begin{minipage}{\mainwidth}\textbf{Main Content}\\This is the main content area calculated to fit properly.\end{minipage}% Complex calculations\newlength{\complexwidth}\setlength{\complexwidth}{(\textwidth - 3\columnsep) / 2}Width calculation: \the\complexwidth\end{document}
\documentclass{article}\begin{document}% Fixed horizontal spacesWord\hspace{1cm}space% Flexible spacesLeft\hfill Right% Negative spaceOver\hspace{-2mm}lap% Stretchable space\hspace{1cm plus 1cm minus 0.5cm}% Fill remaining spaceText\hfill\hfill More text% Specific spacing commandsThin\,space (3/18 em)Medium\:space (4/18 em)Thick\;space (5/18 em)Quad\quad space (1 em)Double\qquad space (2 em)\end{document}
\documentclass{article}\begin{document}First paragraph.\vspace{2cm}Paragraph with 2cm space above.\vspace*{1in}Paragraph with 1 inch space that won't disappear at page breaks.% Stretchable vertical space\vspace{1cm plus 2cm minus 0.5cm}Flexible space above this paragraph.% Fill remaining pageContent at top.\vfillContent at bottom.% Negative vertical spaceLine one.\vspace{-\baselineskip}Line that overlaps above.\end{document}
\documentclass{article}% Customize default lengths\setlength{\parindent}{2em} % Paragraph indentation\setlength{\parskip}{1ex plus 0.5ex} % Space between paragraphs\setlength{\baselineskip}{14pt} % Line spacing\setlength{\columnsep}{2em} % Column separation% Custom length variables\newlength{\sectionspace}\setlength{\sectionspace}{2ex plus 1ex minus 0.5ex}\newlength{\figuremargin}\setlength{\figuremargin}{1cm}\begin{document}% Use custom lengths\section{Introduction}\vspace{\sectionspace}Normal paragraph with custom settings.% Dynamic adjustments\addtolength{\leftskip}{2em}This paragraph is indented by 2em on the left.\addtolength{\leftskip}{-2em}Back to normal margins.\end{document}
\documentclass{article}\usepackage{graphicx}\usepackage{booktabs}\begin{document}% Table with unit-based sizing\begin{table}[h]\centering\begin{tabular}{p{3cm}p{4cm}p{2cm}}\topruleFixed 3cm & Fixed 4cm & Fixed 2cm \\\midruleContent adapts & to specified & column width \\\bottomrule\end{tabular}\caption{Table with fixed column widths}\end{table}% Figure scaling with units\begin{figure}[h]\centering% Scale by absolute size\includegraphics[width=8cm]{example-image}\caption{Figure scaled to 8cm width}\end{figure}% Relative scaling\begin{figure}[h]\centering\includegraphics[width=0.8\textwidth]{example-image}\caption{Figure scaled to 80\% of text width}\end{figure}\end{document}
\documentclass{article}\usepackage{framed}% Define environment with custom spacing\newenvironment{myquote}[1][2em]{% \vspace{1ex}% \begin{quote}% \leftskip=#1% \rightskip=#1% \itshape%}{% \end{quote}% \vspace{1ex}%}\begin{document}Regular paragraph text.\begin{myquote}This is a quote with default 2em indentation.\end{myquote}\begin{myquote}[4em]This quote has 4em indentation on both sides.\end{myquote}Regular text continues.\end{document}
\documentclass{article}% Good: Font-relative spacing\setlength{\parskip}{0.5\baselineskip plus 0.2\baselineskip}% Good: Consistent unit system\geometry{margin=2.5cm, marginparwidth=2cm}% Good: Flexible spacing\newcommand{\flexspace}{\vspace{1ex plus 0.5ex minus 0.2ex}}% Avoid: Mixing systems inconsistently% \geometry{margin=1in, marginparwidth=3cm} % Don't mix% Good: Relative to context\newlength{\myindent}\setlength{\myindent}{2em} % Scales with font\begin{document}Properly spaced content with consistent units.\end{document}
\documentclass{article}\usepackage{layouts}\begin{document}% Display current settings\begin{itemize}\item Text width: \the\textwidth\item Text height: \the\textheight\item Line height: \the\baselineskip\item Paragraph indent: \the\parindent\item Paragraph skip: \the\parskip\end{itemize}% Show page layout\currentpage\pagediagram% Measure specific elements\newlength{\testlength}\settowidth{\testlength}{Sample text to measure}Width of "Sample text to measure": \the\testlength\settoheight{\testlength}{Sample text}Height of "Sample text": \the\testlength\end{document}
Use relative units (em, ex) when spacing should scale with the font (e.g., paragraph spacing, indents). Use absolute units (pt, cm) for fixed physical dimensions (e.g., margins, figure sizes).
Why does spacing look different after changing font size?
em and ex scale with the current font, so changes to font size affect spacing. For fixed spacing independent of font, use absolute units like pt or cm.
How do I measure current lengths in my document?
Use \the\length to print a value (e.g., \the\textwidth) and packages like layouts to visualize page geometry. See the Debugging section for examples.
Best way to set margins?
Use the geometry package and specify margins in cm/mm for clarity. For responsive layouts, consider percentages of \paperwidth/\paperheight.