Skip to content

More feature-complete export of tables: table.header(), table.hline(), and align()#50

Draft
andersjohansson wants to merge 2 commits into
jmpunkt:mainfrom
andersjohansson:table-header-and-hlines
Draft

More feature-complete export of tables: table.header(), table.hline(), and align()#50
andersjohansson wants to merge 2 commits into
jmpunkt:mainfrom
andersjohansson:table-header-and-hlines

Conversation

@andersjohansson

Copy link
Copy Markdown

table.header() is best practice in Typst for styling and accessibility

This uses org-export heuristics for determining rows that should go in
the header.

It also prints explicit table rules as table.hline(), but not the rule
at the bottom of the header and at the bottom of the table (it is
assumed that the user can use a default style for this).

Inspiration for this still simplified implementation from ox-html and ox-latex.

table.header() is best practice in Typst for styling and accessibility

This uses org-export heuristics for determining rows that should go in
the header.

It also prints explicit table rules as table.hline(), but not the rule
at the bottom of the header and at the bottom of the table (it is
assumed that the user can use a default style for this).

Inspiration for this still simplified implementation from ox-html and ox-latex.
@andersjohansson andersjohansson marked this pull request as draft February 21, 2026 17:55
@andersjohansson

Copy link
Copy Markdown
Author

I realize that tests should be updated if this is added.

By the way, my assumption that the user can style strokes appropriately is based on me hacking away on a standard style for “academic” tables (like booktabs in latex):

//Academic strokes:
#set table(stroke: (_, y) =>
(  top: if y==0 { 1pt } else if y==1 {0.5pt} else { 0pt },
    bottom:  1pt 
))
#set table.hline(stroke: .5pt)

But this actually doesn’t put a (thin) line below “the header”, just below the first row of the table. I am unsure if the header can be addressed directly.

https://typst.app/docs/guides/tables/
https://typst.app/docs/reference/model/table/

See also: https://typst.app/universe/package/akatable, which creates the new function academic-table. Exporting to that would perhaps lead to a similar mess like in ox-latex-table, with support for tabular, longtable, tabu, longtabu, etc.

@andersjohansson

Copy link
Copy Markdown
Author

I also realized it would be reasonable to set alignment based on the heuristics or explicit settings (alignment cookies, a row with ‘’, ‘’ or ‘’ for the columns) of org-mode.

I was inspired by how this is done in ox-html, where there is an option to set alignment per cell, which could possibly also be used for typst. I didn’t take that path here.

This is a quick implementation that “works on my file”, but the design needs to be considered, and tests written.

@andersjohansson andersjohansson changed the title Create table.header() and table.hline() when appropriate More feature-complete export of tables: table.header(), table.hline(), and align() Feb 22, 2026
@jmpunkt

jmpunkt commented May 2, 2026

Copy link
Copy Markdown
Owner

Sorry for taking so long to come back to you. I wonder what the use-cases are here. I think the first part which adds the table.header is fine and we should do that. But I am not sure if got the second part correctly. You want to use academic styled tables. So you applied this fix and you are using a custom style to archive that? The last part with the table alignment seems also fine.

The academic-table package seems to have a very similar style for their input as the current implementation. I wonder if we can have a feature flag which allows the user to use the different table exports. I guess that similar to what LaTeX does with their tables (as you mentioned with the longtabu, etc.).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants