3

I know that my question may be a duplicate, but I couldn't find a solution that worked for me elsewhere on the site.

Here is the MWE :

\documentclass[12pt]{article}
\usepackage{graphicx}
\begin{document}
This is my attempt to import the image into latex.
I do not know how so I decided to try all possible cases. 
\begin{center}
\begin{figure}
\includegraphics[scale=0.7]{12.pdf}
\end{figure}
\end{center}
\end{document}

You can get my 12.pdf file there: 12.pdf.

After compiling, I get a PDF file with a page that contains my text, and another contains the image in 12.pdf. The problem is that I want to insert the image right after the words, but there seems to be lot of white space (in the image).

So, how can I get rid of that white space? I'm not a professional TeX user, so the simpler the solution, the better.

trequartista
  • 1,891
  • 3
    Very likely, you can mitigate the effect by cropping correctly the picture (use tools like pdfcrop, GIMP or whatever), even if I would draw my self the two triangles. TikZ, PSTricks are candidates for drawing. – Claudio Fiandrino Feb 13 '14 at 09:16
  • 3
    Side note: Instead of \begin{center} \begin{figure} \includegraphics[scale=0.7]{12.pdf} \end{figure} \end{center}, write \begin{figure} \centering \includegraphics[scale=0.7]{12.pdf} \end{figure}. – jub0bs Feb 13 '14 at 09:16
  • As Claudio has pointed out, this is only related to your image. The image itself takes up a hole page, including all the blank space. Crop it correctly and then latex will position it correctly automatically. – Vlad030691 Feb 13 '14 at 09:17
  • The problem is: How can I crop? This is only a simple example, there are the others images that is more complicated so I do not use TikZ or PSTricks. I also do not know how to use GIMP, pdfcrop. And as I said above, I am not a professional user, so please explain for me in the most precise way. Best, Nguyễn Duy Khánh – trequartista Feb 13 '14 at 09:21
  • 1
    I think this is what you want. link. You have to tell us what system you are using like mac or pc. I did most of these pdf figures for my advisor. – Aung Feb 13 '14 at 09:25
  • @Aung : I use Window 8 – trequartista Feb 13 '14 at 09:25
  • But how can I crop by pdfcrop? Is there any command that can used for the whole latex file? I really do not want to use GIMP, which is too complicated for me. – trequartista Feb 13 '14 at 09:28
  • 1
    I usually use texshop to crop but it is only for mac. Do you have Adobe Acrobat or Inkscape ? – Aung Feb 13 '14 at 09:46
  • Is there any other ways? Like a latex code that can help me to crop? I have heard about the pdfcrop package. – trequartista Feb 13 '14 at 09:49
  • @Nguyễn Duy Khánh: In case you work on a windows system, here is solution: copy these lines in a .batch file (call it e.g. mycrop.bat, or whatever you want, but not pdfcrop.bat): @echo off echo "Cropping pdf files ..." for %%i in (./*.pdf) do pdfcrop %%i %%~ni-cropped.pdf --verbose echo. echo Done pause – Bernard Feb 15 '14 at 00:23
  • @Nguyễn Duy Khánh: Didn't have the time to finish writing. Here is the end: You put the .bat in a directory containing your pdf's and it will crop all of them, adding -croppedat the end of its name. – Bernard Feb 15 '14 at 00:31

1 Answers1

4

With respect to the problem, first consider that the figure environment is a float, that mean that it can stay here, or float freely to the top, to the bottom, or jump to the next page or the last page, according to complex rules. See What are penalties and which ones are defined? and How to influence the position of float environments like figure and table in LaTeX?

Moreover, a float can add some vertical space around it. See Space after float with [h]

But the float width is always the width of the text, so center it is completely useless. As Jubobs point, what you really want is center the contents of the float, but center add vertical space also, so it is better \centering.

Another problem could be the \includegraphic option. Play only with the text and this command in your MWE, to isolate the problem.

Note that you fix a size relative of the original file size (that is, the 70% of who know ...) so if the image can be fitted or not depend of the original file.

To avoid this, usually it is a better idea fix an absolute width or height size (as [height=10cm]) that you know that is smaller than the page, but much better approach is to fix sizes relatives to the text size area. For example, with [height=.5\textheight] so your image will be the half of the text, no matter if you are using an A4 or an A5 paper, or how wider are your margins. You can fix both width or height and maintain the aspect ratio in this way:

\includegraphics[width=\textwidth,height=.95\textheight,keepaspectratio]
{example-image-10x16} % require the mwe package

MWE0

What now? The image can be fitted in the page, filling the remaining space. But note that is too close to the text. To take care of this, you can include this image in a float (or for another reason, as include a caption), but obviously reducing .95\textheight value as needed, if you want avoid a float jump:

\documentclass{article}
\usepackage{graphicx}
\begin{document}

This is my attempt to import the image into latex.
I do not know how so I decided to try all possible cases. 

\begin{figure}[h]
\centering 
\includegraphics[width=\textwidth,height=.75\textheight,keepaspectratio]{example-image-10x16}
\end{figure}

\end{document}

MWE

Finally, if the problem is not a proper scaling, but a bad image that contain empty areas, you can crop the image with Gimp or another tool, as suggested in the comments, but also maintain the original image and show only some area. For example:

\includegraphics[width=\textwidth,height=.75\textheight,
keepaspectratio,bb=0bp 0bp 200bp 300bp,clip]{example-image-10x16}

MWE2

Note: For a MWE with example images, use the option demo in graphicx package or install the mwe package to use some standard images as example-image-a, so others can deal with your code without downloading any image (May be you will need include \usepackage{mwe} in the preamble to use the example images, but at least in Linux with TeXLive 2013 is not needed.)

Fran
  • 80,769