title: Issues getting pdf from latex code generated by kable() in r markdown environment
body: <p>I am trying to get a pdf document including a conditionally formatted table using kable() and kable_styling) as described here : <a href="https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html</a>.</p>
  
  <p>I encounter errors when I do so (see code). It seems that the Latex code generated by kable() is the cause.</p>
  
  <p>Attached to this post you can find : </p>
  
  <ul>
  <li><p>a r markdown code that creates the html file</p></li>
  <li><p>a r markdown code that should create the same document as the HTML code but in .pdf</p></li>
  </ul>
  
  <p>Here is the table I would like to get in a pdf document : <a href="https://i.stack.imgur.com/mojNa.jpg" rel="nofollow noreferrer">https://i.stack.imgur.com/mojNa.jpg</a></p>
  
  <pre><code>---
  title: "testhtml"
  output:
    pdf_document:
      fig_caption: yes
      highlight: tango
      number_sections: yes
      toc: yes
    html_document:
      number_sections: yes
      theme: united
      toc: yes
  ---
  
  ```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = FALSE)
  ```
  
  ```{r}
  if (!require(tidyverse)) {install.packages("tidyverse")}
  library(tidyverse)
  if (!require(knitr)) {install.packages("knitr")}
  library(knitr)
  if (!require(kableExtra)) {install.packages("kableExtra")}
  library(kableExtra)
  if (!require(tinytex)) {install.packages("tinytex")}
  library(tinytex)
  #Data sample
  risque_alpha = 0.05
  synthese_ex &lt;- structure(list(campagne = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
                                                       1L, 1L, 1L, 1L), .Label = "2017", class = "factor"), 
                                prelevement = structure(c(1509667200, 1509667200, 1509667200, 1509667200, 1509667200, 1509667200,
                                                          1504483200, 1504483200, 1504483200, 1504483200), class = c("POSIXct", "POSIXt"),
                                                        tzone = "UTC"), 
                                profondeur = c("-110", "-90", "-70", "-50", "-30", "-10", "-110", "-90", "-70", "-50"), 
                                test_applique = c("ANOVA","Kruskal-Wallis", "ANOVA", "ANOVA", "ANOVA", "ANOVA", "ANOVA", "Kruskal-Wallis",
                                                  "Kruskal-Wallis", "Kruskal-Wallis"),
                                p_value_test = c(0.2691, 0.16966, 0.29958, 0.25323, 8e-05, 0.00214, 0.70138, 0.45697, 0.69763, 0.65208)),
                           row.names = 2:11, class = "data.frame")
  #conditional formatting
  options(knitr.table.format = "html") # ....................... for pdf this causes a prolem!?
  tab_synthese &lt;- synthese_ex %&gt;% mutate(p_value_test = cell_spec(p_value_test, color = ifelse(p_value_test &lt; risque_alpha, "green","red"))) %&gt;% kable(escape = FALSE, booktabs = T, linesep = "") %&gt;% kable_styling("striped", full_width = F)
  tab_synthese
  ```
  </code></pre>
  
  <p>If run the Rmd above as html you get</p>
  
  <blockquote>
    <p>Fehler: Functions that produce HTML output found in document targeting
    latex output. Please change the output type of this document to HTML.
    Alternatively, you can allow HTML output in non-HTML formats by adding
    this option to the YAML front-matter of your rmarkdown file:
      always_allow_html: yes
    Note however that the HTML output will not be visible in non-HTML
    formats.
    Ausführung angehalten</p>
  </blockquote>
  
  <h1>Code to generate the pdf error :</h1>
  
  <pre><code>---
  title: "testpdf"
  output:
    pdf_document:
      fig_caption: yes
      highlight: tango
      number_sections: yes
      toc: yes
    html_document:
      number_sections: yes
      theme: united
      toc: yes
  #always_allow_html: yes
  ---
  
  ```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = FALSE)
  ```
  
  ```{r}
  if (!require(tidyverse)) {install.packages("tidyverse")}
  library(tidyverse)
  if (!require(knitr)) {install.packages("knitr")}
  library(knitr)
  if (!require(kableExtra)) {install.packages("kableExtra")}
  library(kableExtra)
  if (!require(tinytex)) {install.packages("tinytex")}
  library(tinytex)
  #Data sample
  risque_alpha = 0.05
  synthese_ex &lt;- structure(list(campagne = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
                                                       1L, 1L, 1L, 1L), .Label = "2017", class = "factor"), 
                                prelevement = structure(c(1509667200, 1509667200, 1509667200, 1509667200, 1509667200, 1509667200,
                                                          1504483200, 1504483200, 1504483200, 1504483200), class = c("POSIXct", "POSIXt"),
                                                        tzone = "UTC"), 
                                profondeur = c("-110", "-90", "-70", "-50", "-30", "-10", "-110", "-90", "-70", "-50"), 
                                test_applique = c("ANOVA","Kruskal-Wallis", "ANOVA", "ANOVA", "ANOVA", "ANOVA", "ANOVA", "Kruskal-Wallis",
                                                  "Kruskal-Wallis", "Kruskal-Wallis"),
                                p_value_test = c(0.2691, 0.16966, 0.29958, 0.25323, 8e-05, 0.00214, 0.70138, 0.45697, 0.69763, 0.65208)),
                           row.names = 2:11, class = "data.frame")
  #conditional formatting
  options(knitr.table.format = "latex") # ....................... for pdf this causes a prolem!
  tab_synthese &lt;- synthese_ex %&gt;% mutate(p_value_test = cell_spec(p_value_test, color = ifelse(p_value_test &lt; risque_alpha, "green","red"))) %&gt;% kable(escape = FALSE, booktabs = T, linesep = "") %&gt;% kable_styling("striped", full_width = F)
  tab_synthese
  ```
  </code></pre>
  
  <h1>Code to generate something very close to the targetted document</h1>
  
  <p>It seems that the problem comes from the <code>kable_styling()</code> function. Please note that the <code>options(knitr.table.format = "")</code> part has been removed and replace by <code>format = "pandoc"</code> in the <code>kable()</code> function.</p>
  
  <pre><code>---
  title: "testpdf"
  output:
    pdf_document:
      fig_caption: yes
      highlight: tango
      number_sections: yes
      toc: yes
    html_document:
      number_sections: yes
      theme: united
      toc: yes
  always_allow_html: yes
  ---
  
  ```{r setup, include=FALSE}
  knitr::opts_chunk$set(echo = FALSE)
  ```
  
  ```{r}
  if (!require(tidyverse)) {install.packages("tidyverse")}
  library(tidyverse)
  if (!require(knitr)) {install.packages("knitr")}
  library(knitr)
  if (!require(kableExtra)) {install.packages("kableExtra")}
  library(kableExtra)
  if (!require(tinytex)) {install.packages("tinytex")}
  library(tinytex)
  #Data sample
  risque_alpha = 0.05
  synthese_ex &lt;- structure(list(campagne = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
                                                       1L, 1L, 1L, 1L), .Label = "2017", class = "factor"), 
                                prelevement = structure(c(1509667200, 1509667200, 1509667200, 1509667200, 1509667200, 1509667200,
                                                          1504483200, 1504483200, 1504483200, 1504483200), class = c("POSIXct", "POSIXt"),
                                                        tzone = "UTC"), 
                                profondeur = c("-110", "-90", "-70", "-50", "-30", "-10", "-110", "-90", "-70", "-50"), 
                                test_applique = c("ANOVA","Kruskal-Wallis", "ANOVA", "ANOVA", "ANOVA", "ANOVA", "ANOVA", "Kruskal-Wallis",
                                                  "Kruskal-Wallis", "Kruskal-Wallis"),
                                p_value_test = c(0.2691, 0.16966, 0.29958, 0.25323, 8e-05, 0.00214, 0.70138, 0.45697, 0.69763, 0.65208)),
                           row.names = 2:11, class = "data.frame")
  #conditional formatting
  tab_synthese &lt;- synthese_ex %&gt;% mutate(p_value_test = cell_spec(p_value_test, color = ifelse(p_value_test &lt; risque_alpha, "green","red"))) %&gt;% kable(format = "pandoc", escape = FALSE, booktabs = T, linesep = "") %&gt;% kable_styling( "striped", full_width = F)
  tab_synthese
  `
  </code></pre>
  
  <p>``</p>