Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tabularray as table format in LaTeX output #7475

Open
lvjr opened this issue Aug 5, 2021 · 36 comments
Open

Support tabularray as table format in LaTeX output #7475

lvjr opened this issue Aug 5, 2021 · 36 comments

Comments

@lvjr
Copy link

lvjr commented Aug 5, 2021

I have written a modern LaTeX3 pacakge tabularray for typesetting tabulars and arrays. And it would be nice if pandoc could support this package.

Similar to HTML+CSS, with this package, you can completely separate the styles from the contens of tables, and the styles of tables can be completely set in keyval way. Therefore it is easier to write converter for it.

image
image

Also, it is feature complete. It has builtin supports for table colors, dash lines, multiline cells, rowspan/colspan, X columns in tabularx and tabu packages, three part tables, long tables. The long tables can work in two column documents. And you can easily change a short table to long table by just adding a long option. ( The rowhead and rowfoot in the following example are similar to thead and tfoot in HTML.)

\begin{tblr}[long]{
 rowhead = 2, rowfoot = 1,
}
 Head    & Head  & Head    \\
 Head    & Head  & Head    \\
 Alpha   & Beta  & Gamma   \\
 Epsilon & Zeta  & Eta    \\
 Iota    & Kappa & Lambda \\
 Nu      & Xi    & Omicron \\
 Rho     & Sigma & Tau     \\
 Phi     & Chi   & Psi     \\
 Foot    & Foot  & Foot    \\
\end{tblr}

At last, there are h and f columns for vertically aligning cell text at row top and bottom, which most of LaTeX table packages don't support, but HTML/CSS and Microsoft Word natively support.

image

@mhwombat
Copy link
Contributor

mhwombat commented Jan 28, 2023

This package makes it much easier for users to customise the format of tables, globally or individually. And I think it might be easier for Pandoc as well.

For example, suppose we have the following table in markdown:

  Right     Left     Center     Default
-------     ------ ----------   -------
     12     12        12            12
    123     123       123          123
      1     1          1             1

For the above table, Pandoc currently generates the LaTeX code shown below.

\begin{longtable}[]{@{}rlcl@{}}
\toprule()
Right & Left & Center & Default \\
\midrule()
\endhead
12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\
1 & 1 & 1 & 1 \\
\bottomrule()
\end{longtable}

If instead we use tabularray, the LaTeX code that Pandoc generates would be much simpler.

\begin{tblr}[]{@{}rlcl@{}}
Right & Left & Center & Default \\
12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\
1 & 1 & 1 & 1 \\
\end{tblr}

Also, somewhere in the header Pandoc would put something like this, to set the default table format.

\SetTblrInner{
  hline{1} = {1pt, solid},
  hline{2} = {solid},
  hline{Z} = {solid},
}

The really cool thing is that users could change the formatting of each table
by inserting the appropriate formatting command as raw LaTeX.
You would still use Markdown syntax for the table itself.
For example, this table would have borders around all cells.

\SetTblrInner{
  hlines, vlines,
}

  Right     Left     Center     Default
-------     ------ ----------   -------
     12     12        12            12
    123     123       123          123
      1     1          1             1

@iandol
Copy link
Contributor

iandol commented Jan 29, 2023

@lvjr / @mhwombat — what, if any, are the downsides to this package? Would it just be the requirement of a modern TeX install?

@lvjr
Copy link
Author

lvjr commented Jan 29, 2023

@lvjr / @mhwombat — what, if any, are the downsides to this package? Would it just be the requirement of a modern TeX install?

@iandol tabularray is slower than longtable, but it only needs one compilation to get the result. It requires at least TeXLive 2020.

@mhwombat
Copy link
Contributor

I think it would be best to have a Pandoc command-line option / defaults file entry to choose between the table packages. For academic and traditional publishing, booktabs is still the best choice, and I would make it the default setting. It enforces good design principles, and it's simple to use (because a lot of decisions are made on your behalf).

In cases where you need more precise control (perhaps to apply corporate brand design standards, or just for creativity), tabularray would be the better option.

@jgunstone
Copy link

I would love to see this functionality -
tabularray is great for customisation of table output -
the attached example demonstrates how tabularray creates a well formatted long table in 2 column mode -
to my knowledge this would be impossible using the pandoc default of longtable

test2_1.pdf
image

@zwz
Copy link

zwz commented May 17, 2023

Really hope it will be supported soon.

@fsoedjede
Copy link

@lvjr have you written a lua filter doing the transformation from Pandoc table to LaTeX?
I would be interested if so.
Thanks

@JakeI
Copy link

JakeI commented Jul 22, 2023

EDIT: ⚠️ as far as I can tell this should work for versions 2.x.x (though it's only been tested on 2.9.2.1) for versions 3.x.x see my updated version below

@lvjr have you written a lua filter doing the transformation from Pandoc table to LaTeX? I would be interested if so. Thanks

You don't actually need a filter. Just add the following to the preamble of your latex template

$if(tables)$
\usepackage{tabularray}
\let\longtable\longtblr
\let\endlongtable\endlongtblr
\let\endhead\empty
\UseTblrLibrary{booktabs}
\NewTblrTheme{headless}{
    \DefTblrTemplate{contfoot-text}{default}{}
    \DefTblrTemplate{conthead-text}{default}{}
    \DefTblrTemplate{caption}{default}{}
    \DefTblrTemplate{conthead}{default}{}
    \DefTblrTemplate{capcont}{default}{}
}
\def\tabularnewline{\\}
\SetTblrOuter[longtblr]{
    expand=\tabularnewline,
    entry=none,
    label=none,
    theme=headless,
}
$endif$

This aliases pandocs preferred longtable environment to longtblr from tabularray.

It has to use the booktabs library to provide \toprule, \midrule, and \bottomrule. I'd prefer to define such rules using \SetTblrInner but unfortunate latex has no easy way to remove \bottomrule that leaves no token behind. Something like \let\bottomrule\empty won't work because the left over \empty appends an additional empty row to each table.

Applying the headless theme removes the caption that normally comes with longtblr.

The main drawbacks of this are:

  1. The template still doesn't get do decide if there should be a bottom rule (although one could probably try to set it to 0 width)
  2. This won't handle multi page tables with captions and labels
  3. Always using longtblr allows page page-breaks in tables with very view rows.
  4. EDIT: This won't handle table captions (in fact it will crash if there are any table captions in the document). Also see this comment below

Here is an example of how to apply styling to longtblr (as opposed to tblr). This should highlight headers, use zebra colors, and make all columns variable width.

\UseTblrLibrary{varwidth}
\SetTblrInner[longtblr]{
  row{1}   = {gray!20,valign=h},
  row{Z}   = {valign=f},
  row{odd} = {gray!5},
  hspan    = minimal,
  columns  = {co=1,valign=t},
}

@maikol-solis
Copy link

I just discovered tabularray and hope that Pandoc supports it by default. Best.

@jankap
Copy link

jankap commented Nov 27, 2023

Same here, tabularray seems to solve lots of table-related issues, e.g. long-living ones like #1023

@jankap
Copy link

jankap commented Nov 27, 2023

@lvjr have you written a lua filter doing the transformation from Pandoc table to LaTeX? I would be interested if so. Thanks

You don't actually need a filter. Just add the following to the preamble of your latex template

$if(tables)$
\usepackage{tabularray}
\let\longtable\longtblr
\let\endlongtable\endlongtblr
\let\endhead\empty
\UseTblrLibrary{booktabs}
\NewTblrTheme{headless}{
    \DefTblrTemplate{contfoot-text}{default}{}
    \DefTblrTemplate{conthead-text}{default}{}
    \DefTblrTemplate{caption}{default}{}
    \DefTblrTemplate{conthead}{default}{}
    \DefTblrTemplate{capcont}{default}{}
}
\def\tabularnewline{\\}
\SetTblrOuter[longtblr]{
    expand=\tabularnewline,
    entry=none,
    label=none,
    theme=headless,
}
$endif$

@JakeI nice snipped, thanks!

I tried to add this to the preamble, but the ifs seem not to be allowed there. I removed them - not sure if that's correct or not.

However, the aliasing seem to work, but Pandoc adds some \noalign commands:

| test | haha |
| ---- | ---- |
| 1    | 1    |
| 2    | 3    |

results in

\begin{longtable}[]{@{}ll@{}}
\toprule\noalign{}
test & haha \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
1 & 1 \\
2 & 3 \\
\end{longtable}

and the error is

! Misplaced \noalign.
\l_tmpa_tl ->\noalign
{} test
l.902 \end
{longtable}
?

When I remove all \noalign commands and \bottomrule\noalign command (looks like \bottomrule has an implicit \noalign) and add a \let\endlastfoot\empty to the preamble, it seems to work.

This compiles:

\begin{longtable}[]{@{}ll@{}}
\toprule
test & haha \\
\midrule
\endhead
\endlastfoot
1 & 1 \\
2 & 3 \\
\end{longtable}

Any idea whats going on with \noalign and \bottomrule? Right now, no Markdown -> Latex table work :)

I'm using TexLive 2023.

@JakeI
Copy link

JakeI commented Nov 28, 2023

Any idea whats going on with \noalign and \bottomrule?

@jankap Yes, I wrote my snippet for pandoc version 2.9.2.1 (that seams to be the latest version available through my package manager, however it's also 3 years old at this point). I should have mentioned the version number in my original description, sorry about that.

Pandoc adds some \noalign commands:

@jankap Yes, I can reproduced this in pandoc version 3.1.9 (build from the current main branch). Apparently the latex output changed and we have those \noaling commands now. The revision history for version 3.0 mentions the change in it's section about the LaTeX writer. I tried updating my original code for this version and here is what I came up with:

$if(tables)$
\usepackage{tabularray}
\let\longtable\longtblr
\let\endlongtable\endlongtblr
\NewTblrTheme{headless}{
    \DefTblrTemplate{contfoot-text}{default}{}
    \DefTblrTemplate{conthead-text}{default}{}
    \DefTblrTemplate{caption}{default}{}
    \DefTblrTemplate{conthead}{default}{}
    \DefTblrTemplate{capcont}{default}{}
}
\SetTblrOuter[longtblr]{
    entry=none,
    label=none,
    theme=headless,
}
\let\noalign\empty
\def\endlastfoot{\hspace{-2.5mm}} % compensate whitespace produced by left over \empty tokens
\let\endhead\empty
\def\toprule{\hspace{-1mm}} % compensate whitespace produced by left over \empty tokens
\let\midrule\empty
\let\bottomrule\empty
% add some optional styling
\UseTblrLibrary{varwidth}
\SetTblrInner[longtblr]{
  row{1}     = {gray!20,valign=h},
  hline{1,Z} = {0.3mm},
  hline{2}   = {0.1mm},
  row{Z}     = {valign=f},
  row{odd}   = {gray!5},
  hspan      = minimal,
  columns    = {co=1,valign=t},
}
$endif$

However this still uses a really dirty hack. Because redefining \noalign etc. as \empty still leaves tokens and I cannot find any easy ways to remove those, latex will still insert some whitespace before the actual cell content. The hack is using negative space to compensate for the unwanted space. Visually this looks fine, but it is not exactly a clean solution.

I tried to add this to the preamble, but the ifs seem not to be allowed there. I removed them - not sure if that's correct or not.

@jankap did you by any chance add this to a latex document class or package that that gets imported by your actual template? If so, simply dropping the $if(tables)$ and $endif$ was probably the thing to do and things should work normally. To me a pandoc template is a variation on the default template (run pandoc -D latex to print it). Pandoc templates are specified using the --template path/to/template.latex command line argument. $if(tables)$...$endif$ should work in pandoc templates. In fact the default already includes a $if(tables)$ section that you would replace by the snippet above. Anyway the purpose of the if-condition is preventing latex from loading tables related packages on documents that don't actually contain any tables. Other than slightly increased latex runtimes I see no harm in removing them.

@jankap
Copy link

jankap commented Nov 28, 2023

@JakeI
thank you very much!

Rigth now, that snipped does not work, but I can't find any missing brackets. The table is generated by Pandoc.

image

\documentclass{article}

\usepackage{cite}
\usepackage{amssymb,amsfonts}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{amsmath}
% \usepackage{subcaption}
% \usepackage{caption}
\usepackage{longtable}

\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

\usepackage{siunitx}


% % see https://github.com/lvjr/tabularray/discussions/396
\DefTblrTemplate{caption-sep}{default}{\par}
\DefTblrTemplate{caption}{default}{%
  \makebox[\tablewidth]{\parbox{\columnwidth}{%
    \UseTblrAlign{caption}%
    \UseTblrTemplate{caption-tag}{default}%
    \UseTblrTemplate{caption-sep}{default}%
    \UseTblrFont{caption-text}%
    \UseTblrTemplate{caption-text}{default}%
  }}%
}
\SetTblrStyle{caption}{halign=c}
\SetTblrStyle{caption-text}{font=\scshape}
\SetTblrStyle{note}{indent=\tabcolsep}

% added by Jan, see https://github.com/lvjr/tabularray/issues/268
% \DefTblrTemplate{firsthead}{default}{\addtocounter{table}{-1}\captionof{table}{\InsertTblrText{caption}}}

%% see https://github.com/jgm/pandoc/issues/7475#issuecomment-1829790171
% if we want to enable pandoc tables again...
% $if(tables)$
\usepackage{tabularray}
\let\longtable\longtblr
\let\endlongtable\endlongtblr
\NewTblrTheme{headless}{
    \DefTblrTemplate{contfoot-text}{default}{}
    \DefTblrTemplate{conthead-text}{default}{}
    \DefTblrTemplate{caption}{default}{}
    \DefTblrTemplate{conthead}{default}{}
    \DefTblrTemplate{capcont}{default}{}
}
\SetTblrOuter[longtblr]{
    entry=none,
    label=none,
    theme=headless,
}
\let\noalign\empty
\def\endlastfoot{\hspace{-2.5mm}} % compensate whitespace produced by left over \empty tokens
\let\endhead\empty
\def\toprule{\hspace{-1mm}} % compensate whitespace produced by left over \empty tokens
\let\midrule\empty
\let\bottomrule\empty
% add some optional styling
\UseTblrLibrary{varwidth}
\SetTblrInner[longtblr]{
  row{1}     = {gray!20,valign=h},
  hline{1,Z} = {0.3mm},
  hline{2}   = {0.1mm},
  row{Z}     = {valign=f},
  row{odd}   = {gray!5},
  hspan      = minimal,
  columns    = {co=1,valign=t},
}
% $endif$

\definecolor{abstractbg}{rgb}{0.89804,0.94510,0.83137}
\setlength{\fboxrule}{0pt}
\setlength{\fboxsep}{0pt}
\begin{document}
\title{Title}

\maketitle

% pandoc test (output from a md file)
\begin{longtable}[]{@{}ll@{}}
  \toprule\noalign{}
  test & haha \\
  \midrule\noalign{}
  \endhead
  \bottomrule\noalign{}
  \endlastfoot
  1 & 1 \\
  2 & 3 \\
  \end{longtable}
\end{document}

@JakeI
Copy link

JakeI commented Nov 28, 2023

@jankap that's odd, I cannot reproduce this. If I copy your example code and run pdflatex, or xelatex, or lualatex on it the expected pdf is produced. You seem to be using some sort of graphical development environment. Maybe you could try running latex directly? Maybe delete any .aux files etc. and run things from scratch?

I was using pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian)

@jankap
Copy link

jankap commented Dec 2, 2023

@JakeI very interesting. I can reproduce the error with pdflatex and lualatex.

I'm using a (self-built) Docker image, do you have Docker? You could try it on your own, e.g. by using https://hub.docker.com/r/pandoc/latex.

Copy the latex source below into a local file "test.tex". Then, run from this folder: docker run -it --rm -v ".:/data" --entrypoint '/bin/sh' pandoc/latex:3.1 -c "tlmgr install amsmath booktabs tabularray siunitx cite varwidth xcolor ninecolors && pdflatex test.tex", the error is still (and the pandoc container uses tex live 2022!)

LaTeX Warning: No \author given.

! Missing } inserted.
<inserted text>
                }
l.96   \end
           {longtable}
?

test.tex:

\documentclass{article}

\usepackage{cite}
\usepackage{amssymb,amsfonts}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{amsmath}
% \usepackage{subcaption}
% \usepackage{caption}
\usepackage{longtable}

\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

\usepackage{siunitx}


% % see https://github.com/lvjr/tabularray/discussions/396
\DefTblrTemplate{caption-sep}{default}{\par}
\DefTblrTemplate{caption}{default}{%
  \makebox[\tablewidth]{\parbox{\columnwidth}{%
    \UseTblrAlign{caption}%
    \UseTblrTemplate{caption-tag}{default}%
    \UseTblrTemplate{caption-sep}{default}%
    \UseTblrFont{caption-text}%
    \UseTblrTemplate{caption-text}{default}%
  }}%
}
\SetTblrStyle{caption}{halign=c}
\SetTblrStyle{caption-text}{font=\scshape}
\SetTblrStyle{note}{indent=\tabcolsep}

% added by Jan, see https://github.com/lvjr/tabularray/issues/268
% \DefTblrTemplate{firsthead}{default}{\addtocounter{table}{-1}\captionof{table}{\InsertTblrText{caption}}}

%% see https://github.com/jgm/pandoc/issues/7475#issuecomment-1829790171
% if we want to enable pandoc tables again...
% $if(tables)$
\usepackage{tabularray}
\let\longtable\longtblr
\let\endlongtable\endlongtblr
\NewTblrTheme{headless}{
    \DefTblrTemplate{contfoot-text}{default}{}
    \DefTblrTemplate{conthead-text}{default}{}
    \DefTblrTemplate{caption}{default}{}
    \DefTblrTemplate{conthead}{default}{}
    \DefTblrTemplate{capcont}{default}{}
}
\SetTblrOuter[longtblr]{
    entry=none,
    label=none,
    theme=headless,
}
\let\noalign\empty
\def\endlastfoot{\hspace{-2.5mm}} % compensate whitespace produced by left over \empty tokens
\let\endhead\empty
\def\toprule{\hspace{-1mm}} % compensate whitespace produced by left over \empty tokens
\let\midrule\empty
\let\bottomrule\empty
% add some optional styling
\UseTblrLibrary{varwidth}
\SetTblrInner[longtblr]{
  row{1}     = {gray!20,valign=h},
  hline{1,Z} = {0.3mm},
  hline{2}   = {0.1mm},
  row{Z}     = {valign=f},
  row{odd}   = {gray!5},
  hspan      = minimal,
  columns    = {co=1,valign=t},
}
% $endif$

\definecolor{abstractbg}{rgb}{0.89804,0.94510,0.83137}
\setlength{\fboxrule}{0pt}
\setlength{\fboxsep}{0pt}
\begin{document}
\title{Title}

\maketitle

% pandoc test (output from a md file)
\begin{longtable}[]{@{}ll@{}}
  \toprule\noalign{}
  test & haha \\
  \midrule\noalign{}
  \endhead
  \bottomrule\noalign{}
  \endlastfoot
  1 & 1 \\
  2 & 3 \\
  \end{longtable}
\end{document}

Some version infos of the container:

PS D:\OneDrive\Promotion> docker run -it --rm -v ".:/data"  --entrypoint '/bin/sh' pandoc/latex:3.1 -c "pdflatex -v"  
pdfTeX 3.141592653-2.6-1.40.24 (TeX Live 2022)                                           
kpathsea version 6.3.4
Copyright 2022 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.37; using libpng 1.6.37
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.03
PS D:\OneDrive\Promotion> 

@JakeI
Copy link

JakeI commented Dec 6, 2023

@jankap ok, so using docker I was able to reproduce this. This ! missing } error appears to show up if some exact combination of latex package version and latex version happen to be installed.

The fix is removing the \UseTblrLibrary{booktabs} line. That's a good idea anyway because pandoc 3 no longer generates \toprule, \midrule, and \bottomrule and the only job of the booktabs library is providing those.

@jankap
Copy link

jankap commented Dec 10, 2023

@JakeI Impressive find, thank you very much, I've tried lots of things and couldn't solve it :) Unfortunately, I'm using \cmidrule a lot for sub-tables. That's why I had to load booktabs. I'm looking for alternatives in tabularray though.

@zwz
Copy link

zwz commented Jan 20, 2024

@jankap ok, so using docker I was able to reproduce this. This ! missing } error appears to show up if some exact combination of latex package version and latex version happen to be installed.

The fix is removing the \UseTblrLibrary{booktabs} line. That's a good idea anyway because pandoc 3 no longer generates \toprule, \midrule, and \bottomrule and the only job of the booktabs library is providing those.

Thank you @JakeI for the useful code snippet.
But a table with a caption would result in error.
Do you have any idea to make it support captioned table?

@tytyvillus
Copy link

I think it would be best to have a Pandoc command-line option / defaults file entry to choose between the table packages. For academic and traditional publishing, booktabs is still the best choice, and I would make it the default setting. It enforces good design principles, and it's simple to use (because a lot of decisions are made on your behalf).

In cases where you need more precise control (perhaps to apply corporate brand design standards, or just for creativity), tabularray would be the better option.

I agree with @mhwombat, options would be much better, and booktabs should be the default — it's clean, simple, doesn't break anything, works in twocolumn, and overall has a great design philosophy.

(Currently desperately trying to find a workaround to get longtable to work in twocolumn.)

@yuki
Copy link

yuki commented Apr 20, 2024

Hello,

I have created a very basic Lua Filter for Pandoc that generates a table with Tabularray. There's a demo repository here https://github.com/yuki/pandoc-filter-tabularray

The main feature is that I parse the caption and if it has the key-value "tablename=XXX" the generated table has this value. So, if the Markdown file has:

| Head 1 | Head 2  | Head 3 | 
|:-------|:-------:|-------:|
| Alpha  | Beta    | Gamma  | 
| Delta  | Epsilon | Zeta   |
| Eta    | Theta   | Iota |

Table: Table content {tablename=yukitblr}

The output is:

\begin{yukitblr}[caption={Table content }]{X[l]X[c]X[r]}
Head 1 & Head 2 & Head 3 \\ 
Alpha & Beta & Gamma \\ 
Delta & Epsilon & Zeta \\ 
Eta & Theta & Iota \\ 
\end{yukitblr}

Of course, in the LaTeX template there must be setted the \NewTblrEnviron{yukitblr} in order to work. In the repository I have added a very basic LaTeX template with this custom environment.

I know that it's not the best option, but AFAIK there's no "a good way" to do this. And in this thread #6317 are talking about it. So yes, this is a hack that works for me 😄

The filter also admits HTML tables, which generates tabularray table, but right now the alignment is not working. Also there's an example in the repository.

I have used Tabularray in a very basic way in the last three years to create custom table-environments. So in order to convert my tables into Markdown (or HTML), this filter does the job for me.

PS: I'm not a Lua programmer, so the code can be very ugly and maybe not working in all scenarios.

@jgm
Copy link
Owner

jgm commented Oct 4, 2024

I've had a look at tabularray and it does look very good. Now that it's 2024 we might want to consider it.

I do like the nice-looking tables we currently get using booktabs, which has nice top, bottom, and mid-rules with good spacing and width defaults. I'm wondering whether the exact look of our current tables is reproducible using tabularray?

@mhwombat
Copy link
Contributor

mhwombat commented Oct 4, 2024

@jgm You probably could achieve the look of booktabs using tabularray. However, I wonder if it would be worth the effort. To my mind the two packages have different use cases. I use booktabs when I want to present columns of data (typically, but not always, numeric) in tabular format, and I don't need a lot of special formatting, I just want a professional result with minimal effort. I use tabularray when I want to arrange information (typically, but not always, plain text) in a grid, and I'm using colour, fontsize, and layout to make the story clearer.

So if I want to show some numerical results from an experiment in an academic paper, I go for booktabs. But for an architecture diagram, tabularray is my choice.

@jgm
Copy link
Owner

jgm commented Oct 4, 2024

One of the reasons to use tabularray would be that it offer support for tables that break over pages (like longtable), but unlike longtable it works in two-column mode. This addresses a frequent complaint about pandoc's table support (#1023).

It also sounds as if tabularray allows users to customize table styles globally in the preamble. This would allow users to choose a booktabs-like appearance or something with more lines (I think -- I'm not really familiar with tabularray except for a cursory look at the manual).

EDIT: and, to make this explicit, I'm not really interested in supporting multiple table packages; the idea would be to choose one to replace longtable which we currently use (in conjunction with booktabs for the horizontal rules)(.

@samcarter
Copy link

tabularray has a booktabs library. One can create equally nice tables with tabularray than with booktabs.

For a project like pandoc, I think tabularray would be particularly suited, because one can make all the settings regarding fonts, lines, colours either globally in the preamble, at the start of the table or within the cells. This means it would be very easy for pandoc to create document with a uniform style for tables.

@samcarter
Copy link

samcarter commented Oct 4, 2024

(one disadvantage of tabularray is that it is slow, in particular for very long tables. For the tex world, this can be a problem for overleaf users who's compilation might time out. I'm wondering if rstudio cloud users might also run into problems because of this)

@jgm
Copy link
Owner

jgm commented Oct 4, 2024

I'm curious; with tabularrray is it possible to adjust intercolumn spacing globally (e.g. to select whether you want the padding on the left and right of the table that is provided if @{} is not used in the column specifiers?)

As regards slowness: how slow are we talking, compared with longtable? Can this be quantified?

@samcarter
Copy link

You, you can make all these settings globally. I'll throw together a short example.

@samcarter
Copy link

@jgm Here a quick example which would change things like spacing and rules globally:

\documentclass{article}

\usepackage{tabularray}

\SetTblrInner{
  colsep=10pt,
  hline{1,Z}={1pt},
  hline{2}={0.5pt},
  column{1}={leftsep=0pt},
  column{Z}={rightsep=0pt}
  }



\begin{document}

\begin{tblr}{}
a & b & c\\
a & b & c\\
a & b & c\\
\end{tblr}

\end{document}

@samcarter
Copy link

As regards slowness: how slow are we talking, compared with longtable? Can this be quantified?

The people from overleaf might have some numbers on this. I'll ask somebody who might know...

@u-fischer
Copy link

u-fischer commented Oct 4, 2024

You should perhaps also consider accessibility: For tabular and longtable we have implemented tagging support but tabularray doesn't have that yet.

@samcarter
Copy link

@jgm Please see https://chat.stackexchange.com/transcript/message/66393443#66393443 for some statistics about the speed.

Many thanks to yo' from overleaf for providing them!

@jgm
Copy link
Owner

jgm commented Oct 4, 2024

@u-fischer good point. Where does tagging support get implemented? Would it be in the tabularray package itself? How much work would be required to add this?

@jgm
Copy link
Owner

jgm commented Oct 4, 2024

@samcarter - just looked at these numbers. Wow. I don't think we can switch with that kind of slowness.

@u-fischer
Copy link

@jgm tabulararray would have to add tagging support. We can not patch from the outside such a large package. I can not really say how much work it would be.

@jankap
Copy link

jankap commented Oct 5, 2024

@samcarter - just looked at these numbers. Wow. I don't think we can switch with that kind of slowness.

That's indeed weird. I can't confirm these numbers locally. I have a large document with many graphics and tables and it is always under 20 secs. I'll provide some concrete numbers.

Is overleaf that show?

@davidcarlisle
Copy link

I have a large document with many graphics and tables

tblr is typically a few hundred times slower than tabular but whether that makes a difference in practice depends on what else the document is doing. The overleaf test file intentionally just consists of tables to allow measurement with reasonably scaled times whereas a large document with tikz and png inserts and other things the time for tables may not be that significant.

A test I did a year ago or so which also just has tables is available at

https://www.overleaf.com/read/hcwysmssrwzx#6a76d1

It just consists of repeated copies of

\begin{table}[h]
\centering
\begin{mytblr}{
}
  & Description \\
  & 1 & 2 & 3 & 4 \\
  A & 10 & 20 & 30 & 40 \\
  B & 15 & 25 & 35 & 25 \\
  C & 12 & 22 & 32 & 80 \\
\end{mytblr}
\caption{Table 1}
\label{lbl1}
\end{table}

with 28 copies it gets a timeout error and no output on the free overleaf
above about 19 copies it works with a time warning from Overleaf that the limit is approaching.

That's actually quite a bit better than it was when I originally made the test as the limit was around 20 then (I think the package has optimised some of its slower parts, and overleaf has changed its servers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests