1

I have searched the other question here extensively as the problem of spacing seems to re-occur often, but still have not found the solution to my specific problem:

I have way to much white space above my figure! Even after lowering the \floatsep (has no effect at all it seems). The figure itself does not have any white space on top (I have double checked). I have also tried by defining the bounding box instead of the natwidth,natheight, but still the same output so it is driving me crazy.

This is a MWE which results in the given picture which is of course not what I desire

enter image description here

\documentclass[fleqn,10pt,twoside,openright]{report}

\usepackage{graphicx}
% set graphics path
\graphicspath{{Figures/}}

\begin{document}

 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis tristique velit, gravida vehicula mi. Donec iaculis, nunc venenatis tempor porttitor, sapien leo elementum urna, nec congue tellus ligula condimentum lectus. Praesent ullamcorper congue risus et porta. Fusce viverra tortor tempor odio porttitor efficitur. In congue tortor eget libero dignissim, sit amet eleifend diam tempor. Ut convallis pretium sapien, a cursus ante iaculis quis. Vestibulum dictum mauris nec tellus mollis, quis laoreet dolor ornare. Vivamus vehicula magna sed urna mattis pellentesque. Donec malesuada tortor a leo venenatis, sit amet maximus orci accumsan. Cras tempus imperdiet neque eget imperdiet. Nulla iaculis in ante et tempor. Quisque euismod, sem id sodales mattis, ex nisl tincidunt nisl, vitae sollicitudin nisi nunc eu tortor. Praesent varius massa mi, vitae malesuada ante laoreet nec. Sed in dui eu urna iaculis facilisis. Integer et arcu a metus varius rutrum. Mauris orci nunc, iaculis ut nunc ultricies, maximus feugiat augue.


\begin{figure}[htbp]%

\centering

\includegraphics[natwidth=124px,natheight=169px,width=5cm]{sad.png}%

\caption{testFig}%

\end{figure}

Nullam at dui sapien. Morbi orci orci, blandit sed erat non, tempus venenatis neque. Donec ut venenatis nunc. Mauris volutpat lectus nec molestie iaculis. Donec lobortis arcu a ante cursus sodales. Mauris nec nulla sapien. Morbi id volutpat eros. Vestibulum quis justo eget lectus pellentesque molestie. In hac habitasse platea dictumst. Nullam pellentesque gravida felis non ultrices. Pellentesque tellus velit, congue id accumsan id, lacinia a eros. In molestie porta est non tristique.

\end{document}
7
  • It is impossible to really debug without the image but you almost never want to specify natwidth and natheight if they are the actual natural size of the figure they are not needed, and if they are not exactly the size of the figure then strange things happen. If you could reproduce the problem using example-image (that most people have already) it would be easier to help Mar 4, 2016 at 11:28
  • Welcome to TeX.SX! The first debugging step is to enclose the \includegraphics in an \fbox, so as to see whether the white space is in the picture itself.
    – egreg
    Mar 4, 2016 at 11:28
  • egreg: the white space is not in the picture itself, as I said I already checked that as mentioned in the post
    – Ingrid
    Mar 4, 2016 at 12:23
  • the problem can be reproduced with any png picture (of course after updating to the correct pixel size). Sorry I was not aware of the existence of example pictures and I am not quit sure how to use them
    – Ingrid
    Mar 4, 2016 at 12:27
  • carlisle: I am specifying the natwidth and natheight because otherwise my picture was not showing because I am using the Latex->DVI->pdf sequence to compile. This is not my choice but cannot be changed as I am using a template of my university and otherwise a whole lot of other stuff will change which I have no idea on how to correct (I am new at this). So I have found this solution here.
    – Ingrid
    Mar 4, 2016 at 12:27

2 Answers 2

1

I think this might be down to conflicting definitions of the size of a 'pixel'. Using preview, I find that this image has size 14pt x 14pt (approximately), or 48 pixels x 48 pixels.

enter image description here

However, the following experiment using pdftex produces something quite different:

*\newdimen\mydimen
*\mydimen=1px
*\showthe\mydimen
> 1.00375pt.

So 1px = 1pt (more or less). Using the image in a document, and compiling with latex+dvipdfmx produces white space if I use 48px for natwidth and natheight, but the problem goes away if I use 14pt.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\fbox{\includegraphics[natwidth=48px,natheight=48px,width=5cm]{xboard.png}}% 
\fbox{\includegraphics[natwidth=14pt,natheight=14pt,width=5cm]{xboard.png}}% 
\end{document}

enter image description here

So, try using measurements in points, rather than pixels.

1

david carlisle, since you made the comment about the natwidth definition I started searching more in this direction and more specifically how I can avoid to use this. So I have found that if I include this, it works without needing to define the size of the image and the annoying white space disappears. Unfortunately, also my figure in my more complex document disappeared. But I figured out that was because I was also using the color package which was apparently interfering, but I solved that by putting the color package before the graphicx package and my figure re-appeared. Thank you for your help!

\usepackage[dvipdfm]{graphicx}
\usepackage{bmpsize}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.