首页 > 解决方案 > 在 Rmarkdown/papaja 中保持 apa_table 位置

问题描述

我确实有另一个 Rmarkdown/papaja 包问题,如果有人愿意提供帮助,我会很高兴:)

与互联网上的许多人一样,我很难控制我的桌子的位置。我有

floatsintext: yes

YAML 标头中包含的选项。我知道有诸如 fig.pos = "!H" 之类的 LATEX 选项,我必须为此加载 float 包

header-includes:
- usepackage\{float}

但是,这样做我收到以下错误消息:

! LaTeX Error: Unknown float option `H'.

这告诉我浮动包无法加载我猜?(我确实安装了 MacTex 以及最新的 R 版本)。

对我来说绝对令人困惑的是,当我离开默认间距时,表格(使用 app_table() 生成)出现在(大约)正确的位置,但只在我添加时出现在我的工作结束时

header-includes:
  - \usepackage{setspace}
  - \AtBeginEnvironment{tabular}{\singlespacing}
  - \AtBeginEnvironment{lltable}{\singlespacing}
  - \AtBeginEnvironment{tablenotes}{\singlespacing}

到 YAML 标头以控制我的表格的间距。

我真的很感激任何帮助!提前致谢!

编辑:我不知道这是否达到目的,但如果我创建以下选项,我的表格会出现在最后(而不是应该在哪里)

title : "TITLE" 
shorttitle        : "short title"

author: 
  - name          : "me"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "x"
    email         : "y"
    role:         # Contributorship roles (e.g., CRediT, https://casrai.org/credit/)
      - Conceptualization
      - Writing - Original Draft Preparation
      - Writing - Review & Editing
 #  - name          : "Ernst-August Doelle"
 #    affiliation   : "1,2"
 #    role:
  #      - Writing - Review & Editing

affiliation:
  - id            : "1"
    institution   : ""
 #  - id            : "2"
#     institution   : "Konstanz Business School"

authornote: |
  Enter author note here.

abstract:  |
 
keywords          : "keywords"
wordcount         : "X"

bibliography      : 

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

csl:                "apa.csl"
documentclass     : "apa7"
classoption       : "man"
output            : papaja::apa6_pdf

toc: true 
header-includes:
  - \usepackage{float}
  - \usepackage{setspace}
  - \AtBeginEnvironment{tabular}{\singlespacing}
  - \AtBeginEnvironment{lltable}{\singlespacing}
  - \AtBeginEnvironment{tablenotes}{\singlespacing}
---


{r setup, include = FALSE}
library("papaja")
library("apa")
library("tidyverse")
library("apaTables")
r_refs("r-references.bib")


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


{r}
cor_table <- apa.cor.table(iris)


Text BLABLABLABLA

{r tab, results = "asis", fig.pos = "!h"}
apa_table(cor_table$table.body,
          caption = "Means, standard deviations, and correlations with confidence intervals for study variables.", 
          note = "Note. M and SD are used to represent mean and standard deviation, respectively.Values in square brackets indicate the 95% confidence interval.The confidence interval is a plausible range of population correlations that could have caused the sample correlation (Cumming, 2014). * indicates p < .05. ** indicates p < .01.", font_size = "footnotesize", row.names = F,
          placement = "p")


# Methods
We report how we determined our sample size, all data exclusions (if any), all manipulations, and all measures in the study. <!-- 21-word solution (Simmons, Nelson & Simonsohn, 2012; retrieved from http://ssrn.com/abstract=2160588) -->

## Participants

## Material

## Procedure

## Data analysis
We used `r cite_r("r-references.bib")` for all our analyses.


# Results

# Discussion


\newpage

# References

\begingroup
\setlength{\parindent}{-0.5in}
\setlength{\leftskip}{0.5in}

<div id="refs" custom-style="Bibliography"></div>
\endgroup

标签: latexr-markdownpapaja

解决方案


对于 PDF 输出,推荐一种方法来自定义通过apa_table(). (您不必float通过头文件加载包。)

首先,设置 YAML 标头选项floatsintext: yes

其次,在创建表时apa_table(),使用函数的placement参数:

```{r tab}
apa_table(cor_table$table.body,
          caption = "Means, standard deviations, and correlations with confidence intervals for study variables.", 
          note = "Note. M and SD are used to represent mean and standard deviation, respectively.Values in square brackets indicate the 95% confidence interval.The confidence interval is a plausible range of population correlations that could have caused the sample correlation (Cumming, 2014). * indicates p < .05. ** indicates p < .01.", font_size = "footnotesize", row.names = F,
          placement = "H")

推荐阅读