title: R markdown pdf change caption's labels of side by side tabels
body: <p>Referring to this question:
  <a href="https://stackoverflow.com/questions/50879745/latex-kable-side-by-side-tables-not-in-outer-par-mode">latex kable side-by-side tables “Not in outer par mode”</a></p>
  
  <p>Following a small example from Peter's answer on the related question.</p>
  
  <pre><code>    ---
      title: "example"
      header-includes:
        \usepackage{subcaption}
        \usepackage{booktabs}
        \usepackage[table]{xcolor}
      ---
  
  
      ```{r start-block}
      library(dplyr)
      library(knitr)
      library(kableExtra)
      opts_chunk$set(echo = FALSE)
      ``` 
  
      Build two example tables based on the `mtcars` data set.
  
  
      ```{r sample, results='asis'}
      t1 &lt;- kable(head(mtcars)[1:3], format = "latex", booktabs = TRUE) %&gt;%  kable_styling(latex_options = c("striped"), font_size=5)
      t2 &lt;- kable(head(mtcars)[4:6], format = "latex", booktabs = TRUE) %&gt;% kable_styling(latex_options = c("striped"), font_size=5) 
      ```
  
      Modify the tables to use the `subtable` environment and added labels and
      captions.
  
      ```{r}
      t1 &lt;- gsub("\\begin{table}[H]", "\\begin{subtable}[b]{0.48\\linewidth}\n\\caption{\\label{tab:1a}This is Table 1 in the example, but now labeled with a (a).}\n", t1, fixed = TRUE)
      t1 &lt;- gsub("\\end{table}", "\\end{subtable}", t1, fixed = TRUE) 
  
      t2 &lt;- gsub("\\begin{table}[H]", "\\begin{subtable}[b]{0.48\\linewidth}\n\\caption{\\label{tab:1b}Shorter caption.}", t2, fixed = TRUE)
      t2 &lt;- gsub("\\end{table}", "\\end{subtable}", t2, fixed = TRUE) 
      ```
  
      Place the tables into the document.
  
      ```{r, results = "asis"}
      cat("",
          "\\begin{table}[!htb]",
          "\\centering",
          "\\caption{\\label{tab:tab1}Two tables, side-by-side.}",
          t1,
          t2,
          "\\end{table}",
          "",
          sep = "\n") 
      ```
  </code></pre>
  
  <p>I'm able to print two table side by side. What i would to do is to change the caption label of the two tables from "(a)" to "Table 1".
  I tried to change it directly form the string:</p>
  
  <pre><code>    ```{r}
      t1 &lt;- gsub("\\begin{table}[H]", "\\begin{subtable}[b]{0.48\\linewidth}\n\\caption{\\label{tab:Table 1}This is Table 1 in the example, but now labeled with a (a).}\n", t1, fixed = TRUE)
  
      t2 &lt;- gsub("\\begin{table}[H]", "\\begin{subtable}[b]{0.48\\linewidth}\n\\caption{\\label{tab:Table 2}Shorter caption.}", t2, fixed = TRUE)
      ```
  </code></pre>
  
  <p>But nothing change. 
  If I change the labels directly in the kable option with:</p>
  
  <pre><code>t1 &lt;- kable(head(mtcars)[1:3], format = "latex", booktabs = TRUE, labels="Table",caption="Test") %&gt;% 
   kable_styling(latex_options = c("striped"), font_size=5)
  
  </code></pre>
  
  <p>I get the error </p>
  
  <pre><code>! Package caption Error: \caption outside float.
  </code></pre>
  
  <p>because the Latex structure isn't correct.</p>
  
  <p>..any suggestion?</p>