How to avoid that a large table footer widens the whole table?

If you want a non-expanding cell feature, then you should open an issue.

Using the same hack as in How to distribute column widths equally for specific rows in a table? - #4 by Andrew, it’s not that hard to make it work:

#set page(margin: 1cm)

#let make-label(counter, alignment, n: auto) = {
  assert(alignment in (left, right))
  let counter-name = repr(counter).split("\"").at(1)
  let alignment-str = repr(alignment)
  let n = if n == auto { str(counter.get().first()) } else { str(n) }
  label(counter-name + "." + n + "." + alignment-str)
}

#let cell-counter = counter("cell-counter")

#let pin-corner(counter, alignment) = context {
  place(alignment)[#metadata(none)#make-label(counter, alignment)]
}

#let pin-left-right(counter) = {
  pin-corner(counter, left)
  pin-corner(counter, right)
}

#let mark-cell(counter, body, ..args) = table.cell(
  ..args,
  counter.step() + pin-left-right(counter) + body,
)

#let get-pinned-left-right-x(counter) = {
  let cell-inset = if table.cell.inset == auto { 5pt } else { cell.inset }
  let adjusted-position(pos) = (pos.x - page.margin, pos.y - page.margin)
  let n = counter.get().first()
  let (left, right) = (left, right).map(alignment => {
    adjusted-position(locate(make-label(counter, alignment, n: n)).position())
  })
  (left.first(), right.first())
}

#let non-expanding-cell(body, ..args) = {
  mark-cell(cell-counter, ..args, context {
    let (x1, x2) = get-pinned-left-right-x(cell-counter)
    block(width: x2 - x1, body)
  })
}

Basically the same thing, but instead of Y axis you work with X axis.

#table(
  rows: 3,
  columns: 5,
  column-gutter: 0.25em,
  align: center,
  stroke: none,
  table.hline(),
  [A1], [B1], [C1], [D1], [E1],
  [A2], [B2], [C2], [D2], [E2],
  [A3], [B3], [C3], [D3], [E3],
  table.hline(),
  non-expanding-cell(align: left, colspan: 5, text(0.8em, lorem(15)))
)

image

Full example
#set page(margin: 1cm)

#let make-label(counter, alignment, n: auto) = {
  assert(alignment in (left, right))
  let counter-name = repr(counter).split("\"").at(1)
  let alignment-str = repr(alignment)
  let n = if n == auto { str(counter.get().first()) } else { str(n) }
  label(counter-name + "." + n + "." + alignment-str)
}

#let cell-counter = counter("cell-counter")

#let pin-corner(counter, alignment) = context {
  place(alignment)[#metadata(none)#make-label(counter, alignment)]
}

#let pin-left-right(counter) = {
  pin-corner(counter, left)
  pin-corner(counter, right)
}

#let mark-cell(counter, body, ..args) = table.cell(
  ..args,
  counter.step() + pin-left-right(counter) + body,
)

#let get-pinned-left-right-x(counter) = {
  let cell-inset = if table.cell.inset == auto { 5pt } else { cell.inset }
  let adjusted-position(pos) = (pos.x - page.margin, pos.y - page.margin)
  let n = counter.get().first()
  let (left, right) = (left, right).map(alignment => {
    adjusted-position(locate(make-label(counter, alignment, n: n)).position())
  })
  (left.first(), right.first())
}

#let non-expanding-cell(body, ..args) = {
  mark-cell(cell-counter, ..args, context {
    let (x1, x2) = get-pinned-left-right-x(cell-counter)
    block(width: x2 - x1, body)
  })
}

#table(
  rows: 3,
  columns: 5,
  column-gutter: 0.25em,
  align: center,
  stroke: none,
  table.hline(),
  [A1], [B1], [C1], [D1], [E1],
  [A2], [B2], [C2], [D2], [E2],
  [A3], [B3], [C3], [D3], [E3],
  table.hline(),
  non-expanding-cell(align: left, colspan: 5, text(0.8em, lorem(15)))
)
3 Likes