# Cannot center pdf image [duplicate]

This question already has an answer here:

I'm using sharelatex and pdflatex as a compiler. I am using the memoir class. (It's for a book.)

At first I used .png images but the compiler always took too long so I converted all my image files to .pdf in order to gain a smaller file size=faster compilation speed and I realized that vector images' quality are better than raster so I want to keep working with vector formats (and I didn't use .svg or .eps because sharelatex doesn't support them).

The image has to fit the page's width margins (for the vector image) or if it does ever exceed, it can be floated(but still centered; and again, I used this trick for png images but they were too big and never loaded properly).

I've tried many solutions, but none of them managed to work. They used to work when the extension was still .png. But once I've switched to pdf they're all broken. (or worked differently so I didn't got my results).

I'm going to add the document's frames so it'll be easier to get an idea of how much the image is off-bounds to the center.

\documentclass[14pt]{memoir}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\graphicspath{ {images/} }

\usepackage[paperwidth=6in, paperheight=9in, margin=0.9in, showframe]{geometry}

\begin{document}

\begin{center}
\includegraphics[scale = 1]{001}
\end{center}

\end{document}


Which got me this:

\documentclass[14pt]{memoir}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\graphicspath{ {images/} }

\usepackage[paperwidth=6in, paperheight=9in, margin=0.9in, showframe]{geometry}

\begin{document}

\begin{center}
\includegraphics[scale = 1]{001_pngversion}
\end{center}

\end{document}


Result:

Which gives me the high resolution png version. Somehow, it looks like more aligned to the left...? Maybe it was because it's too big, it exceeded the page limits and couldn't center properly?

I then decided to use the \centering trick and the \linewidth trick to resize it:

\documentclass[14pt]{memoir}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\graphicspath{ {images/} }

\usepackage[paperwidth=6in, paperheight=9in, margin=0.9in, showframe]{geometry}

\begin{document}

\begin{center}
\includegraphics[width=1\linewidth]{001}
\end{center}

\end{document}


Which got me this, the exact result I was looking for:

Now, let's try the same trick with pdf images:

\documentclass[14pt]{memoir}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\graphicspath{ {images/} }

\usepackage[paperwidth=6in, paperheight=9in, margin=0.9in, showframe]{geometry}

\begin{document}

\begin{figure}
\centering
\includegraphics[width=1\linewidth]{001}
\end{figure}

\end{document}


Results:

Which obtained the same exact result as the FIRST ONE (failed one)

I then tried \begin{figure} \begin{floatrow} or \centerfloat , etc but it still failed. Only worked for pngs...

What I want to achieve is the result I got from the png version, while using .pdf images.

(On a side note, could someone explain the difference in using /centering, /centerline, and /centerfloat? While I was looking for answers concerning centering floating images that surpassed the page's margins. Which one is usually recommended?)

## marked as duplicate by Martin Schröder, user13907, Svend Tveskæg, Werner horizontal-alignment StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jan 13 '16 at 17:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• Centering is accomplished by adding equal amounts of glue (usually 1\fil) to the left and right of the thing to be centered. It really doesn't matter which you use (except possibly in beamer). Setting the width to \linewidth (or \textwidth) should fill the whole space and centering has nothing to fill. – John Kormylo Jan 11 '16 at 22:59
• \centerline should generally be avoided unless you know why you need it. \centering is generally appropriate in floats (figure, table...) because it doesn't add additional vertical space to that already added by those environments. Where you do want some space, \begin{center}...\end{center} is appropriate. I have no idea about \centerfloat. I've never heard of it before and certainly never used it. – cfr Jan 11 '16 at 23:11
• @JohnKormylo That is not true. It absolutely matters which you use because they behave in different ways e.g. in terms of vertical space added etc. I know the OP didn't ask about the center environment, but certainly \centerline and \centering behave differently. (Maybe not in this case but I took that question to be a general one.) – cfr Jan 11 '16 at 23:13
• Welcome! (By the way.) Could you check the code examples in your question? They don't always seem to correspond to the description e.g. you say you're using \centering and \linewidth but then don't seem to do so. Also, could you say how you converted the PNGs to PDF? – cfr Jan 11 '16 at 23:15
• Try putting \fbox{} around the images e.g. \fbox{\includegraphics[<options>]{<filename>}}. This won't help but it often helps diagnose problems because you can see where the boundaries of the images are e.g. if there's a lot of white space on one side of the image or something like that. – cfr Jan 12 '16 at 0:37