Skip to content

Commit

Permalink
Add a visual test + finetune error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Aug 14, 2024
1 parent 143c915 commit fdbf80b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 5 deletions.
Binary file modified pkgdown/assets/gt-latex.pdf
Binary file not shown.
58 changes: 57 additions & 1 deletion pkgdown/assets/gt-latex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@

\title{LaTeX Quarto test}
\author{}
\date{2024-07-19}
\date{2024-08-14}

\begin{document}
\maketitle
Expand Down Expand Up @@ -284,6 +284,62 @@

\end{table}%

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{tab }\OtherTok{\textless{}{-}}\NormalTok{ exibble }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{gt}\NormalTok{(}\AttributeTok{rowname\_col =} \StringTok{"row"}\NormalTok{, }\AttributeTok{groupname\_col =} \StringTok{"group"}\NormalTok{, }\AttributeTok{row\_group\_as\_column =} \ConstantTok{TRUE}\NormalTok{) }\SpecialCharTok{|\textgreater{}}
\FunctionTok{tab\_spanner}\NormalTok{(}\StringTok{"spanners"}\NormalTok{, }\FunctionTok{c}\NormalTok{(char, num)) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{tab\_spanner}\NormalTok{(}\StringTok{"Second level spanners"}\NormalTok{, }\FunctionTok{c}\NormalTok{(char, num, fctr)) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{tab\_stubhead}\NormalTok{(}\StringTok{"Stubhead label"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{tab\_style}\NormalTok{(}
\AttributeTok{style =} \FunctionTok{list}\NormalTok{(}\FunctionTok{cell\_fill}\NormalTok{(}\StringTok{"\#f0f0f0"}\NormalTok{), }\FunctionTok{cell\_text}\NormalTok{(}\AttributeTok{weight =} \StringTok{"bold"}\NormalTok{)),}
\FunctionTok{cells\_stubhead}\NormalTok{()}
\NormalTok{ ) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{tab\_header}\NormalTok{(}\AttributeTok{title =} \StringTok{"Stubhead styling and multiple spanner levels"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{table}

\centering{

\caption*{
{\large Stubhead styling and multiple spanner levels}
}
\fontsize{12.0pt}{14.4pt}\selectfont
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l|l|lrcrrrr}
\toprule
\multicolumn{2}{l}{} & \multicolumn{3}{c}{Second level spanners} & & & & \\
\cmidrule(lr){3-5}
\multicolumn{2}{l}{} & \multicolumn{2}{c}{spanners} & & & & & \\
\cmidrule(lr){3-4}
\multicolumn{2}{c}{{\bfseries \cellcolor[HTML]{F0F0F0}{Stubhead label}}} & char & num & fctr & date & time & datetime & currency \\
\midrule\addlinespace[2.5pt]
\multirow{4}{*}{grp\_a} & row\_1 & apricot & 1.111e-01 & one & 2015-01-15 & 13:35 & 2018-01-01 02:22 & 49.950 \\
& row\_2 & banana & 2.222e+00 & two & 2015-02-15 & 14:40 & 2018-02-02 14:33 & 17.950 \\
& row\_3 & coconut & 3.333e+01 & three & 2015-03-15 & 15:45 & 2018-03-03 03:44 & 1.390 \\
& row\_4 & durian & 4.444e+02 & four & 2015-04-15 & 16:50 & 2018-04-04 15:55 & 65100.000 \\
\midrule\addlinespace[2.5pt]
\multirow{4}{*}{grp\_b} & row\_5 & NA & 5.550e+03 & five & 2015-05-15 & 17:55 & 2018-05-05 04:00 & 1325.810 \\
& row\_6 & fig & NA & six & 2015-06-15 & NA & 2018-06-06 16:11 & 13.255 \\
& row\_7 & grapefruit & 7.770e+05 & seven & NA & 19:10 & 2018-07-07 05:22 & NA \\
& row\_8 & honeydew & 8.880e+06 & eight & 2015-08-15 & 20:20 & NA & 0.440 \\
\bottomrule
\end{tabular*}

}

\caption{\label{tbl-spanner-stub}Stubhead styling and multiple spanner
levels}

\end{table}%

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# }\AlertTok{FIXME}\CommentTok{ Borders known not to be exact}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{tab }\OtherTok{\textless{}{-}}\NormalTok{ pizzaplace }\SpecialCharTok{\%\textgreater{}\%}
Expand Down
4 changes: 2 additions & 2 deletions scripts/visual-tests-latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ header_latex <- c(

if (length(table_titles) != n_chunks) {
cli::cli_abort(c(
"The structure is not respected. We have {n_chunks} examples, but {length(table_titles)}.",
"Each table should be labelled with #| label: and have a tab_header(title = \"\") title"
"The structure is not respected. We have {n_chunks} examples, but {length(table_titles)} actually detected.",
i = "Each table should be labelled with #| label: and have a tab_header(title = \"<title>\") title"
))
}

Expand Down
45 changes: 43 additions & 2 deletions vignettes/gt-visual.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,45 @@ tab <- exibble |>
) |>
tab_spanner(c(num, char), label = "A spanner") |>
tab_header(title = "background color")
```

::: panel-tabset
### html

```{r}
#| echo: false
tab
```

### interactive

```{r}
#| echo: false
opt_interactive(tab)
```

### plot

```{r}
#| echo: false
plot(tab)
```
:::

## Spanner and Stubhead {#sec-spanners-stub}

```{r}
#| label: spanner-stub
tab <- exibble %>%
gt(rowname_col = "row", groupname_col = "group", row_group_as_column = TRUE) |>
tab_spanner("spanners", c(char, num)) %>%
tab_spanner("Second level spanners", c(char, num, fctr)) %>%
tab_stubhead("Stubhead label") %>%
tab_style(
style = list(cell_fill("#f0f0f0"), cell_text(weight = "bold")),
cells_stubhead()
) %>%
tab_header(title = "Stubhead styling and multiple spanner levels")
```

::: panel-tabset
Expand All @@ -59,19 +97,22 @@ tab <- exibble |>
```{r}
#| echo: false
tab
# FIXME #1827
```

### interactive

```{r}
#| echo: false
#| warning: false
opt_interactive(tab)
# FIXME Borders known not to be exact
```

### plot

```{r}
#| echo: false
#| echo: false
plot(tab)
```
:::
Expand Down Expand Up @@ -141,7 +182,7 @@ opt_interactive(tab)
### plot

```{r}
#| echo: false
#| echo: false
plot(tab)
```
:::

0 comments on commit fdbf80b

Please sign in to comment.