Reputation: 71
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.
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
Upvotes: 2
Views: 9029
Reputation: 38783
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
Upvotes: 2