How to get images from the .tex folder (relative path) in Rmarkdown?

后端 未结 2 1953
刺人心
刺人心 2021-01-25 04:12

I\'m trying to get a watermark image like here:

How to add a watermark image on rmarkdown?

I almost did it, but as I wrote on my original question the back

相关标签:
2条回答
  • 2021-01-25 04:53

    "It works for me." Here is a minimal Rmarkdown file, trimmed down from one of the templates offered by RStudio:

    ---
    title: "Demo"
    author: "Dirk"
    date: "October 3, 2016"
    output: pdf_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## R Markdown
    
    This is an R Markdown document. We include one figure
    
    \includegraphics{Rlogo.png}
    
    La fin.
    

    I can hit the knit button just fine, or run this by hand:

    /tmp$ cat includeDemo.Rmd
    ---
    title: "Demo"
    author: "Dirk"
    date: "October 3, 2016"
    output: pdf_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## R Markdown
    
    This is an R Markdown document. We include one figure
    
    \includegraphics{Rlogo.png}
    
    La fin.
    
    /tmp$ Rscript -e 'rmarkdown::render("includeDemo.Rmd")'
    
    
    processing file: includeDemo.Rmd
      |......................                                           |  33%
      ordinary text without R code
    
      |...........................................                      |  67%
    label: setup (with options) 
    List of 1
     $ include: logi FALSE
    
      |.................................................................| 100%
      ordinary text without R code
    
    
    output file: includeDemo.knit.md
    
    /usr/bin/pandoc +RTS -K512m -RTS includeDemo.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output includeDemo.pdf --template /usr/local/lib/R/site-library/rmarkdown/rmd/latex/default-1.15.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' 
    
    Output created: includeDemo.pdf
    /tmp$ 
    

    Maybe something is playing tricks with you by switching from the current directory to a temporary processing directory. In which an (icky!!) absolute path may help...

    0 讨论(0)
  • 2021-01-25 04:55

    I just did it.

    The problem were on MiKTeX for Windows.

    I just followed the steps on this answer, remembering to assure that the folder is TDS-compliant (with a tex folder in it), and after I just put the image on the tex folder.

    0 讨论(0)
提交回复
热议问题