Hi there,
how can I create a table with round edges (Edges with a radius like in the box oder the rect function)?
Hi there,
how can I create a table with round edges (Edges with a radius like in the box oder the rect function)?
The CeTZ Typst package should have the functionality you want—have a look at the rect
function with the radius attribute here.
It is worth noting that Typst’s rect
(Rectangle Function – Typst Documentation) and block
(Block Function – Typst Documentation) built-in elements also have a radius
parameter, rendering CeTZ unnecessary here.
This can be used to provide an outer outer stroke to a table, as follows:
#block(
// block will provide stroke with radius around the table
// we have to ensure the table doesn't fight it with its own stroke
stroke: black,
radius: 5pt,
table(
columns: 3,
stroke: (x, y) => (
// Only draw top stroke if we're beyond the first row
// Avoid conflicting with the outer block stroke
top: if y > 0 { black },
// Only draw left stroke if we're beyond the first column
// Avoid conflicting with the outer block stroke
left: if x > 0 { black }
// No bottom or right stroke so that cells at the last row
// or last column don't generate stroke conflicting with
// the block outer stroke
),
table.header([*Name*], [*Amount*], [*Location*]),
[Joseph], [5], [United States],
[Mary], [10], [Germany],
)
)
Note that we have to customize the table stroke to ensure it doesn’t conflict with the block’s outer stroke by disabling top and left stroke from cells at the first row and first column respectively, as well as disabling bottom and right stroke from all cells so that cells at the last row and at the last column respectively don’t override the outer block’s stroke at that position.
If you’d like radius for cells within the table, you’ll have to manually use #rect(radius: ...)
around your cells’ contents, which can be unwieldy at the moment (see How to make each grid cell take up all available space?).
Thank you for this solution.
Filling the header row or any row at tables border with some color is not possible, is it?
Try using clip:true
as a paramater of the block.
Yepp, this did work!
Thank you all.
Hmm,
compiling tables / blocks with round corners does consume so much more compiletime.
I am working a daily planer (currently 741 pages). When building normal tables, initial building is finished in about 63 seconds. When using blocks with round corners around tables (nothing else changed), the same document compiles about 600 seconds.
A bit difficult to tell what could be the cause without seeing the code, but you could try replacing clip: true
with having fill directly in the block if possible. I imagine clipping must be a bit more expensive.
ok, within all included documents, there are about 1.200 blocks with clip:true. I just search and replaced them with clip:false. First compilation time: 720 seconds. even more as with clip:true (I tested it again and it ran for 600 seconds at first compilation.
The tables (1.200) are more or less in this structure (most of them have more links, but die amount of links does not change):
#place(dy: -0cm, dx: 7.1cm,
block(
stroke: 0.2pt,
clip: true,
radius: 3pt,
table(
fill: (x, y) =>
if x == 0 or x == 6 or x == 7 or y==1 { silver },
columns: (0.45cm,0.45cm,0.45cm,0.45cm,0.45cm,0.45cm,0.45cm,0.45cm,),
inset: 2pt,
stroke: 0.2pt,
align: center,
table.header(
table.cell(colspan:8, fill: silver)[*Dezember*],
[*KW*],[*Mo*], [*Di*], [*Mi*], [*Do*], [*Fr*], [*Sa*], [*So*]
),
[48], [], [], [], [], [1], [2], [3],
[49], [4], [5], [6], [7], [8], [9], [10],
[50], [11], [12], [13], [14], [15], [16], [17],
[51], [18], [19], [20], [21], [22], [23], [24],
[52], [25], [26], [27], [28], [29], [30], [31],
)
)
The difference between the 600 seconds run an the 60 seconds run are
block(
stroke: 0.2pt,
clip: false,
radius: 3pt,
and the closing )
of cause.
Could it be the block itself? Even with
//clip:true,
the compiletime ist beyon 740 seconds (using typst 0.11.1 (50115102) with Windows 11)
Getting a 10x slowdown seems excessive. You could test 0.12.0-rc1 to see if it helps here (it also supports multi-threading with explicit #pagebreak
s).
I will try this the next few days.
I just compiled typst 0.12.0-rc1 (d5b1f4a6).
I do not know what you all did with 0.12., but the bulid time for my document is about 10 seconds (instead of 600-700 seconds).
Wow!