代码之家  ›  专栏  ›  技术社区  ›  Jonas Striaukas

rmarkdown数字未出现在pdf中

  •  0
  • Jonas Striaukas  · 技术社区  · 2 年前

    我使用rmarkdown创建了一组幻灯片。我用乳胶加了一个数字 includegraphics 其如预期的那样工作。但是,当我添加一个通过R代码生成的图形时,“乳胶”图形就会消失。

    最小代码示例

    ---
    title: "TITLE"
    author: "JS"
    subtitle: SUBTITLE
    output:
      beamer_presentation: 
        keep_tex: yes
      ioslides_presentation: default
    fontsize: 14pt
    ---
    
    
    
    # Example 
    
    \begin{figure}[t]
      \centering
      \includegraphics[scale=0.25]{include_figure}
    \end{figure}
    
    ---
    
    # Add figure via R code
    
    ```{r, message = FALSE, warnings = FALSE, eval = TRUE, echo = TRUE}
    plot(rnorm(100))
    

    有什么建议我做错了什么吗?

    1 回复  |  直到 2 年前
        1
  •  2
  •   samcarter_is_at_topanswers.xyz    2 年前

    出于某种原因,rmarkdown和/或pandoc认为添加

    \makeatletter
    \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
    \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
    \makeatother
    % Scale images if necessary, so that they will not overflow the page
    % margins by default, and it is still possible to overwrite the defaults
    % using explicit options in \includegraphics[width, height, ...]{}
    \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
    

    序言是个好主意。。。显然不是这样。

    您可以通过指定图像的高度而不是比例因子来避免这个问题:

    ---
    title: "TITLE"
    author: "JS"
    subtitle: SUBTITLE
    output:
      beamer_presentation: 
        keep_tex: yes
      ioslides_presentation: default
    fontsize: 14pt
    ---
    
    
    
    # Example 
    
    \begin{figure}
      \includegraphics[height=4cm]{example-image-duck}
    \end{figure}
    
    ---
    
    # Add figure via R code
    
    ```{r, message = FALSE, warnings = FALSE, eval = TRUE, echo = TRUE}
    plot(rnorm(100))
    ```