vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
211 stars 18 forks source link

Border in `group_tt()` groups doesn't extend to 100% of the width #235

Closed andrewheiss closed 7 months ago

andrewheiss commented 7 months ago

When adding a top or bottom border with style_tt() on a group label row, the border doesn't take up 100% of the row in LaTeX:

---
title: "Testing"
format: pdf
---

```{r}
library(tinytable)

tt(mtcars[1:10, 1:5]) |>
  group_tt(
    i = list(
      "Hello" = 3,
      "World" = 8),
    j = list(
      "Foo" = 2:3,
      "Bar" = 4:5)) |> 
  style_tt(
    i = c(3, 9), 
    background = "#e6e6e6",
    line = "bt", 
    line_width = 0.05
  )


![image](https://github.com/vincentarelbundock/tinytable/assets/73663/603008b3-2a08-4471-ac41-5eac3431ca70)

Everything's fine with HTML:

<img width="309" alt="image" src="https://github.com/vincentarelbundock/tinytable/assets/73663/4dd5c229-2f52-494f-a3a4-3f20ce71ec13">
vincentarelbundock commented 7 months ago

Interesting. I'm not sure what tabularray does for the end lines. I can just add 1 to the last j index, but that appears to make underlines stretch to far when the end position is not the last column. It's as if tabularray had a "hidden" last column.

For reference, here's the LaTeX code:

\begin{table}
\centering
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]Q[]},
cell{1}{2}={c=2,}{halign=c,},
cell{1}{4}={c=2,}{halign=c,},
cell{5}{1}={c=5}{},cell{11}{1}={c=5}{},
cell{3}{1}={preto={\hspace{1em}}},
cell{4}{1}={preto={\hspace{1em}}},
cell{6}{1}={preto={\hspace{1em}}},
cell{7}{1}={preto={\hspace{1em}}},
cell{8}{1}={preto={\hspace{1em}}},
cell{9}{1}={preto={\hspace{1em}}},
cell{10}{1}={preto={\hspace{1em}}},
cell{12}{1}={preto={\hspace{1em}}},
cell{13}{1}={preto={\hspace{1em}}},
cell{14}{1}={preto={\hspace{1em}}},
cell{15}{1}={preto={\hspace{1em}}},
row{5}={,bg=ce6e6e6,},
row{11}={,bg=ce6e6e6,},
hline{5,11,6,12}={1,2,3,4,5,6}{solid, 0.05em, black},
hline{8,9}={1,2,3,4,5}{solid, 0.05em, black},
}                     %% tabularray inner close
\tinytableDefineColor{ce6e6e6}{HTML}{e6e6e6}
\toprule
& Foo &  & Bar &  \\ \cmidrule[lr]{2-3}\cmidrule[lr]{4-5}
mpg & cyl & disp & hp & drat \\ \midrule %% TinyTableHeader
21.0 & 6 & 160.0 & 110 & 3.90 \\
21.0 & 6 & 160.0 & 110 & 3.90 \\
Hello &&&&& \\
22.8 & 4 & 108.0 &  93 & 3.85 \\
21.4 & 6 & 258.0 & 110 & 3.08 \\
18.7 & 8 & 360.0 & 175 & 3.15 \\
18.1 & 6 & 225.0 & 105 & 2.76 \\
14.3 & 8 & 360.0 & 245 & 3.21 \\
World &&&&& \\
24.4 & 4 & 146.7 &  62 & 3.69 \\
22.8 & 4 & 140.8 &  95 & 3.92 \\
19.2 & 6 & 167.6 & 123 & 3.92 \\
\bottomrule
\end{tblr}
\end{table} 
vincentarelbundock commented 7 months ago

The source of the problem was that group_tt() inserted an extraneous column in LaTeX.

Should be fixed on Github main.

Thanks for the report.