[Future Request] Providing a way to create your own variations of the `hline`/`vline` key
You can change the thickness, color, dashes, etc. of the ruled line, but the entire document uses only a fixed style of ruled line. It is tedious to specify the style each time using hline/vline.
So it's very useful to be able to define styles for these stylized ruled line.
Motivation
The booktabs library is an important library for creating beautiful tables, but to use this library you need to stick to the basic interfaces.
The tabularray package has the extra interface that separates table style and content, which I feel is a great strength, but the booktabs library interferes with this.
So having this feature (or a key option in the booktabs library) would be very useful, since it would allow you to focus on creating tables in the extra interfaces.
Expected usage
Possible practical examples are the following:
- Ruled lines provided by the booktabs library
- Double ruled line
I envision the following usage flow:
-
Construct a new table/inner key for ruled line using a definition command such as
\NewTblrHlineKey/\NewTblrVlineKey.%% ruled lines provided by the booktabs library: \NewTblrHlineKey{toprule}{ wd = 0.08em } \NewTblrHlineKey{bottomrule}{ wd = 0.08em } \NewTblrHlineKey{midrule}{ wd = 0.05em } \NewTblrHlineKey{cmidrule}{ wd = 0.03em, endpos } %% double ruled line: \NewTblrHlineKey{dbhline}{ %% Cannot be configured with current hline/inner keys. %% For example, it would be useful to have the following properties: repeat = 2, } -
With above configuration, it is assumed that you will use it as follows:
\begin{tblr}{ toprule{1}, bottomrule{Z}, midrule{3}, cmidrule{2} = {2-3}{} } %% only tabular contents \end{tblr}
Comparing the two interfaces
Configure the four keys in preamble as below:
\NewTblrHlineKey{toprule}{ wd = 0.08em }
\NewTblrHlineKey{bottomrule}{ wd = 0.08em }
\NewTblrHlineKey{midrule}{ wd = 0.05em }
\NewTblrHlineKey{cmidrule}{ wd = 0.03em, endpos }
This shows the difference between using the booktabs library and using the extra interface.
| booktabs library | Extra Interfaces |
|---|---|
|
|
| booktabs library | Extra Interfaces |
|---|---|
|
|
| booktabs library | Extra Interfaces |
|---|---|
|
|
| booktabs library | Extra Interfaces |
|---|---|
|
|
I warmly second this FR.
I'm wondering if \NewTblrHlineKey{toprule}{ wd = 0.08em } could be achieved with the experimental public key paths with something like:
\DeclareTblrKeys{hline/inner}{
toprule .code = {
hline{#1} = {wd = 0.08em}
}
}
But, if so, I couldn't make it work...
@dbitouze You can use \DeclareTblrKeys like this:
\documentclass{article}
\usepackage{tabularray}
\usepackage{ninecolors}
\DeclareTblrKeys{table/inner}{
toprule .meta:n = {
hline{#1} = {wd = 2pt, fg=purple3}
},
bottomrule .meta:n = {
hline{#1} = {wd = 2pt, fg=purple3}
},
midrule .meta:n = {
hline{#1} = {wd = 1pt, fg=blue3}
},
cmidrule .meta:n = {
hline{#1} = {1-2}{wd = 0.5pt, fg=teal3, lr, endpos},
hline{#1} = {3-4}{wd = 0.5pt, fg=teal3, lr, endpos}
},
}
\begin{document}
\begin{tblr}{
toprule = {1},
bottomrule = {Z},
midrule = {2},
cmidrule = {5}
}
Head & Head & Head & Head \\
Alpha & Beta & Gamma & Delta \\
Epsilon & Zeta & Eta & Theta \\
Iota & Kappa & Lambda & Mu \\
Alpha & Beta & Gamma & Delta \\
Epsilon & Zeta & Eta & Theta \\
Iota & Kappa & Lambda & Mu
\end{tblr}
\end{document}
Nice! But would it be possible, e.g. for toprule, to be able to receive keys just as row? It would be handy to be able to specify e.g.:
toprule{1} = {blue7}
And, then, what about providing these booktabs (the package) equivalents by booktabs (the library) ?
As a test, I implemented it in the following way so that I could create my own hline key.
-
\NewTblrHlineKeysaves the new key name and properties to\l__tblr_hline_special_prop -
In
\__tblr_table_special_key:nn:- Save
\l__tblr_key_split_name_stras\l__tblr_key_split_name_tl - If
\l__tblr_hline_special_prophas the same key as\l__tblr_key_split_name_str, change\l__tblr_key_split_name_strto "hline"
- Save
-
In
\tblr_set_hline:nnnn:- If
\l__tblr_key_split_name_tlis in\l__tblr_hline_special_prop, add the properties stored in\tblr_set_hline:nnn
- If
Specifically, it can be found in the following repository:
https://github.com/yarakos95/tabularray/blob/new-hline/vline-key/tabularray.sty
In this implementation, the toprule key etc. will be available by loading the booktabs library.