Tôi đang cố gắng chèn một hình trong một tài liệu RMarkdown nhưng đang gặp khó khăn để nó xuất hiện ở đúng nơi. Hình bên dưới cho thấy vấn đề: khi sử dụng chú thích hình, con số xuất hiện ở đầu trang thay vì bên dưới đoạn có liên quan trong tài liệu.Knitr bỏ qua fig.pos?
Đây là mã cho tối thiểu này ví dụ làm việc:
---
title: "Untitled"
author: "Author"
date: "27 February 2017"
output:
pdf_document:
fig_cap: yes
keep_tex: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.pos= "h")
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
\newpage
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE, fig.cap = "Hello"}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Và đây là phần có liên quan của sản lượng LaTeX; lưu ý rằng tùy chọn fig.pos
bị bỏ qua:
You can also embed plots, for example:
\begin{figure}
\centering
\includegraphics{test_files/figure-latex/pressure-1.pdf}
\caption{Hello}
\end{figure}
Note that the \texttt{echo\ =\ FALSE} parameter was added to the code
chunk to prevent printing of the R code that generated the plot.
Thiết lập của tôi được mô tả bên dưới. Tôi khá chắc chắn điều này đã làm việc trong phiên bản trước của knitr, nhưng tôi không có một lưu ý về phiên bản mà có thể có được.
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] backports_1.0.5 magrittr_1.5 rprojroot_1.2 htmltools_0.3.5 tools_3.3.2
[6] yaml_2.1.14 Rcpp_0.12.9 stringi_1.1.2 rmarkdown_1.3 knitr_1.15.1
[11] stringr_1.2.0 digest_0.6.12 evaluate_0.10
MCVE của bạn biên dịch như mong đợi (hình giữa các đoạn, '\ begin {figure} [htbp]' trong tệp tex) trên máy của tôi (cùng phiên bản đan/rmarkdown) nhưng tôi đang sử dụng linux) . Có thể kiểm tra phiên bản pandoc của bạn (17.1). – scoa
Tôi đã có 1.19.2.1. Có thể cần phải hạ cấp ... – jkeirstead
Có, tôi đã hạ cấp xuống 1.17.2 và tất cả đều tốt một lần nữa. Cảm ơn. – jkeirstead