No indentation in footnote with kableExtra::kbl for latex output

Viewed 178

I am trying to remove the indention in the footnote section of a table created with kableExtra. I am assuming that the indention comes from the \item function that stands before the note begins (see latex output). Could anybody help to remove this indention resp. the \item prefix from the note?

library(dplyr)
library(kableExtra)

data(mtcars)
tab_data <- mtcars[1:5, 1:3]

cat(
  kbl(
    x = tab_data,
    format = "latex",
    booktabs = TRUE,
  ) %>%
    kable_styling(full_width = FALSE) %>%
    footnote(
      general = "Here is a note of the table. It is very long and I would want to remove this ugly indention on the left side of the table notes. ",
      general_title = "",
      threeparttable = TRUE
    )
)

Here the latex output:

\begin{table}
\centering
\begin{threeparttable}
\begin{tabular}[t]{lrrr}
\toprule
  & mpg & cyl & disp\\
\midrule
Mazda RX4 & 21.0 & 6 & 160\\
Mazda RX4 Wag & 21.0 & 6 & 160\\
Datsun 710 & 22.8 & 4 & 108\\
Hornet 4 Drive & 21.4 & 6 & 258\\
Hornet Sportabout & 18.7 & 8 & 360\\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item Here is a note of the table. It is very long and I would want to remove this ugly indention on the left side of the table notes. 
\end{tablenotes}
\end{threeparttable}
\end{table}

And a print sreen of the PDF and with the indention:

enter image description here

2 Answers

You could add footnote_as_chunk = T:

library(dplyr)
library(kableExtra)

data(mtcars)
tab_data <- mtcars[1:5, 1:3]

kbl(
    x = tab_data,
    format = "latex",
    booktabs = TRUE,
  ) %>%
    kable_styling(full_width = FALSE) %>%
    footnote(
      general = "Here is a note of the table. It is very long and I would want to remove this ugly indention on the left side of the table notes. ",
      general_title = "",
      threeparttable = TRUE,
      footnote_as_chunk = T
    )

-output

enter image description here

If you don't mind changing packages, you could use huxtable. You can then customize padding, borders etc. as you prefer:

library(huxtable)
tab_data <- cbind(model = rownames(tab_data), tab_data)
huxtable(tab_data) |> 
      set_width(0.5) |> 
      theme_article() |>
      add_footnote("Here is a note of the table. It is very long and I would want to remove this ugly indention on the left side of the table notes. ") |> 
      theme_
      set_left_padding(everywhere, 1, 0.1) # change 0.1 to whatever you prefer
      quick_pdf()

huxtable PDF output

One thing to be aware of: this simply adds a cell to the bottom of the table. It doesn't use a TeX footnote or tablenote.

Related