[Tex/LaTex] Why is the picture not centered in the frame

beamerfloatsgraphicshorizontal alignment

Using the following code:

\documentclass[12pt]{beamer}
\usepackage{ctex}
\usepackage{graphicx}
\begin{document}
\begin{frame}{PSA分析级别和实施程序}
\begin{figure}[htbp]
\centering
\includegraphics[scale=0.4]{tikz.pdf}
\end{figure}
\end{frame}
\end{document}

The tikz.pdf is here.

I obtain this as output:

Image of a diagram in chinese which has different border widths on the left and the right

As you can see the image is not centered, the left margin being significantly bigger than the right one. Why does this happen and how do I properly center it?

Best Answer

Because even after scaling it, the image's width is bigger than \textwidth so it protrudes to the right. With your example code you get a warning about this:

Overfull \hbox (11.64403pt too wide) in paragraph at lines 10--10

Instead of scale, control the width using:

\includegraphics[width=\textwidth]{tikz.pdf}

or a fraction of \textwidth:

\includegraphics[width=0.75\textwidth]{tikz.pdf}

A complete example:

\documentclass[12pt]{beamer}
\usepackage{ctex}
\usepackage{graphicx}
\begin{document}
\begin{frame}{PSA分析级别和实施程序}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{tikz.pdf}
\end{figure}
\end{frame}
\end{document}

The result:

enter image description here

With beamer there's no need to use placement specifiers (such as htbp) since floating is internally suppressed.

If you are not going to use \caption for your image, you can get rid of the figure environment.

Related Question