5

In my document there are large blank spaces above and below the images that I inserted, also sometimes I can see blank spaces after the texts too. How can I remove the blank spaces above and below the images. The code I used to insert images is

\usepackage{float} This is in Main.tex file The code to insert images is in another tex file of the same project.

 \begin{figure}[H]
\centering
\includegraphics[scale=0.85]{figurename}
\caption{caption of figure}
\label{fig:img1}
\end{figure}
gman
  • 1,807
  • If you force positioning with [H], the figure will drop onto the next page if it doesn't fit on the current page, creating a large space. Try deleting the [H] option: do the spaces go away? – Ian Thompson May 28 '15 at 11:57
  • If I delete [H], then the image will display on the top of the page . But I need the image in a specific position , i.e after some paragraphs . – botguide May 28 '15 at 12:27
  • But do the spaces go away if you remove it? – Ian Thompson May 28 '15 at 12:39

2 Answers2

5

I understand you need images right where you want them. I also had same condition once. But, then, you have to understand that you always are left with some uncontrollable blank spaces due to forced formatting with 'float' package.

However, I can tell you how to get your sections and texts get stuck to each other without unnecessary whitespaces. You need to add something like this:

\usepackage[compact]{titlesec}         % you need this package
\titlespacing{\section}{0pt}{0pt}{0pt} % this reduces space between (sub)sections to 0pt, for example
\AtBeginDocument{%                     % this will reduce spaces between parts (above and below) of texts within a (sub)section to 0pt, for example - like between an 'eqnarray' and text
  \setlength\abovedisplayskip{0pt}
  \setlength\belowdisplayskip{0pt}}

These will let you reduce spaces in the overall text. For the images, I am not entirely sure how them to stick with text the way you can do with text. Still, try this (along with the float package):

\usepackage[rawfloats=true]{floatrow} 
\restylefloat{figure}     % this, I think, will reduce spaces between images and text.

The text part should work. But, I am not entirely sure about the images, sorry.

Also, if you specifically want to reduce space between two texts/images, you can also try writing (as the last resort)

\vspace{-3mm}

This will reduce vertical space by 3mm. Choose any size. But, again, there will be spaces that will not be reduced by any of these simply because of the formatting constraints, like for example, if you have some widetext in a revtex4 file, you will get some unwanted spaces due to that, as fitting the widetext is a mess, sometimes.

I hope this helps!

RS06
  • 321
  • I tried the above commands , both for text and images as you have given in the main.tex file. I can see some improvements in some images , but still some images and texts still have problems associated and can see more blank spaces. But i have a doubt , the \vspace{-3mm} , this code where should i type ? – botguide May 29 '15 at 12:38
  • You should type it right between the texts/images (where they are written in the code) where the space is undesirably high. Choose the height as per your need. Like I said, the images are a bit trickier than text. I hope text gaps are okay now. – RS06 May 30 '15 at 12:55
  • I tried to use the command \vspace{-3mm} to reduce the space between texts since i can see spaces between a subsection and its above and below paragraphs. But it is not working fine. – botguide Jun 03 '15 at 09:46
  • This anwers are useful even though it cannot solve all the issues . I believe I had some issues since there is one image in the specific position that cannot be moved to previous page because of the size . – botguide Jun 03 '15 at 10:03
3

Make it not float. Here I use a {\centering...\par} delimited image to achieve a centered image, with a small space above and below the image (added with \vspace, which can be removed as needed).

I need the caption package to use \captionof to make the caption.

You could apply a \vbox to the group, if you wanted to avoid the image and caption ever ending up on separate pages.

\documentclass{article}
\usepackage{lipsum,caption,graphicx}
\begin{document}
\lipsum[1]\par
{\centering\vspace{10pt}
\includegraphics[scale=0.85]{example-image}
\captionof{figure}{caption of figure\label{fig:img1}}
\vspace{10pt}
\par}
\lipsum[2]
\end{document}

enter image description here

EDITED to show how to add vertical buffer around figure.