gpt4 book ai didi

r - 如何在knitr的pdf输出中使用图形标题保持图形位置?

转载 作者:行者123 更新时间:2023-12-03 08:35:50 25 4
gpt4 key购买 nike

我正在使用 knitr(1.9.5 和 1.9.17)和 rmarkdown(0.5.3.1),并希望在 pdf 输出中保留图形位置。当块选项 fig.pos="H" 时,生成的 pdf 文件工作正常用来。

但是,当 fig_caption: yes 时,图形位置不保持设置在
yaml 头文件。

我应该如何解决这个问题?感谢您的任何建议。

编辑:

在学习了Latex的float环境之后。我加float打包成标题。

\usepackage{float}

但是生成的tex文件总是使用 htbpfigure环境方面的任何 fig.pos选项被使用。手动更改后 htbpH ,所有数字的位置都保持不变。

这是我的 rmd 文件示例:
---
title: "Untitled"
output:
pdf_document:
fig_caption: yes
includes:
in_header: mystyles.sty
---

# Section 1


Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.


```{r fig1, echo=FALSE, fig.height=8.5, fig.pos="H"}
plot(cars)
```

# Section 2

More test

```{r fig2, echo=FALSE, fig.height=8.5, fig.pos="H"}
plot(cars)
```

# Section 3

```{r fig3, echo=FALSE, fig.height=8.5, fig.pos="H"}
plot(cars)
```

More test

最佳答案

对我来说添加 float打包然后\floatplacement{figure}{H}在 YAML 中解决了如下问题:

---
title: "test"
date: "`r Sys.Date()`"
output:
pdf_document :
keep_tex: true
number_sections: true
header-includes:
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage[table]{xcolor}
\usepackage{wrapfig}
\usepackage{float}
\floatplacement{figure}{H}
---

关于r - 如何在knitr的pdf输出中使用图形标题保持图形位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29696172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com