-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Comments
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:
For the above table, Pandoc currently generates the LaTeX code shown below.
If instead we use
Also, somewhere in the header Pandoc would put something like this, to set the default table format.
The really cool thing is that users could change the formatting of each table
|
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 would love to see this functionality - |
Really hope it will be supported soon. |
@lvjr have you written a lua filter doing the transformation from Pandoc table to LaTeX? |
EDIT:
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 It has to use the booktabs library to provide Applying the The main drawbacks of this are:
Here is an example of how to apply styling to \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},
} |
I just discovered |
Same here, |
@JakeI nice snipped, thanks! I tried to add this to the preamble, but the However, the aliasing seem to work, but Pandoc adds some
results in
and the error is
When I remove all This compiles:
Any idea whats going on with I'm using TexLive 2023. |
@jankap Yes, I wrote my snippet for pandoc version
@jankap Yes, I can reproduced this in pandoc version $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
@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 |
@JakeI Rigth now, that snipped does not work, but I can't find any missing brackets. The table is generated by Pandoc.
|
@jankap that's odd, I cannot reproduce this. If I copy your example code and run I was using |
@JakeI very interesting. I can reproduce the error with 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:
test.tex:
Some version infos of the container:
|
@jankap ok, so using docker I was able to reproduce this. This The fix is removing the |
@JakeI Impressive find, thank you very much, I've tried lots of things and couldn't solve it :) Unfortunately, I'm using |
Thank you @JakeI for the useful code snippet. |
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.) |
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:
The output is:
Of course, in the LaTeX template there must be setted the 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. |
I've had a look at I do like the nice-looking tables we currently get using |
@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. |
One of the reasons to use It also sounds as if 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 |
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. |
(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) |
I'm curious; with As regards slowness: how slow are we talking, compared with longtable? Can this be quantified? |
You, you can make all these settings globally. I'll throw together a short example. |
@jgm Here a quick example which would change things like spacing and rules globally:
|
The people from overleaf might have some numbers on this. I'll ask somebody who might know... |
You should perhaps also consider accessibility: For tabular and longtable we have implemented tagging support but tabularray doesn't have that yet. |
@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! |
@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? |
@samcarter - just looked at these numbers. Wow. I don't think we can switch with that kind of slowness. |
@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. |
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? |
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
with 28 copies it gets a timeout error and no output on the free overleaf 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) |
I have written a modern LaTeX3 pacakge
tabularray
for typesetting tabulars and arrays. And it would be nice ifpandoc
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.
Also, it is feature complete. It has builtin supports for table colors, dash lines, multiline cells, rowspan/colspan,
X
columns intabularx
andtabu
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 along
option. ( Therowhead
androwfoot
in the following example are similar tothead
andtfoot
in HTML.)At last, there are
h
andf
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.The text was updated successfully, but these errors were encountered: