[Tex/LaTex] Problem with verbatim in a beamer frame

beamerverbatim

It seems that verbatim is not working properly. It produce an error and the output is not as I expected. Here is the latex code

% !TEX encoding = UTF-8 Unicode
\documentclass{beamer}

\mode<presentation>
\usetheme{Madrid}
\setbeamercovered{transparent}

\usepackage{beamerthemesplit}
\usepackage[utf8]{inputenc}
\usepackage{graphics}
\usepackage{graphicx} 
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{natbib} 
\usepackage[turkish]{babel}
\usepackage{verbatim}
\AtBeginDocument{\catcode`==12 }

\begin{document}
\begin{frame}

\begin{verbatim}

Call:
glm(formula = propn.dead ~ conc, family = binomial(link = logit), 
    weights = number)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.5941  -0.3944   0.8329   1.2592   1.5940  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -60.717      5.181  -11.72   <2e-16 ***
conc          34.270      2.912   11.77   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 284.202  on 7  degrees of freedom
Residual deviance:  11.232  on 6  degrees of freedom
AIC: 41.43

Number of Fisher Scoring iterations: 4
\end{verbatim}
\end{frame}
\end{document}

enter image description here

Best Answer

The error is because you have to declare the frame as [fragile] due to the presence of verbatim code.

To get a good fit you can reduce the size of the font and you can use another font. To reduce the size of the font you can use \footnotesize or \scriptsize in the frame. If you add \usepackage[scaled]{beramono} to the preamble it will use the beramono font for the monospaced fonts used in verbatim. The beramono use less space than the default monospaced font.

Look the images below the difference.

Using default font and \footnotesize

enter image description here

Using Beramono font and \footnotesize

enter image description here

The Modified Code

Here is the code using beramono font and \footnotesize (produces the second image)

% !TEX encoding = UTF-8 Unicode
\documentclass{beamer}

\mode<presentation>
\usetheme{Madrid}
\setbeamercovered{transparent}

\usepackage{beamerthemesplit}
\usepackage[utf8]{inputenc}
\usepackage{graphics}
\usepackage{graphicx} 
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{natbib} 
\usepackage[turkish]{babel}
\usepackage{verbatim}
\AtBeginDocument{\catcode`==12 }

\usepackage[scaled]{beramono} %sets the beramono font. Just comment this line to get the default font back

\begin{document}
\begin{frame}[fragile]
\footnotesize %change the font size. You can \scriptsize to get a smaller font.
\begin{verbatim}
Call:
glm(formula = propn.dead ~ conc, family = binomial(link = logit), 
    weights = number)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.5941  -0.3944   0.8329   1.2592   1.5940  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -60.717      5.181  -11.72   <2e-16 ***
conc          34.270      2.912   11.77   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 284.202  on 7  degrees of freedom
Residual deviance:  11.232  on 6  degrees of freedom
AIC: 41.43

Number of Fisher Scoring iterations: 4
\end{verbatim}
\end{frame}
\end{document}

It´s a matter of your personal taste now. :-)

Related Question