How to keep text vertically centered in table when adjusting row height?

So I wanted to shrink the row height of a table, but now the text is aligned to the bottom, so it touches horizontal lines below, while there is plenty of space above the text. Is there a way to change that? Thanks!

Hi there! Could you please provide the code for the table? It would clarify your problem and help us come up with a solution.

Sure. Here’s what I’m working with:


#set text(size: 8pt)

#figure(
  
  table(
    
    
    columns: (12),
    stroke: none,
    rows: (10pt),
    fill: (_, y) => if calc.odd(y) and y > 2 { rgb("EAF2F5") },
    
    
    
    table.hline(start: 0, y: 0),
    table.hline(start: 0, y: 3),
    table.hline(start: 0, y: 5),
    table.hline(start: 0, y: 6),
    table.hline(start: 0, y: 11),
  
    
    table.vline(x: 0, start: 0),
    table.vline(x: 1, start: 0),
    table.vline(x: 3, start: 0),
    table.vline(x: 7, start: 0),
    table.vline(x: 8, start: 0),
    table.vline(x: 9, start: 0),
    table.vline(x: 12, start: 0),

    
    [*Höhe*], table.cell(colspan: 2)[*Temperatur*], table.cell(colspan: 4)[*Druck*], [*Dichte*], [*Wichte*], table.cell(colspan: 3)[*Verhältniszahlen*], 

    [$h$], [$t$], [$T$], [N/$"m"^2$], [$p$], [], [], [$rho$], [$gamma$], [$T/T_n$], [$p/p_n$], [$gamma/gamma_n = rho/rho_n$],

    [km], [°C], [K], [Pa], [Torr], [at], [mbar], [kg/$"m"^3$], [N/$"m"^3$], [], [], [],

    [-0.2], [16.30], [289.46], [103750], [778.20], [1.05796], [1037.51], [1.2487], [12.246], [1.00451], [1.02394], [1.0193],

    [-0.1], [15.65], [288.81], [102532], [769.05], [1.04554], [1025.32], [1.2368], [12.129], [1.00226], [1.01191], [1.0094],

    [_0_], [_15.00_], [_288.16_], [_101325_], [_760.00_], [_1.03323_], [_1013.25_], [_1.2250_], [_12.013_], [_1.00000_], [_1.00000_], [_1.00000_],

    [0.1], [14.35], [287.51], [100130], [751.03], [1.02104], [1001.29], [1.2133], [11.898], [0.99774], [0.98820], [0.99043],
    
    [0.2], [13.70], [286.86], [98945], [742.15], [1.00896], [989.45], [1.2017], [11.785], [0.99549], [0.97651], [0.98094],

    [0.3], [13.05], [286.21], [97772], [733.35], [0.99700], [977.73], [1.1901], [11.671], [0.99323], [0.96494], [0.97151],

    [0.4], [12.40], [285.56], [96611], [724.64], [0.98516], [966.11], [1.1787], [11.559], [0.99097], [0.95348], [0.96216],

    [0.5], [11.75], [284.91], [95461], [716.01], [0.97343], [954.61], [1.1673], [11.447], [0.98872], [0.94213], [0.95287],

))

Oh, and just in case you know - is there a way to change font size within the table or figure environment only, withouth changing the size for the entire page?

You can set align to horizon to make the content vertically centered. And you can use a show-set rule to change the font size within the figure or table environment.

// use figure here if you also want to include the caption
#show table: set text(size: 8pt)

#figure(
  #table(
    columns: 12,
    stroke: none,
    align: horizon,
    rows: 10pt,
    fill: (_, y) => if calc.odd(y) and y > 2 { rgb("EAF2F5") },

    ..(0, 3, 5, 6, 11).map(y => table.hline(start: 0, y: y)),
    ..(0, 1, 3, 7, 8, 9, 12).map(x => table.vline(start: 0, x: x)),

    ...
  )
)

In general I would’ve also recommended you to pass a function to the property stroke instead of using table.hline() and table.vline(). But in your specific case this gets a bit weird due to the cell “Verhältniszahlen” that spans three columns. You can however clean up your table by creating the horizontal lines and vertical lines in a loop.

And if you would want the row height to always be compact relative to the font size, you can use rows: 1.25em instead of rows: 10pt.

1 Like

Thank you. Still trying to get used to the .map function, but you are right, that is way more elegant.