84

I mess up with things when I try to use the figure-thing: the picture is not appearing with the correct alignment (apparently because I forget the float package). Now I want to use only the graphicx package with \includegraphics. How can I center the \includegraphics without figure?

Not working or doing centering to the document afterwards.

\includegraphics[width=0.5 \textwidth]{./Pictures/r.png}{\centering}
\includegraphics[width=0.5 \textwidth]{./Pictures/r.png}\centering
Werner
  • 603,163
hhh
  • 8,743

3 Answers3

98

Put \includegraphics into a center environment -- this also adds some space before and after your picture.

\documentclass{article}

\usepackage[demo]{graphicx}% "demo" to make example compilable without .png-file

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{center}
\includegraphics[width=0.5\textwidth]{mypicture.png}
\end{center}

\lipsum[1]

\end{document}
lockstep
  • 250,273
  • 13
    The environment center puts some extra vertical space around its contents, which is frowned upon, at least for me. Therefore I prefer the command \centering, i.e. {\centering\includegraphics[width=0.5\textwidth]{mypicture.png}}, the outer pair of braces is to make the effect of \centering be local. – yo' Mar 05 '12 at 21:51
  • 5
    @tohecz I'd say center should be frowned upon inside floats (which add own space before/after them), but is perfectly fine for pictures inserted directly in the text. – lockstep Mar 05 '12 at 21:57
  • 1
    @tohecz Your command misses a \par before the end of outer bracket. Without \par it won't work. – xji Nov 14 '14 at 08:04
  • 2
    Neither the center environment nor centering appears to work for beamerposter. =/ – Translunar Mar 31 '15 at 20:36
  • 1
    \centering can cause trouble when you specify a rotation angle in a way that defining an environment using \begin{center}...\end{center} seems to avoid - however, if \centering is causing trouble, it can help to specify as follows: {\centering \includegraphics[width=0.5\textwidth]{mypicture.png} \par} – HoneyBuddha Nov 20 '20 at 11:15
24

\includegraphics{..} looks to TeX like a big letter, center it the same way

\begin{center}
  \includegraphics{...}
\end{center}

or use \centering if you prefer.

mareoraft
  • 105
David Carlisle
  • 757,742
2

Another way to center a includegraphic is to use \centerline:

\centerline{\includegraphics{...}}

I've no always managed to get centering to work for what ever reason.

rhody
  • 1,020
  • You should be aware that \centerline is not a supported LaTeX command and that it has some subtleties. For instance, you want to use it only between blank lines. – egreg Jun 02 '23 at 09:56
  • I found it tends to work more often than \centering – rhody Jun 03 '23 at 19:47