Search code examples
rlatexknitrpapaja

papaja: controlling text spacing when placing floats H


I am using the great papaja package to create a manuscript. I want to place figures in the text (floatsintext: yes) AND I want them to appear exactly where specified.

To achieve the latter, I followed this advice to add the following to the YAML:

header-includes: #allows you to add in your own Latex packages
- \usepackage{float} #use the 'float' package
- \floatplacement{figure}{H} #make every figure with caption = h

This puts the figures where I want, but the text spacing is set to use the entire page. I would prefer that the preceding text uses the space from top to bottom, leaving the whitespace at the bottom of the page before the figure.

enter image description here

---
title             : "The title"
shorttitle        : "Title"

author: 
  - name          : "First Author"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Postal address"
    email         : "[email protected]"
  - name          : "Ernst-August Doelle"
    affiliation   : "1,2"

affiliation:
  - id            : "1"
    institution   : "Wilhelm-Wundt-University"
  - id            : "2"
    institution   : "Konstanz Business School"

authornote: |
  Add complete departmental affiliations for each author here. Each new line herein must be indented, like this line.

  Enter author note here.

abstract: |

keywords          : "keywords"
wordcount         : "X"

bibliography      : ["r-references.bib"]

floatsintext      : yes
figurelist        : no
tablelist         : no
footnotelist      : no
linenumbers       : yes
mask              : no
draft             : no

documentclass     : "apa6"
classoption       : "man,noextraspace"
header-includes:
  - \usepackage{pdfpages}
  - \usepackage{setspace}
  - \AtBeginEnvironment{tabular}{\singlespacing}
  - \makeatletter\let\expandableinput\@@input\makeatother
  - \interfootnotelinepenalty=10000
  - \usepackage{float} #use the 'float' package
  - \floatplacement{figure}{H} #make every figure with caption = h
output            : papaja::apa6_pdf
---

```{r setup, include = FALSE}
library("papaja")
```

```{r analysis-preferences}
# Seed for random number generation
set.seed(42)
knitr::opts_chunk$set(cache.extra = knitr::rand_seed)
```

# Methods
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sollicitudin libero id arcu accumsan sagittis. Sed vel rutrum magna, et posuere tellus. Aenean auctor maximus mauris, a dapibus lectus. Sed efficitur ultricies semper. Vestibulum dignissim mollis dui, ut rhoncus urna porttitor id. Vestibulum eget maximus tellus, molestie imperdiet nulla. Phasellus congue, libero quis sagittis porttitor, ex dui posuere leo, eget viverra nisi sapien non arcu. Ut consectetur magna quis sem fringilla, ac elementum risus suscipit. Morbi lobortis sem non ante imperdiet, in faucibus dui lobortis. Nam at lorem erat. Donec nec maximus erat, quis vehicula mi. Sed sed gravida lacus. Nam non elit enim.

Maecenas finibus turpis at lectus convallis, eget congue turpis rutrum. Fusce eleifend tellus turpis, eget egestas odio mattis at. Aenean interdum lectus a orci tempus, eget sodales diam congue. Aenean ac tellus a leo auctor rhoncus. Nam condimentum, diam sit amet iaculis gravida, risus augue aliquam urna, in vestibulum eros ex quis risus. Quisque porta euismod lectus hendrerit sollicitudin. Nulla condimentum est risus, non interdum urna commodo ac.


```{r pressure, echo=FALSE}
plot(pressure)
```

Solution

  • The documentclass you are using seems to have \flushbottom active, which will ensure that all pages have the same bootom line. This is usually done in things like books etc.

    If you don't want this, you can use the \raggedbottom macro.