0

I have an R array output that I would like to include in a LaTeX beamer slide.

The array is simple enough

, , 1

       [,1] [,2] [,3] [,4] [,5]
 [1,]   NA   NA   NA   NA   NA
 [2,]   NA   NA   NA   NA   NA
 [3,]   NA   NA   NA   NA   NA
 [4,]   NA   NA   NA   NA   NA
 [5,]   NA   NA   NA   NA   NA
 [6,]   NA   NA   NA   NA   NA
 [7,]   NA   NA   NA   NA   NA
 [8,]   NA   NA   NA   NA   NA
 [9,]   NA   NA   NA   NA   NA
[10,]   NA   NA   NA   NA   NA

but seems a nightmare to format quickly and easily using the amsmath package and \begin{array}[cccccc] and \end{array}[cccccc].

Does someone know of a nice solution?

Any assistance is greatly appreciated.

1 Answers1

1

You can use the varbatim environment for data such as program outputs. Note that the beamer frame needs to be fragile for this environment.

The font size can be changed by patching \verbatim@font with etoolbox, as in https://tex.stackexchange.com/a/161713.

MWE:

\documentclass{beamer}
% optional font size setting for verbatim text, can be removed
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@verbatim}
  {\verbatim@font}
  {\verbatim@font\tiny}     % set font size here
  {}{}
\makeatother
% end of optional font size setting

\begin{document}
\begin{frame}[t,fragile]{50 tiny fragile top-aligned NAs}
\begin{verbatim}
       [,1] [,2] [,3] [,4] [,5]
 [1,]   NA   NA   NA   NA   NA
 [2,]   NA   NA   NA   NA   NA
 [3,]   NA   NA   NA   NA   NA
 [4,]   NA   NA   NA   NA   NA
 [5,]   NA   NA   NA   NA   NA
 [6,]   NA   NA   NA   NA   NA
 [7,]   NA   NA   NA   NA   NA
 [8,]   NA   NA   NA   NA   NA
 [9,]   NA   NA   NA   NA   NA
[10,]   NA   NA   NA   NA   NA
\end{verbatim}
\end{frame}
\end{document}

Result:

enter image description here

Note that for displaying source code (e.g., R scripts) it is usually preferred to use packages like listings or minted.

Marijn
  • 37,699