Q: What's the best way to fill an entire beamer slide with tikzDevice output (i.e., the .tex
file output from the tikz()
function in R's tikzDevice
package)?
I've included some undesirable examples below. In summary:
- Example 1: Can see that the input .pdf looks sloppy.
- Example 2: Can see that simply inputting the tikzDevice output leads to spilling out over the slide
- Example 3: Can see that simply inputting the tikzDevice output designed to fill the text region works just fine. But this is not my goal. I want to fill the entire slide
- Example 4: Can see that the
\resizebox{}
leads to spillage. I was surprised this didn't work - Example 5: Including the tikzDevice output within another
tikzpicture
environment. This actually works fine. But atikzpicture
environment within atikzpicture
environment? Seems hacky. There must be a better way. - Example 6: Well, there's no actual example here. I'm just hypothesizing that there are some minimal edits one can make directly to the tikzDevice output which will lead to the desired outcome. But I've mucked around and come up with nothing.
R Code
################### Setup
library(tikzDevice)
beamer.parms = list(paperwidth = 364.19536/72, # converts `pt` to `in`
paperheight = 273.14662/72,
textwidth = 307.28987/72,
textheight = 269.14662/72,
x = rnorm(1000)
#################### PDF Plot
pdf(file = "./img/img0010a-eg.pdf",
width = beamer.parms$paperwidth,
height = beamer.parms$paperheight)
plot(x, main = "my title", las = 1, type = "n")
grid(lwd=2, lty="dashed", col="gray")
points(x)
dev.off()
######################## TikZ image to fill full beamer slide
tikz("./img/img0010b-eg-full.tex",
width = beamer.parms$paperwidth,
height = beamer.parms$paperheight)
plot(x, main = "my title", las = 1, type = "n")
grid(lwd=2, lty="dashed", col="gray")
points(x)
dev.off()
######################## TikZ image to fill text region of beamer slide
tikz("./img/img0010c-eg-text.tex",
width = beamer.parms$textwidth,
height = beamer.parms$textheight)
plot(x, main = "my title", las = 1, type = "n")
grid(lwd=2, lty="dashed", col="gray")
points(x)
dev.off()
tikzDevice output (img0010b-eg-full.tex)
\begin{tikzpicture}[x=1pt,y=1pt]
<coloring commands>
\begin{scope}
\path[clip] ( 0.00, 0.00) rectangle (365.56,274.17);
<more coloring commands>
<drawing commands>
\end{scope}
\end{tikzpicture}
LaTeX Code
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} % fills a full slide, put is ugly because of pdf input
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[width=\paperwidth, height=\paperheight]{./img/img0010a-eg}
};
\end{tikzpicture}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} % spills off to the right
\input{./img/img0010b-eg-full.tex}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} % fills the text region of the slide. But goal is to fill ALL.
\input{./img/img0010c-eg-text.tex}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} % Surprised this didn't work. Spills off to the right.
\resizebox{\paperwidth}{\paperheight}{%
\input{./img/img0010b-eg-full.tex}
}%
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame} % This works. But a tikzpicture environment inside of a
% tikzpicture environment? This seems hacky. Must be a better
% way.
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\input{./img/img0010b-eg-full.tex}
};
\end{tikzpicture}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
Resulting slides
tikzDevice
you get the plot font matching the style and size of the surrounding latex document. You can edit all the text of the plot to include complicated mathematics as well. It's great! I just need to be able to fill a god-damned slide! I can't believe this is so hard.