簡體   English   中英

圖像從R markdown推出投影機輸出的幻燈片

[英]Images pushed off slides in beamer output from R markdown

我正在使用R markdown v2創建一個投影儀演示文稿。 我的大多數幻燈片都包含由ggplot生成的圖像,有時在幻燈片上方有解釋性文字。 我發現我必須單獨調整每張幻燈片上每個元素的大小(即圖像,文本等),以確保圖像不會從幻燈片的末尾被推出。

這最終變得非常耗時,並且有點失敗了R降價的既定目的之一:即,是一種快速的方式來吐出可重復的研究。

我想知道是否有任何方法可以智能地自動調整各種元素的大小? 即使看起來不太好,至少事情也不會被推到最后? 或者如果沒有,也許人們會使用其他方法來確保事情恰好適合不花太多時間。

提前感謝您的想法......

這是一個棘手的問題,因為排版很棘手。 Rmarkdown在隱藏很多棘手的細節Rmarkdown做得很好,但是如果你想排版,你需要排版。 你會看到,在Latex中它甚至很難。 有很多移動部件,例如標題和圖例,渲染圖像然后包含在中間.tex文件中,因此pandoc可以生成.pdf 如果不要求大量輸入(這是您首先想要避免的),那么完全可推廣的解決方案是不可能的。

我不認為創建Beamer演示文稿本身與可重復的研究不兼容,但可能是合法的輸出,可能與其他報告一起。

但是在推出Latex之前,你應該考慮一個非常簡單的解決方法,即只在每張幻燈片上放置一個圖形而不是文本。 這可靠地適合幻燈片上的圖像。 然后,您可以在ggplot2使用注釋來添加其他文本。 這就是我要做的。

以下Rmarkdown使用一些復雜的嵌入式Latex來做你想做的或多或少的事情。 它確實將圖像限制在屏幕的下半部分(但如果您了解有關tikz更多信息,則可以更改此圖像...),但是當上部文本塊增加時, tikz圖像縮放到剩余的頁面大小。 當然,它也可以擴展你的所有傳說,但你可以在ggplot2中調整它們。

---
title: "Some beamer slides with figures"
author: Somebody
date: November 06, 2015
output:
  beamer_presentation:
    keep_tex: yes
header-includes:
- \usepackage{graphicx}
- \usepackage{tikzpagenodes}
- \usetikzlibrary{calc}
- \usepackage{caption}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, fig.path="figures/beamer-example/")

library(ggplot2)
```

```{r}
mtcars$gear <- factor(mtcars$gear,levels=c(3,4,5),
   labels=c("3gears","4gears","5gears"))
mtcars$am <- factor(mtcars$am,levels=c(0,1),
   labels=c("Automatic","Manual"))
mtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8),
   labels=c("4cyl","6cyl","8cyl"))
```
## A default plot

```{r mpg-plot}
qplot(mpg, data=mtcars, geom="density", fill=gear, alpha=I(.5),
   main="Distribution of Gas Milage", xlab="Miles Per Gallon",
   ylab="Density")
```

## test

  - some text which
  - fills vertical 
  - space

\begin{tikzpicture}[overlay,remember picture]
    % Caption
    \node [anchor=south west,outer sep=0pt,inner sep=0pt,text width=\textwidth] (caption) at (current page text area.south west) {%
    };
    % Image
    \path let \p0 = (0,0), \p1 = (caption.north) in
        node [inner sep=0pt,outer sep=0pt,anchor=south] at (\x1,\y1) {%
            \pgfmathsetmacro\imgheight{\y0-\y1-\abovecaptionskip}%
            \includegraphics[height=\imgheight pt,width=\textwidth,keepaspectratio]{figures/beamer-example/mpg-plot-1}%
    };
\end{tikzpicture}

## test2

  - some text which
  - fills vertical 
  - space
  - but squashes
  - the image badly

\begin{tikzpicture}[overlay,remember picture]
    % Caption
    \node [anchor=south west,outer sep=0pt,inner sep=0pt,text width=\textwidth] (caption) at (current page text area.south west) {%
    };
    % Image
    \path let \p0 = (0,0), \p1 = (caption.north) in
        node [inner sep=0pt,outer sep=0pt,anchor=south] at (\x1,\y1) {%
            \pgfmathsetmacro\imgheight{\y0-\y1-\abovecaptionskip}%
            \includegraphics[height=\imgheight pt,width=\textwidth,keepaspectratio]{figures/beamer-example/mpg-plot-1}%
    };
\end{tikzpicture}

## test3
\begin{tikzpicture}[overlay,remember picture]
    % Caption
    \node [anchor=south west,outer sep=0pt,inner sep=0pt,text width=\textwidth] (caption) at (current page text area.south west) {%
    };
    % Image
    \path let \p0 = (0,0), \p1 = (caption.north) in
        node [inner sep=0pt,outer sep=0pt,anchor=south] at (\x1,\y1) {%
            \pgfmathsetmacro\imgheight{\y0-\y1-\abovecaptionskip}%
            \includegraphics[height=\imgheight pt,width=\textwidth,keepaspectratio]{figures/beamer-example/mpg-plot-1}%
    };
\end{tikzpicture}

您可以在以下網址閱讀一些血腥的詳細信息: https//tex.stackexchange.com/questions/14512/how-to-define-a-figure-size-so-that-it-consumes-the-rest-of-a-頁

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM