Center an image in LaTeX (centering)
Write \centering inside the figure environment, before \includegraphics. An image without a figure goes into a center environment.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{graphicx}Center an image in a figure
\centering applies up to \end{figure} and adds no vertical space.
\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\caption{The measurement setup}
\end{figure}Center an image without a figure
The center environment starts a new paragraph, centers the image and leaves space above and below it.
Text before the image.
\begin{center}
\includegraphics[width=0.5\textwidth]{image.png}
\end{center}
Text after the image.Center an image that is wider than the text
An image wider than the text block starts at the left margin and sticks out on the right, also with \centering. \makebox[\textwidth]{...} builds a box as wide as the text block and centers the image on it, so the image sticks out by the same amount on both sides.
\begin{figure}
\makebox[\textwidth]{\includegraphics[width=1.2\textwidth]{image.png}}
\caption{An image that is wider than the text block}
\end{figure}Center an image vertically on a page
\vspace*{\fill} above and below the image shares the free height of the page equally. \newpage ends the page before and after it.
\newpage
\vspace*{\fill}
\begin{center}
\includegraphics[width=0.6\textwidth]{image.png}
\end{center}
\vspace*{\fill}
\newpagePitfalls
- Inside a
figure, use\centeringand not thecenterenvironment, which adds its own space above and below to the space of the float. - A figure that LaTeX puts on a page with floats only is centered vertically on that page without any command.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- How-to Insert an image in LaTeX
- How-to Center a table in LaTeX
- How-to Center, left-align and right-align text in LaTeX
- How-to Figure placement in LaTeX
- Package
graphicx