我使用R标记v2创建一个光束演示文稿。我的大多数幻灯片都包含了ggplot生成的图像,有时还会在幻灯片的上方加上解释性文本。我发现,我真的必须单独调整每个幻灯片上每个元素的大小(即图像、文本等),以确保图像不会从幻灯片的末尾被推开。
这最终花费了很长的时间,并且某种程度上挫败了R标记的一个既定目的:那就是,快速地吐出可重复的研究。
我想知道是否有任何方法使各种元素智能自动大小?即使它看起来不太好,至少事情不会被推开?或者,如果没有,也许还有其他的方法来确保事情不需要太多的时间。
提前谢谢你的想法..。
发布于 2015-11-08 03:20:35
这是一个棘手的问题,因为排版很棘手。Rmarkdown在隐藏许多棘手的细节方面做得很好,但是如果您想要排版,就需要排版。在拉特克斯甚至很难,你会看到的。有太多的移动部分,例如标题和传说,呈现一个图像,然后包含在中间的.tex文件中,这样pandoc就可以生成.pdf。一个完全通用的解决方案是不可能的,不需要大量的输入(这是您试图避免的第一步)。
我不认为创建Beamer演示文稿本身与可复制的研究是不相容的,但它是一个合法的输出,可能与其他报告一样。
但是在开始使用Latex之前,您应该考虑一个非常简单的解决方法:只在每一张幻灯片上放置一个图形而不使用文本。这可靠地符合幻灯片上的图像。然后,您可以在ggplot2中使用注释来添加其他文本。这就是我会做的。
下面的Rmarkdown使用一个复杂的嵌入式Latex来做您想做的事情。它确实将图像限制在屏幕的下半部分(但如果您了解更多关于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(回声=假,fig.path=“数字/光束-示例/”)
图书馆(Ggplot2)
```{r}mtcars$齿轮<-因子(mtcars$3,4,5,levels=c(3,4,5),
Labels=c(3齿轮、4齿轮、5齿轮)
$am <- factor(mtcar$am,levels=c(0,1),
Labels=c(“自动”、“手动”)
$cyl <- factor(mtcar$cyl,levels=c(4,6,8)
Labels=c(“4 8cyl”,“6 8cyl”,“8 8cyl”)
## A default plot
```{r mpg-plot}(mpg,data=mtcars,geom=“密度”,fill=gear,alpha=I(.5)
Main=“汽油里程分配”,xlab=“每加仑英里”,
Ylab=“密度”)
## 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-page中阅读一些血淋淋的详细信息。
https://stackoverflow.com/questions/28284319
复制相似问题