# How do I align an image to centre?

How do I align an image to centre?

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}


It is enough to use the center enviroment:

\begin{center}
\includegraphics{yourimage}
\end{center}


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}
\end{figure}


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

Here are two ways of achieving this:

\begin{center}
\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} – Yiannis Lazarides Apr 30 '12 at 21:00
• I personally think \centerline is just perfect to center single boxes like images. @YiannisLazarides – Martin Scharrer Apr 30 '12 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. – cacamailg Dec 7 '15 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 '15 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 – Simon Baars Jun 12 '19 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 '17 at 3:50

\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... – Phelype Oleinik Jun 15 '18 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.

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 '19 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. – Niraj D Pandey Mar 28 '19 at 13:07