18

When making presentations (with latex beamer class), I often go for a frame layout with text and equations on the left and a corresponding figure on the right. My standard solution has been to wrap the text in a minipage and figure in another minipage and add a small space in between, but it does not work when replacing the figure with a knitr chunk.

As this is a common slide design I hope someone out there knows how to produce it.

enter image description here

%-------------------------------[ Text + pdf on disk works fine ]
\begin{frame}
  \begin{minipage}{5cm}
    Text
  \end{minipage}
  \hspace{.5cm}
  \begin{minipage}{5cm}
    \begin{figure}
      \includegraphics{my_figure.pdf}
    \end{figure}
  \end{minipage}
\end{frame}

%-------------------------------[ Text + knitr chunk does not work ]
\begin{frame}
  \begin{minipage}{5cm}
    Text
  \end{minipage}
  \hspace{.5cm}
  \begin{minipage}{5cm}
<<echo=FALSE,eval=TRUE,out.width='4cm',out.height='4cm'>>=
plot(1:10)
@
  \end{minipage}
\end{frame}
lockstep
  • 250,273
Backlin
  • 401
  • 1
    i've had some success with \begin{columns}... in beamer+ knitr. – baptiste Nov 16 '12 at 10:02
  • Thanks! I got it working now. I was experimenting with it too earlier, but couldn't figure out how and abandoned it. There is just such a vast amout of possibilities in LaTeX you can't follow every lead through, unless you know it can do the job. If you want some rep I'd be happy to accept an answer from you. Just post anything and I'll edit it to the solution I arrived at. –  Nov 16 '12 at 10:17
  • 3
    @Backlin one tiny tip: use results='asis' when you only want to show the figure and nothing else; it will make the knitr output cleaner – Yihui Xie Nov 16 '12 at 17:43
  • We'd like to keep answers separate from questions, so you should write a separate answer instead of editing your answer into the question. Self-answers are perfectly admissible, and a well-written answer may earn you additional reputation. – lockstep Nov 20 '12 at 10:04
  • Aye-aye! I tried that first, but the popup made me think editing my original questian was preferred by the community. – Backlin Nov 20 '12 at 10:12

1 Answers1

12

This is the answer I arrived at with the help of @baptiste and it works just like I wanted it to.

\begin{frame}
  \begin{columns}
    \begin{column}{.5\linewidth}
      Text
    \end{column}
    \begin{column}{.5\linewidth}
<<echo=FALSE,eval=TRUE,out.width='4cm',out.height='4cm'>>=
plot(1:10)
@
    \end{column}
  \end{columns}
\end{frame}
Backlin
  • 401