2017-02-27 38 views
8

Bir RMarkdown belgesine şekil eklemeye çalışıyorum, ancak doğru yerde görünmesi için sorun yaşıyorum. Aşağıdaki şekil problemi göstermektedir: bir şekil başlığı kullanıldığında, şekil belgedeki ilgili paragrafın altına değil, sayfanın üst kısmında görünür. İşte Knitr fig.pos'u göz ardı ediyor mu?

enter image description here

Bu minimum çalışma örneği kodudur:

--- 
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. 

Ve burada LaTeX çıkışın ilgili parçasıdır; fig.pos seçenek göz ardı edilir unutmayın:

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. 

Benim kurulum aşağıda açıklanmıştır. Eminim bu, daha önceki knitr sürümünde çalıştığından eminim, ancak hangi versiyonun olabileceğine dair bir notum yok.

> 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 
+0

Kişisel MCVE beklendiği gibi derler (şek paragraflar arasında olup, '\ begin {figure} [hTBP]' tex dosyasında) (ı linux çıkıyorum aynı knitr/rmarkdown versiyonu, ama) benim makinede . Belki pandoc versiyonunu kontrol et (17.1). – scoa

+0

1.19.2.1 var. Düşürme ihtiyacı olabilir ... – jkeirstead

+0

Evet, 1.17.2'ye düştüm ve her şey bir kez daha iyi. Teşekkürler. – jkeirstead

cevap

9

knitr saf Markdown ![]() yerine LaTeX figure ortamı yazmak zorunda düşündüğünde yığın seçenek fig.pos sadece kullanılır ve bunun bir şekil açıklaması (fig.cap) belirtildiğinde yalnızca LateX'i yazar ve, bu seçeneklerden en az biri belirtilmiştir: fig.align, out.width, out.extra. knitr şekilleri için LaTeX kodunu yazmak ve fig.pos'u kullanmak için zorlamak istiyorsanız, out.extra = '' yığın seçeneğini ayarlayabilirsiniz.

0

bu zaten Yihui Xie tarafından yanıtlandı biliyorum ama out.extra = '' ya da altyazısı olmayan işlenen figürlerin müdahale etmeden verildi diğer seçeneğin herhangi içerecek şekilde ihtiyacını ortadan kaldırır alternatif bir çözüm var.

'float' lateks paketini ekleyin ve her bir resim yazısı istediğiniz şekilde metin içinde düzgün bir şekilde işlendiğinden emin olmak için \floatplacement{figure}{H} kullanın. Alternatif olarak,, RMarkdown bir pdf'yi örttüğünde kullanılan .tex dosyasına eklenebilir, ancak bu konuda oldukça yeniyim ve bu seçeneğe kendim bakmak için zamanım olmadı.

Ben sadece YAML içine üç satırı ekleyerek oldukça kolay bir düzeltmedir Chestar Ismay

den thesisdown pakette .tex dosyasına bakarak bu düzeltme bulundu. Çalışan bir ekran görüntüsünü yayınlamak için yeterli saygınlığım yok ama yaptığım şeyi kopyalayıp kendiniz deneyebilirsiniz!

--- 
title: "Untitled" 
author: "Author" 
date: "27 February 2017" 
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 
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. 
İlgili konular