haozhu233 / kableExtra

Construct Complex Table with knitr::kable() + pipe.

Home Page:https://haozhu233.github.io/kableExtra/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

latex: Keep using linesep when pack_rows is used

jobrachem opened this issue · comments

I think an example explains it best. Take the following minimal data frame:

df <- data.frame(Col1 = c("val1", "val2", "val3"), Col2 = c("val4", "val5", "val6"))

The following code yields the expected output

df |> kbl(format = "latex", linesep = c("\\addlinespace"))
% output of the R code above
\begin{tabular}[t]{l|l}
\hline
Col1 & Col2\\
\hline
val1 & val4\\
\addlinespace
val2 & val5\\
\addlinespace
val3 & val6\\
\hline
\end{tabular}

When I use pack_rows() however, the \addlinespace commands are omitted:

df |> kbl(format = "latex", linesep = c("\\addlinespace")) |> 
    pack_rows("Packed rows", 1, 2)
% output of the R code above
\begin{tabular}[t]{l|l}
\hline
Col1 & Col2\\
\hline
\multicolumn{2}{l}{\textbf{Packed rows}}\\
\hline
\hspace{1em}val1 & val4\\
\hspace{1em}val2 & val5\\
val3 & val6\\
\hline
\end{tabular}

However, in the table I am currently building, I would really like to add space between the rows within a group, not only between the groups of packed rows (which is possible using the argument latex_gap_space). So my desired output would allow for something like this:

% desired output
\begin{tabular}[t]{l|l}
\hline
Col1 & Col2\\
\hline
\multicolumn{2}{l}{\textbf{Packed rows}}\\
\hline
\hspace{1em}val1 & val4\\
\addlinespace % space between rows within a group
\hspace{1em}val2 & val5\\
\addlinespace % space between two groups
val3 & val6\\
\hline
\end{tabular}

If this is possible already, I apologize and would welcome a hint. Thank you so much for the awesome package! 😊