2
votes

I seem to be unable to control the number of blank spaces after a figure caption.

For two (to my eyes) identical pieces of code, one is placed and immediately followed by text after its caption, whereas the other figure has about half a page worth of blank space following its caption before the text I want is there.

the two chunks giving different results in the .pdf output

the corresponding two plots

In this second picture - of latex'd plots, why does the first code chunk give a near-empty page after caption and the second be followed by subsequent text so nicely?

This is a part of my index.rmd (minus title, etc.) - could it be something to do with linestretch?

header-includes: 
- \usepackage{float}  #use the 'float' package
- \floatplacement{figure}{H} #make every figure with caption = H
output:
  bookdown::pdf_book:
    fig_caption: yes
    fig_crop: false
    df_print: kable
    includes:
      in_header: preamble.tex
    latex_engine: xelatex
    keep_tex: yes
fontsize: 11pt
linestretch: 1.5
toc-depth: 1
secnumdepth: 1
lof: True
lot: True
site: bookdown::bookdown_site
documentclass: book
classoption: openany
bibliography: [packages.bib, book.bib]
biblio-style: apalike
link-citations: True
geometry: "left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm"
---

my bookdown.yml

book_filename: "_Project2019"
delete_merged_file: true
before_chapter_script: "script1.R"
rmd_files: ["index.Rmd", "01-intro.Rmd", "02-EDA.Rmd", "03-method.Rmd"]
documentclass: book
language:
  label:
    fig: "Figure"
    tab: "Table"

and my output.yml

bookdown::pdf_book:
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
  fig_width: 6
  fig_height: 4.5
  fig_crop: false
  fig_caption: true
  df_print: kable

Additionally, I'm using this as my preamble.tex, where all the \let\origfigure lines were just a solution to making fig.pos="h" work consistently I saw on here a while ago...

\usepackage{booktabs}
\usepackage[none]{hyphenat}
\usepackage{float}
\usepackage[belowskip=-5pt,aboveskip=0pt]{caption}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
    \expandafter\origfigure\expandafter[H]
} {
    \endorigfigure
}
\pagestyle{plain}

I've already tried adding the caption package with belowskip=-5pt as you can see in this. I've also already tried a good amount of combinations of no spaces before/after each chunk but it does seem random - is there an option I'm missing in the code chunks themselves? I'm quite stuck!

I don't really know how to make this problem replicable so I apologise for that, any ideas let me know

Thanks in advance,
James

1
Just as a test, can you change \floatplacement{figure}{H} to \floatplacement{figure}{htbp} ? My suspicion is that there is not enough room on the one page to place two figures, but because of your restrictive options to place the floats, the only solution tex has left is to insert white space because it is not allowed to effectively float the image to a suitable placesamcarter_is_at_topanswers.xyz
@samcarter Thanks! That's fixed the problem for all of my figures apart from one which is now taking up an entire page seen hereyanqui
The figure looks misplaces, neither vertically nor horizontally centred. Could it be, that the image has excessive white space around it and thus is too big to place it in the normal text?samcarter_is_at_topanswers.xyz
@samcarter i believe it's something to do with that, either changing the out.width part of the chunk commands or just reducing the dimensions places it where it should be!yanqui

1 Answers

2
votes

I suggest to change \floatplacement{figure}{H} to \floatplacement{figure}{htbp}. This will give latex more possibilities to come up with suitable positions for the images.

At the moment there is simply not enough room on the one page to place two figures, but because of your restrictive options to place the floats, the only solution tex has left is to insert white space because it is not allowed to effectively float the image to a suitable place