r - 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?

1 Answer

  1. Johnny- Reply

    2019-11-13

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>