0
votes

When I use kable to create a table in my Rnw file, the table outputs as expected. However when I include the caption, the table ceases to output at all. Below is my latex and sample knitr chunk.

\documentclass[titlepage]{article}

\usepackage{graphicx}

\usepackage[dvipsnames]{xcolor}

\usepackage{afterpage}

\usepackage{booktabs}

\usepackage{longtable}

\pagecolor{ForestGreen}\afterpage{\nopagecolor}

\color{white}

\title{%
  \noindent\makebox[\linewidth]{\rule{9cm}{0.9pt}}
  \huge \textbf{\textit{Key Distributor Report}}\\
  \LARGE \vspace{2mm} \textbf{\textit{A detailed quarterly review}} \\
  \noindent\makebox[\linewidth]{\rule{9cm}{0.9pt}}
  \vspace{6mm} \LARGE Macdonald Corp.} 

\pagenumbering{arabic}

\begin{document}

\maketitle

\color{black}

\newpage  

\tableofcontents

\newpage

\section{Overview of Key Distributors}

\section{Company A}

\subsection{National Overview}

\subsubsection{Account base structure}

<<
tester, echo=FALSE, message=FALSE, warning=FALSE,    results='asis',fig.height=3, fig.width=3, fig.align='center', eval=TRUE >>=

library(knitr)

kable(head(mtcars[,1:3]), booktabs=TRUE, caption='This is a caption')

@


\end{document}
1

1 Answers

0
votes

This seems to be a problem of coloring the texts. If you try to select all content in the pdf you realize, that the table is actually there, but the text is white. So simply change the way of coloring the title page (use \color on \maketitle instead of \title):

\documentclass[titlepage]{article}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{afterpage}
\usepackage{booktabs}
\usepackage{longtable}
\pagecolor{ForestGreen}\afterpage{\nopagecolor}

\title{%
  \noindent\makebox[\linewidth]{\rule{9cm}{0.9pt}}
  \huge \textbf{\textit{Key Distributor Report}}\\
  \LARGE \vspace{2mm} \textbf{\textit{A detailed quarterly review}} \\
  \noindent\makebox[\linewidth]{\rule{9cm}{0.9pt}}
  \vspace{6mm} \LARGE Macdonald Corp.} 

\pagenumbering{arabic}

\begin{document}

{\color{white}%
  \maketitle
}
\color{black}

\newpage  
\tableofcontents
\newpage

\section{Overview of Key Distributors}
\section{Company A}
\subsection{National Overview}
\subsubsection{Account base structure}


<<tester, echo=FALSE, message=FALSE, warning=FALSE,results='asis',fig.height=3, fig.width=3, fig.align='center', eval=TRUE >>=
library(knitr)
library(kableExtra)
library(dplyr)
kable(head(mtcars[,1:3]), booktabs=T, caption='This is a caption') %>%
kable_styling(latex_options = "hold_position")
@

\end{document}