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}
Result
The compiled example

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.
Result
The compiled example

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}
Result
The compiled example

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}
\newpage
Result
The compiled example

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages