标题不显示表格

时间:2018-03-13 19:14:00

标签: knitr sweave kable

当我使用kable在我的Rnw文件中创建表时,表按预期输出。但是当我包含标题时,表格根本不再输出。下面是我的乳胶和样品编织块。

\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 个答案:

答案 0 :(得分:0)

这似乎是为文本着色的问题。如果您尝试选择您认识到的pdf中的所有内容,表格实际上就在那里,但文本是白色的。因此,只需更改标题页的着色方式(使用\color上的\maketitle代替\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}