4

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: undesirable result

\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: enter image description here

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: enter image description here

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: enter image description here

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?)

Xyd
  • 407
  • 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
  • 1
    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
  • @cfr (Yeah I'm new haha, thanks) I used Inkscape to convert the PNGs to PDF. Well, I tried every codes I've mentioned ( \begin{center}, \centering, \centerline, and they all worked with PNGs(I converted them manually, one by one), and using \floatrow or \centerfloat (since I'm using memoir)). My goal is to either center them if they don't surpass the margins, OR scaling the image to the margins by using \linewidth. Like I said in my initial post, every tricks worked with pngs but after I've converted them to PDFs, none of it worked. And uhhh yeah I got a little mistake I'll fix it in the OP! – Xyd Jan 12 '16 at 00:26
  • 2
    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 00:37
  • @cfr OK thank you, I'll try it and will report later! But as for right now it means that there's no solution found?... Should I switch to another type of file extension? – Xyd Jan 12 '16 at 00:39
  • @cfr My god this is what I obtained while using the code \fbox{\includegraphics[width=1.0\textwidth]{001}} : http://i.imgur.com/VKxixuo.png; This is the Original PDF file viewed in Acrobat: http://i.imgur.com/fxBo7Cg.png . Something is wrong here... Even the PNG isn't safe(the rendered png file's resolution is correct though): http://i.imgur.com/B7nA1Nh.png ...Why are they not centered? EDIT: OK I think that it might be an indent but even so aren't indent not supposed to affect /linewidth? Or are they negated by centering...? I'll try it again with /centering this time... – Xyd Jan 12 '16 at 00:47
  • Can you post the PDF somewhere so we can take a look? That is, the PDF of the image 001.pdf. And maybe 001.png, too. – cfr Jan 12 '16 at 00:51
  • \centering will kill regular indentation, but just setting the size of the graphic won't. \noindent\fbox{\includegraphics[]{}} is another option. Note that, if you aren't using figure or something, you need a paragraph break (blank line) after including the image if you use \centering. That is, don't have \end{document} on the next line. Leave a line blank first. – cfr Jan 12 '16 at 00:54
  • With the PNG, it is definitely the indentation. – cfr Jan 12 '16 at 00:55
  • @cfr Oh yeah the new solution worked perfectly for... the PNG version!(It's aligned perfectly, yup)... But the PDF still has that problem: http://i.imgur.com/kkELUNX.png . Anyhow, I've uploaded the pdf to GDrive: https://drive.google.com/file/d/0B9wgTC1ahjTjMEx4WXlmUmJia00/view?usp=sharing – Xyd Jan 12 '16 at 00:58
  • I can't reproduce the output you're reporting. I downloaded the PDF and compiled it and got this result which seems fine. Code: `\documentclass[14pt]{memoir} \usepackage[utf8]{inputenc} \usepackage{graphicx} \usepackage[paperwidth=6in, paperheight=9in, margin=0.9in, showframe]{geometry}

    \begin{document} \begin{figure} \centering \includegraphics[width=1\linewidth]{001} \end{figure} \end{document}. (I didn't set a different path for graphics as I don't have animages` sub-directory.)

    – cfr Jan 12 '16 at 03:03
  • I notice that in your image, you are on page 3. That suggests that you are not posting output produced by the code you are posting, which creates only a single page. Please double-check what happens when you compile a document with just that content and nothing else. – cfr Jan 12 '16 at 03:05
  • @cfr Sorry for the inconvenience I caused. The document was originally made in one shot and stitched all 4 pages together but seeing examples made here I always thought that it was customary to put a \begin{document} and an \end{document} if you were to put something in between(like comments and images). So I decided to separate them. (Here's the original code: http://i.imgur.com/EPh93Ob.png ) I also figured out the problem, the bad result was mainly caused by sharelatex not rendering the preview properly. After I've decided to download it, it turned like this: http://i.imgur.com/e6rs6yp.png . – Xyd Jan 12 '16 at 15:08
  • By the way do you know a solution if I want to get a pdf preview render quickly and reliably? I only used sharelatex because I'm new and it didn't seem like a hassle to set up and I liked how it showed my mistakes. I've tried installing other desktop PC clients but I was totally at lost at what I was doing. (I need to get a preview each time when I finish a new code to verify because I always make a lot of mistakes and things don't get compiled properly.) – Xyd Jan 12 '16 at 15:12
  • There's a big list question on editors which might be helpful. I just compile when I want, so I haven't looked into automating it, but some editors offer that facility. And, of course, it depends on your OS what is available, as well. – cfr Jan 12 '16 at 16:49

0 Answers0