Search code examples
rlatexkableextra

How to increase the underline thickness using kableExtra?


I need to apply underline some rows in a table, and I need to increase the thickness of the underline in order to make it easier to spot.

I tried with the LaTeX-commands below, without any success unfortunately.

\renewcommand{\ULthickness}{1.35pt}

table.tbl <- tibble(var1 = c("entry 1", "entry 2", " ", "entry 3", "entry 4", "entry 5"),
            var2 = c("2000", "1000", " ", "3000", "200", "500"),
            var3 = c("3000", "2000", " ", "4000", "100", "600"))

table.tbl %>%  
  kable("latex") %>% 
  row_spec(c(2), underline = T)

I want to be able to increase the thickness of the underline from the current thickness to something thicker.


Solution

  • The output of kable('latex') merely prints a tabular with the appropriate specifications from your data frame (or tibble). That means you have access to change the code before compiling it in LaTeX.

    With this in mind, add

    \usepackage{soul}
    % \setul{<depth>}{<thickness>}
    \setul{}{1.5pt}
    

    to your LaTeX preamble and substitute \ul for all the \underlines. Alternatively, you can update the \underline command to default to \ul using this:

    enter image description here

    \documentclass{article}
    
    \usepackage{soul}
    
    \let\underline\ul % Make \underline default to \ul from soul package
    
    % \setul{<depth>}{<thickness>}
    \setul{}{1.5pt}
    
    \begin{document}
    
    \begin{tabular}{ l | l | l }
      \hline
      var1 & var2 & var3 \\
      \hline
      entry 1 & 2000 & 3000 \\
      \hline
      \underline{entry 2} & \underline{1000} & \underline{2000}\\
      \hline
       &  & \\
      \hline
      entry 3 & 3000 & 4000 \\
      \hline
      entry 4 & 200 & 100 \\
      \hline
      entry 5 & 500 & 600 \\
      \hline
    \end{tabular}
    
    \end{document}
    

    The default thickness of the underline is .4pt.