Search code examples
latexknitrbeamer

How to resize an R code output on Beamer Latex


I would like to resize my R code output on Beamer Latex. I have something like :

\begin{frame}[fragile]
\frametitle{Application du modèle : contenu de lung}

<<echo=FALSE>>=
library(survival)
attach(lung)
head(lung)
@

\textbf{\underline{Objectif:}} construire un modèle qui vérifie les hypothèses de Cox 
à partir de ce jeu de données
\end{frame}

The problem is that the output table protrudes from the slide. Thanks.

Edit : also when i try to compile this part of code

\begin{frame}{Premier modèle naïf}
<<echo=FALSE, linebreaks=TRUE>>=
library(survival)
model_1<-coxph(Surv(time,status) ~ age+factor(sex)+ph.ecog+wt.loss, data = lung)
cox.zph(model_1)
@
\textbf{\underline{Objectif:}} construire un modèle qui vérifie les hypothèses de Cox à partir de ce jeu de données
\end{frame}

It looks like :

Problem


Solution

  • Internally this kniter thingy seems wrap the code in a custom environment called kframe. You can change the font size for this environment like this:

    \documentclass{beamer}
    
    \AtBeginEnvironment{kframe}{\tiny}
    
    \begin{document}
    
    \begin{frame}[fragile]
    \frametitle{Application du modèle : contenu de lung}
    
    <<echo=FALSE>>=
    library(survival)
    attach(lung)
    head(lung)
    @
    
    \textbf{\underline{Objectif:}} construire un modèle qui vérifie les hypothèses de Cox 
    à partir de ce jeu de données
    \end{frame}
    
    \end{document}
    

    enter image description here