# How do I align an image to center?

How do I align an image to center?

In a beamer presentation I have a 2-3 items on a slide followed by an image. The image is not wide enough to cover whole slide, so it leaves around 30% space from right. How do I adjust it to leave enough space on both sides?

\begin{frame}
\frametitle{Outlook}
\begin{itemize}
\item apps
\item apps
\item apps
\includegraphics[scale=0.3]{P2P}
\end{itemize}
\end{frame}

## 9 Answers

It is enough to use the center enviroment:

\begin{center}
\includegraphics{yourimage}
\end{center}
• In general you should use center only with text. It adds vertical space before and after the content, which is not really what you want most the time for images, especially not for floats. See Should I use center or centering for figures? and When should we use \begin{center} instead of \centering?. Apr 30, 2012 at 22:41
• @MartinScharrer thanks for the clarification :) May 30, 2014 at 12:33
• Another issue: if your margins are asymmetrical, the image will be centered with a text block which may or may not be there, not the page itself. Sep 30, 2014 at 0:44

The third way is to use the figure environment, which is the best way in my opinion, since it provides the right mark-up. (beamer centers the figures by default.)

\begin{figure}
\includegraphics{<your image>}
\end{figure}

In this case on may also add a caption with \caption{<text>}

Here are two ways of achieving this:

\begin{center}
\includegraphics{<your image>}
\end{center}

or

\hfill\includegraphics{<your image>}\hspace*{\fill}

The former may add some vertical whitespace, while the latter centers its contents on the line used.

• Third way \centerline{\includegraphics...}, perhaps you want to add it. Fourth way {\centering \includegraphics...\par} Apr 30, 2012 at 21:00
• I personally think \centerline is just perfect to center single boxes like images. @YiannisLazarides Apr 30, 2012 at 22:42
• I tend to prefer the opening-closing environments. So, I do not like much to use {\centering ...} but prefer \bgroup \centering ... \egroup. Dec 7, 2015 at 10:30
• @cacamailg: For what it's worth, they are equivalent, as you'll find \let\bgroup={ \let\egroup=} in the LaTeX kernel.
– Werner
Dec 7, 2015 at 17:18

You could also do something like this:

\begin{figure}[!h]
\caption{My caption}
\centering
\includegraphics[width=50mm]{theImage}
\label{fig:label}
\end{figure}
• Just a note here: \centering should come before \includegraphics Jun 12, 2019 at 12:10

One simple way to center an image is to use the adjustbox package with the export option. It provides the center=<width> key to \includegraphics, which centers the image around the given width. It defaults to the \linewidth, so use:

\usepackage[export]{adjustbox}
% ....

\includegraphics[scale=0.3,center]{P2P}

Inside a itemize this will center the image relative to the itemize text width, not to the frame.

• how about to the left and top?
– Vass
Feb 11, 2017 at 3:50
• Strangely, I get different results when I put write [center,scale=0.3] instead of [scale=0.3,center]. Jun 17, 2021 at 12:58

\centering\includegraphics{...} — when the figure is smaller than the text width \centerline{\includegraphics{...}} — when the figure is wider than the text width

• Welcome to TeX.SX! Using just \centering\includegraphics{...} would make the rest of the document from this point on centered if you don't take care of the grouping. Maybe you should add something explaining this too. And I think that nowadays there are better alternatives than \centerline... Jun 15, 2018 at 11:39

You can also use tikz.

\begin{tikzpicture}[remember picture,overlay]
\node at (current page.center) node[anchor=center]{\includegraphics{}};
\end{tikzpicture}

will place your image on the center of the page. This does not account for any header, however. If you have a header that is 1 cm tall you can move the picture to compensate thus:

\begin{tikzpicture}[remember picture,overlay]
\node at ($(current page.center) +(0,-1cm)$) node[anchor=center]{\includegraphics{}};
\end{tikzpicture}

You can also anchor the node to any corner of side of the page, thus achieving absolute positioning with complete control rather effectively.

(I realize this question is old, but the solution is versatile and offers excellent positioning control)

I always use:

\begin{center}
\includegraphics[width=\textwidth]{image}
\end{center}

That's almost perfect for raw screenshots, as images will not overflow the visible content.

• Same answer as those from Tobi (Apr 30 '12 at 20:58) and gcedo (Apr 30 '12 at 20:52). Jun 17, 2021 at 13:02

This helps me

\begin{figure}[!h]
\includegraphics[width= 365pt]{./figures/xyz.png}
\centering
\caption{The picture shows xyz architecture}
\label{fig:xyz}
\end{figure}

You can of course change the width and other things as per your case. The only major part is \centering which helps here.

• Welcome to TeX.SE! I think \centering should go before \includegraphics.
– user156344
Mar 27, 2019 at 4:53
• Thanks for the welcome note. I am not sure, if this has any impact. However, in my case it works perfectly fine. Mar 28, 2019 at 13:07