How can I set the font properties of text within a table?

I’m probably overlooking something simple (I’ve had about… 2 hours sleep) so apologies. But how do I tell Typst that the font size within a specific table should be smaller, for example?

I can’t see what parameter of table I would use. I’m guessing I need to be setting a parameter on something else, or creating a show rule, but it’s just not clicking.

Hi there, you can use a simple show-set rule on table.cell. And braces if needed to limit the scope.

#table(
  columns: 2,
  table.header[Amount][Ingredient],
  [360g], [Baking flour],
 // ... the remaining cells
)

#{
  show table.cell: set text(size: 14pt)

  table(
    columns: 2,
    table.header[Amount][Ingredient],
    [360g], [Baking flour],
   // ... the remaining cells
  )
}

See Table guide – Typst Documentation for more examples.

Edit: No need for a show-set rule if the table is alone in the code block:

Edit: As indicated by @Andrew, changing font size on a table changes block spacing. show table.cell is the proper way to achieve the desired output without changing block spacing.

4 Likes

Thank you, it was the combo of limiting the scope and the cell-based show rule I was missing.

1 Like

Apparently, changing font size on a table changes block spacing. Feels like a bug. So table.cell is actually the only correct way right now.

1 Like

Thanks @Andrew,

Is this a known documented issue or a new one?
Is there a difference between the following two blocks?

#let tbl = table(columns: 2,[a], [b],)

#{
  set text(size: 14pt)
  tbl
}

#{
  show table.cell: set text(size: 14pt)
  tbl

Using repr I can’t find one, same if looking at the output. But you must have seen something? Care to elaborate? Thanks,

I don’t know.

It’s pretty clear from How can I set the font properties of text within a table? - #2 by vmartel08, when changing the styling from one to another.

#let the-table = table[a]

#the-table
// #show table.cell: set text(size: 54pt)
#show table: set text(size: 54pt)
#the-table

That seems like just a consequence of block spacing being set in units of em. Just like table.inset is in units of em by default. (which is not true)

Sorry, but it’s really not clear to me… for me all 3 cases are equivalent (the 2nd case I didn’t suggest, but you did).

#let the-table = table[a]
#the-table
#let a = { //Case 1
  show table.cell: set text(size: 54pt)
  the-table
}
#let b = { //Case 2
  show table: set text(size: 54pt)
  the-table
}
#let c = { //Case 3
  set text(size: 54pt)
  the-table
}
#grid(columns:3,a,b,c,)

I do see the block spacing from the initial font size seem to differ after enlarging the font, but I fail to see why

Aren’t the 3 cases giving a similar result?

You can’t just change the layout and expect to produce the same result/bug.

#{
  table[a]
  show table.cell: set text(size: 54pt)
  // show table: set text(size: 54pt)
  // set text(size: 54pt)
  table[a]
}

Only first doesn’t increase vertical spacing.

They are equivalent, only the scope of set rule changes. If all tables should have same base font size, then the show-set rule works in global scope, but the set rule does not.

For a one-off I would probably have used

#{
  set text(size: 14pt)
  table()
}

But it increases spacing.

Changing font size can change table's block spacing · Issue #6490 · typst/typst · GitHub.

1 Like

I think the demonstration works well like this

#let the-table = table[a]
#let preceding = block(inset: 0.1em)[Preceding block]
#preceding
#the-table
#let a = { //Case 1
  preceding
  show table.cell: set text(size: 54pt)
  the-table
}
#let b = { //Case 2
  preceding
  show table: set text(size: 54pt)
  the-table
}
#let c = { //Case 3
  preceding
  set text(size: 54pt)
  the-table
}

#grid(columns:3,a,b,c,)
1 Like

Thank you very much @bluss and @Andrew, this makes much more sense now. I’ve edited my post suggesting the way to address the original problem to reflect this.

I would think that there is some logic/explanation behind each one of the cases as they all behave in a different way.

See Changing font size can change table's block spacing · Issue #6490 · typst/typst · GitHub.