84

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}
1

9 Answers 9

90

It is enough to use the center enviroment:

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

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>}

0
29

You could also do something like this:

\begin{figure}[!h]
    \caption{My caption}
    \centering
    \includegraphics[width=50mm]{theImage}
    \label{fig:label}
\end{figure}
2
  • Just a note here: \centering should come before \includegraphics Commented Jun 12, 2019 at 12:10
  • @Freefri This worked for me. \begin-\end{center} did not work. Commented Dec 28, 2022 at 20:01
23

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.

4
  • 11
    Third way \centerline{\includegraphics...}, perhaps you want to add it. Fourth way {\centering \includegraphics...\par}
    – yannisl
    Commented Apr 30, 2012 at 21:00
  • 3
    I personally think \centerline is just perfect to center single boxes like images. @YiannisLazarides Commented 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.
    – cacamailg
    Commented Dec 7, 2015 at 10:30
  • 2
    @cacamailg: For what it's worth, they are equivalent, as you'll find \let\bgroup={ \let\egroup=} in the LaTeX kernel.
    – Werner
    Commented Dec 7, 2015 at 17:18
19

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.

2
  • how about to the left and top?
    – Vass
    Commented 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].
    – MERose
    Commented Jun 17, 2021 at 12:58
1

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

1
  • 3
    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... Commented Jun 15, 2018 at 11:39
1

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.

2
  • Welcome to TeX.SE! I think \centering should go before \includegraphics.
    – user156344
    Commented 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. Commented Mar 28, 2019 at 13:07
0

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.

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

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)

2
  • 1
    Example given doesn't work as written. A node must have a label text. When looking to adapt a solution to one's own problem, we shouldn't be stuck just trying to debug the solution. Commented Jan 24, 2023 at 2:42
  • No, a node does not need label text, it can be empty, so long as the curly brackets are there. I guess I should have added something other than \includegraphics{} in the node. The example runs just fine, though you are right, I should have added both the package (tikz) and something to indicate the \includegraphics command needs to reference an image. Add tikz in the preamble and a path to the \includegraphics{} command and there is no issue.
    – The V
    Commented Feb 9, 2023 at 7:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .