Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop table disappearing off end of page with stargazer

I have a .Rnw file that looks like this:

\documentclass[a4paper,11pt]{article}
\begin{document}
\title{}
\author{me}
\date{\today}
\maketitle

\section{Header}

<<table_mtcars, results = "asis">>=

stargazer(rbind(mtcars, mtcars, mtcars), summary = F)

@
\FloatBarrier

\end{document}

I can use knitr::knit to produce a .tex file and then convert this to a PDF. The resultant PDF looks like this:

enter image description here

Note how the table disappears off the end of page 2 and doesnt resurface on page 3. How can I get the table to continue on page 3 of the PDF using stargazer?

like image 349
luciano Avatar asked Feb 20 '14 09:02

luciano


1 Answers

As far as I know this is not currently supported by stargazer. I would recommend emailing the developer, who is usually very open to suggestions. The issue is that you need to use LaTeX's longtable environment instead of tabular, but this is the part that Stargazer doesn't seem to support.

You can create a workaround by doing:

\documentclass[a4paper,11pt]{article}
\usepackage{longtable}
\begin{document}
\title{}
\author{me}
\date{\today}
\maketitle

\section{Header}

\Sexpr{library(knitr);gsub('tabular','longtable',knit(text="<<results = 'asis'>>=\nlibrary(stargazer)\nstargazer(rbind(mtcars, mtcars, mtcars), summary = FALSE, float = FALSE)\n@"))}

\end{document}

Basically, you're calling knitr within your .Rnw file in order to build the table, and gsub the tabular environment to longtable. When I run this, it comes out as three pages long.

like image 111
Thomas Avatar answered Oct 17 '22 23:10

Thomas