0
votes

I am using knitr and kable to generate PDFs with R. The output I got has some special characters printed before/under table caption sample of the error. I found that if I drop "full_width" option in kable_styling, the string of characters disappears. The problem exisits for all my data frames. How can I fix it?

Thanks a lot!

LaTex packages I am using

\usepackage[margin=0.3in]{geometry}
\usepackage[hidelinks]{hyperref}
\usepackage{booktabs}
\usepackage{colortbl}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage[normalem]{ulem}
\usepackage[table]{xcolor}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage{makecell}
\usepackage{framed}

R packages I am using

library(knitr)
library(kableExtra)
library(readxl)
library(tidyr) 
library(dplyr)
library(tibble)
library(xtable)
library(WriteXLS)
library(stringr)
library(ggplot2)
library(lubridate) 
library(reshape2)
library(ggthemes) 
library(stats)
library(zoo)

Table specification

kable(df, "latex", longtable = T, booktabs = T, align = c("l","l","l"))%>%
  column_spec(1, width = "0em")%>%
  column_spec(2,width = "10em")%>%
  kable_styling(latex_options = c("striped", "repeat_header","scale_down"), full_width = T)%>%
  collapse_rows(columns = 1:2, latex_hline = "major", valign = "top", row_group_label_position = 'stack')
1

1 Answers

0
votes

I found that adding

\usepackage{caption}
\captionsetup{width=8in}

improves the output. Now if I have a table caption, it will fully cover the strange characters. But the position of the table caption is not centered as default sample of the error.Without a table caption, it still looks some like this.

It would be great if someone could offer some better solution.