1

I am trying to lay out a book with fairly tight requirements on how and where everything needs to be placed, so I am trying to get the \figure to very precisely control the text around it, and to be placed with very well defined white space around it. The problem I am having is that all the figures have far more white space below them than above. I want them to be the same.

(If anyone can identify a documentation that covers the properties that control the space around a \figure please let me know.)

Through an intense web search, I found mentions of parameters \belowcaptionskip, \abovecaptionskip, \intextsep, \floatsep, \textfloatsep. I have set these all to zero, but still there is more space below the float and I can not figure out what is causing it. (I probably don't want these to be zero, but for testing I want to remove their influence.)

Below is a minimal example, and first it simply includes a graphic using \includegraphics and you see that there is about 0.1 inch above and below the graphic. I don't understand why that space it there. Is there another settings that control that. But at least it is symmetrical so I can supposedly control it. The total size of the space in the text is 2.2 inches.

enter image description here

But when I put the same graphic is a \figure the space at the top disappears, and extra space appear below it. In fact the image appears to be displaced up and overlaps the text partially, and extra space (not quite the same amount) appears at the bottom. (Again, ultimately I will probably add space back in, but I want the same amount above and below.) The figure result looks like:

enter image description here

I looks to me like -0.03 inch above it (essentially moved -0.13 up from what the raw includgraphics had, and 0.18 inch below it (essentially increased by 0.08 inch below). The total size of the space in the text is 2.16 inch (a little smaller than the include graphics alone.)

Why is is that putting an image in a figure (when all the parameters I know of are set to zero) cause it lose white space above it and gain white space below it (but not equal amounts).

One of the problems I am trying to solve is to prevent the moving of images to the next page when there is clearly enough space for it on the current page. I am worried that if I try to hack this with a negative \vspace at the bottom, it will still end up being "larger" than the space when it does not need to be.

Use this to produce the same results:

\documentclass[paper=7in:10in,11pt,pagesize=pdftex,openright,headings=twolinechapter,chapterprefix=true]{scrbook}

\usepackage{graphicx}
\usepackage{needspace}
\usepackage{longtable}
\usepackage{framed}
\usepackage{setspace}
\usepackage{showframe}



%page is 7 x 10.  With these margins the printed area
%is 5.75 inches by 9 inches.
\usepackage[inner=0.75in,outer=0.50in,top=0.75in, bottom=0.75in, footnotesep=.3in, footskip=.4in]{geometry}


%Page size settings
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight

   
 \def\mygraphpaper{%
  \begin{tikzpicture}
    \draw[line width=.4pt,draw=black!30] (0,0) grid[step=0.1in] (\paperwidth,\paperheight);
    \draw[line width=.4pt,draw=red!50] (0,0) grid[step=1in] (\paperwidth,\paperheight);
  \end{tikzpicture}%
 }
 \usepackage{tikz}
 \usepackage{background}
 \backgroundsetup{
  angle=0,
  contents=\mygraphpaper,
  color=green,
  scale=1,
 }

\belowcaptionskip = 0pt
\abovecaptionskip = 0pt
\intextsep = 0pt
\floatsep = 0pt
\textfloatsep = 0pt

\begin{document}


ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ IncludeGraphics

  \begin{center}
    \noindent\includegraphics[width=2in]{example-image-1x1.png}
  \end{center}

ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT Float 

\begin{figure}[!ht]
  \begin{center}
    \noindent\includegraphics[width=2in]{example-image-1x1.png}
  \end{center}
\end{figure}

ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL 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Z LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL 

ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL 

\end{document}

MODIFICATION 1

Fran pointed out that \begin{center} environment adds some vertical space. I changed this to \centering and sure enough, there is less space, but the figure is still lopsided. Here is the \includegraphics test and it looks like it is about 0.04 inches on top, and 0.06 inches on the bottom, with the total size 2.1 inches:

enter image description here

Here is the figure version using \centring and it looks like it is about -0.04 inches on top (still overlaps) and about 0.02 on the bottom with a total size of 1.98 inches (smaller than the image!):

enter image description here

A little \vspace might fix this, but is that the right way?

Thanks Fran!

1
  • 1
    As you have seen, center environment not only center. It also adds vertical spaces. Therefore, if that's not what you want, use {\centering ...\par} or inside a figure environment, just \centering before the image.
    – Fran
    Mar 26 at 6:38
1

With a similar problem I found the solution using the xcoffins package.

In short, it puts the material (text, tables, figures, tikzfigures, etc.) in special boxes. (called coffins, bad choice of a name)

It has several advantages:

(1) It allows the union of these boxes in several ways (here it is not necessary)

(2) The boxes are not floats and are typeset at the current insertion points with added offsets. (to be used here). You can place the boxes anywhere on the physical page, including hard-to-reach places such as corners.

In this particular case there are three steps:

(1) Assign with \NewCoffin.

(2) Fill with \SetHorizontalCoffin.

(3) Typeset and offset with \TypesetCoffin.

The first figure is typeset after AAX without offsets.

The second is horizontally centered and has added vertical space at the top and bottom to show the capability, very useful during the finishing touches of the job.

y

% !TeX TS-program = pdflatex

\documentclass[paper=7in:10in,11pt,pagesize=pdftex,openright,headings=twolinechapter,chapterprefix=true]{scrbook}

\usepackage{graphicx}
\usepackage{needspace}
\usepackage{longtable}
\usepackage{framed}
\usepackage{setspace}
\usepackage{showframe}

\usepackage{xcoffins} %<<<< added
\NewCoffin\FigA   %<<<< allocate

%page is 7 x 10.  With these margins the printed area
%is 5.75 inches by 9 inches.
\usepackage[inner=0.75in,outer=0.50in,top=0.75in, bottom=0.75in, footnotesep=.3in, footskip=.4in]{geometry}

%Page size settings
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight

   
 \def\mygraphpaper{%
  \begin{tikzpicture}
    \draw[line width=.4pt,draw=black!30] (0,0) grid[step=0.1in] (\paperwidth,\paperheight);
    \draw[line width=.4pt,draw=red!50] (0,0) grid[step=1in] (\paperwidth,\paperheight);
  \end{tikzpicture}%
 }
 \usepackage{tikz}
 \usepackage{background}
 \backgroundsetup{
  angle=0,
  contents=\mygraphpaper,
  color=green,
  scale=1,
 }

\belowcaptionskip = 0pt
\abovecaptionskip = 0pt
\intextsep = 0pt
\floatsep = 0pt
\textfloatsep = 0pt

\begin{document}
\SetHorizontalCoffin\FigA{\includegraphics[width=2in]{example-image-1x1.png}}   

ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT  No offsets

AAX \TypesetCoffin\FigA

ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT Centered and vertical offsets

\vspace*{1ex} % upper space
\noindent\TypesetCoffin\FigA(0.5\textwidth-1in,-1ex) % center + no lower space

ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT ZZZ LLL ZZZ MMM ZZZ TTT 

\end{document}

Other examples in

I need a rather complex layout for a scholarly edition and don't know where to start

How do I binpack a set of tables on a page?

How to create a word/equation/diagram collage

2
  • I am definitely going to look at this. I was really looking for an understanding of how floats work in the basic LaTeX system. It looks like it is badly broken. So often the solution is "use this package" which on one hand fixes the problem, but on the other interacts with the other packages, sometimes incompatible. As a purist I want to use as few packages as I can. Yet, I can still imagine others out there frustrated by the apparently sloppy calculations of the base system, and made a package that works predictably and precisely.
    – AgilePro
    Mar 26 at 16:30
  • I found xcoffins invaluable for books. Sometimes you want a figure or a table on the opposite open page or just like here. Floats are nice but they don't read minds. The xcoffins doc is very good. Just follow the example. No problem so far with updates or conflicts with other packages. The less packages the better! Try memoir, for book writing. Mar 26 at 16:47

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.