To Center Or Not To Center: Best Practices For Figures And Tables In Latex
The Problem of Alignment
Aligning figures and tables is a common challenge when typesetting documents in LaTeX. Unlike text, these elements can span the entire page width and need to be consciously positioned. Improper alignment can disrupt the reading flow and appear unprofessional.
LaTeX provides environments like figure
and table
to contain these elements, but they are aligned left by default. Manual adjustment is required to center them on the page or get the desired vertical position.
Several techniques exist for centering, including:
- The
center
environment to center an element horizontally - Commands like
\hspace
to fine-tune horizontal spacing - Options like
[t]
and[b]
to influence vertical positioning - The
\vspace
command for vertical spacing adjustments
However, no single method works for every scenario. The optimum approach depends on elements like caption usage, column layouts, and page dimensions.
This article offers best practices for intelligently centering figures, tables, and related elements in complex LaTeX documents.
Methods for Horizontal Centering
Using the center Environment
The center
environment is the primary LaTeX method for horizontally centering figures, tables, and other content on the page.
Any content inside \begin{center}
and \end{center}
gets centered between the current margins. This works well for single figures, tables, math expressions, algorithms, code snippets, and similar content that should appear centered rather than left or right aligned.
For example:
\begin{center}
\includegraphics{diagram.pdf}
\end{center}
Here, the \includegraphics
command to display an image is wrapped inside center
. So the final rendered diagram gets horizontally centered.
The same applies for tables:
\begin{center}
\begin{tabular}{ |c|c| }
\hline
Cell 1 & Cell 2 \\
\hline
\end{tabular}
\end{center}
This ensures the tabular content inside is centered as well. Centered positioning persists until \end{center}
.
Adjusting Horizontal Spacing with \hspace
When finer control over horizontal spacing is needed, the \hspace
command can help. It lets you insert custom space that moves an element's position left or right.
Syntax options like:
\hspace{2cm}
Will add 2cm of horizontal space, effectively pushing the next element over. Negative values like \hspace{-2cm}
adjust positioning the other way.
For example, to get a figure perfectly centered on a custom page layout, calculate the required offset manually between margins. Then apply \hspace
spacing before or within the figure
environment.
This kind of micro-level spacing tune is useful to position oddly sized figures or elements spanning multiple text columns.
Methods for Vertical Centering
Positioning with [t] and [b]
Latex floats like figure
and table
offer placement specifiers for vertical adjustability.
Options like:
[t]
Position the element at the top of the page. Similarly,
[b]
Moves it to the bottom. This provides high-level control over vertical placement within the current page margin boundaries.
For example:
\begin{table}[b]
\centering
\begin{tabular}{...}
...tabulated data...
\end{tabular}
\end{table}
Puts the entire table
environment at the bottom of the page. Figures behave similarly as needed.
Adjusting Vertical Spacing with \vspace
The \vspace
command adds precise spacing along the vertical axis. This fine tunes position for a figure, table, or any other page element.
Basic options like:
\vspace{1cm}
Inserts 1cm of vertical space above the elements current position, moving it down. Negative values like
\vspace{-1cm}
Shifts elements up instead. When utilized within floats or custom page geometry, precise vertical readjustments are possible.
For example:
\begin{table}[h]
\centering
\vspace{-3mm}
\begin{tabular}{...}
...
\end{tabular}
\end{table}
Nudges the table up by 3mm to fine tune its ultimate vertical position.
Best Practices
Consistency Within Documents
Aim for consistency in alignment styles for all figures, tables, diagrams and similar additive visuals. Center floating elements the same way throughout a LaTeX work for cohesive appearance.
For example, make all table captions left-aligned while figures are captioned centered. Or universally apply top-[t] and bottom-[b] positioning to floats rather than a random mix.
This consistency in alignment approach prevents readers from being distracted by irregular or disjointed document styles from one section to the next.
Considering Page Layout
How figures, tables, and other page elements are centered inevitably depends on the document's margins, columns, and usable page space.
For example, in two-column layouts, content width is limited. So utilize width-spanning [h] environments for more horizontally room. Rely more on precise vertical tuning with [t]
, [b]
and \vspace
for granular adjustments.
On pages with a single wide text block, center
provides excellent horizontal centering. But watch out for orphaned elements stranded by themselves at the very bottom or top with too much vertical space.
So consider page geometry demands when tuning alignment of floats and visuals for centering needs in a given paper, report, book or article.
Accommodating Wide Elements
Occasionally, an element can be too wide for the normal text area, like an oversized diagram or ultrawide table.
In these cases, allow the content to spill out of the center and width-span margins by deliberately breaking alignment. Essentially extending a special element outside the margins to give it required horizontal space.
Just be sure to reset default alignment for subsequent blocks by closing such custom groups.
This way, a necessarily wide element gets proper showcase without affecting central alignment of other figures/tables in the document.
Example Codes
Basic Usage of center
The following demonstration centers a math expression horizontally:
\begin{center}
$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$
\end{center}
Output would showcase the quadratic formula equation authentically centered on the resulting page when compiled.
Centering a Table with Caption
To center an entire table + caption unit, wrap the table
environment in center
:
\begin{center}
\begin{table}
\centering
\caption{An Example Table}
\begin{tabular}{ c c c }
\hline
& Column 1 & Column 2 \\
\hline
Row 1 & values & data \\
Row 2 & values & data \\
\hline
\end{tabular}
\end{table}
\end{center}
This keeps both tabular data and caption text centered as one unit.
Fine-tuning Position of Figures
For precise vertical positioning of a figure, set a default top/bottom location, then microadjust:
\begin{figure}[b]
\centering
\vspace{-5mm}
\includegraphics[width=0.9\linewidth]{figure.png}
\caption{Shifted figure}
\label{fig:shifted}
\end{figure}
First position at bottom with [b]. Then apply negative \vspace to nudge the entire figure 5mm up from there. This combines macro and micro adjustments.