#Footnotes in tables?

32 messages · Page 1 of 1 (latest)

lapis abyss
#

How can I set up notes and footnotes for a table so that they appear immediately below the table and not at the bottom of the page? The way you do it (at least that's how I do it) in LaTex with a minipage environment. You could set up a separate line for notes, but for footnotes it's very cumbersome.

Sorry if this is a trivial question, but as a beginner I couldn't find a solution.

cedar robin
#

Maybe with a figure?

#

?r #figure(table(columns: 2, [a], [b], [c], [d]), caption: [A table with letters])

lapis abyss
lapis abyss
cedar robin
#

Hmm, well I guess you could always create a block containing the table and the note

#

?r #block(breakable: false, [#align(center, table(columns: 2, [a], [b], [c], [d])) #align(center)[_This is a note_] ])

lapis abyss
#

ok. I will try that. I thought #figure() would create a block implicitely.

cedar robin
#

I think it does

#

But I'm not sure if there's a way to also add notes to a figure like you've described them

#

You could create a function to simplify the process, hold on

lapis abyss
#

Then footnotes are ignoring the block. That's maeningfull for normal writing, but not for footnotes in tables.

cedar robin
#

I'm not sure I understand

lapis abyss
#

did you see the examples on the apa site?

cedar robin
#

Ah alright, I see now

stark hollow
#

Do you want the numbering of the footnote to be automatic or is it ok to number and place them manually?

lapis abyss
#

Of course I want it to be automatic 😉 We all want that.... But a manual workaround will help, eventually

stark hollow
# lapis abyss Of course I want it to be automatic 😉 We all want that.... But a manual workaro...

?r ```rs
#set par(justify: true)

#let table-footnote-counter-marker = counter("table-footnote-counter-marker")
#let table-footnote-counter-content = counter("table-footnote-counter-content")
#let table-footnote-counter-table = counter("table-footnote-counter-table")

#show table: it => {
table-footnote-counter-marker.update(0)
table-footnote-counter-content.update(0)
table-footnote-counter-table.step()
it
}

#let table-numbering-pattern = "a"
#let table-footnote-label = "table-footnote"
#let table-footnote-marker() = {
table-footnote-counter-marker.step()
context {
let table-counter = table-footnote-counter-table.get().first()
let counter = table-footnote-counter-marker.get().first()
link(label(table-footnote-label + "-" + str(table-counter) + "-" + str(counter)), super(numbering(table-numbering-pattern, counter)))
}
}

#let table-footnote-content(content) = {
table-footnote-counter-content.step()
context {
let table-counter = table-footnote-counter-table.get().first()
let counter = table-footnote-counter-content.get().first()
let number = super(numbering(table-numbering-pattern, counter))
align(left)[#number #content #label(table-footnote-label + "-" + str(table-counter) + "-" + str(counter))]
}
}

#set figure.caption(position: top)

#figure(
[#table(
columns: 2,
[a#table-footnote-marker()], [b],
[c#table-footnote-marker()], [d]
)
#table-footnote-content(lorem(30))
#table-footnote-content(lorem(10))
],
caption: [A table with letters]
)

stark hollow
#

This is mostly manual, but at least one doens't have to adjust the numbering by hand

#

I updated it to link to the footnotes

#

This also prevents you from accidentally creating a marker without content, but not the other way round

lapis abyss
#

Thank you. I will try that (and try to understand it)! Unfortunately, it seems not be very easy. It is difficult to suggest Typst to my students ... (That's why, I didn't recommend LaTex)

upbeat wing
#

?r

#let table-footnote-counter-footnote = counter("table-footnote-counter-footnote")
#let table-footnote-state-footnotes = state("table-footnote-state-footnotes", ())
#let table-footnote-counter-table = counter("table-footnote-counter-table")

#let table-numbering-pattern = "a"
#let table-footnote-label = "table-footnote"
#show table: it => {
  table-footnote-counter-footnote.update(0)
  table-footnote-state-footnotes.update(())
  table-footnote-counter-table.step()
  
  show footnote: it => {
    table-footnote-counter-footnote.step()
    context {
      let footnote-counter = table-footnote-counter-footnote.get().first()
      let state-footnotes = table-footnote-state-footnotes.get()
      let table-counter = table-footnote-counter-table.get().first()
  
      let base-label = table-footnote-label + "-" + str(table-counter) + "-" + str(footnote-counter)
      let marker-label = label(base-label + "-marker")
      let footnote-label = label(base-label + "-footnote")
      let footnote-numbering = super(numbering(table-numbering-pattern, footnote-counter))
      let footnote-body = it.body
  
      let new-state = (marker-label, footnote-label, footnote-numbering, footnote-body)
      table-footnote-state-footnotes.update((..state-footnotes, new-state))
      
      [#link(footnote-label, footnote-numbering) #marker-label]
    }
  }
  
  it

  context {
    let footnotes = table-footnote-state-footnotes.get()
    for (marker-label, footnote-label, footnote-numbering, footnote-body) in footnotes {
      align(left)[
        #link(marker-label, [#footnote-numbering #footnote-label]) #footnote-body
      ]
    }
  }
}

#set figure.caption(position: top)

#figure(
  table(
    columns: 2, 
    [a#footnote[This is a's footnote]], [b], 
    [c#footnote[And this is b's footnote]], [d]
  ),
  caption: [A table with letters]
)
upbeat wing
#

Oops didn't see the footnote on the bottom

#

That's unfortunate, it looks like a bug

#

Anyway the idea is basically just collect the footnotes in a state and then generate the entries after the table, using the nested show rule. Most of the rest of the code is just for labels between the two footnotes to work

#

?r

#let table-footnote-counter-footnote = counter("table-footnote-counter-footnote")
#let table-footnote-state-footnotes = state("table-footnote-state-footnotes", ())
#let table-footnote-counter-table = counter("table-footnote-counter-table")
#let table-numbering-pattern = "a"
#let table-footnote-label = "table-footnote"

#let table-footnote(body) = {
    table-footnote-counter-footnote.step()
    context {
      let footnote-counter = table-footnote-counter-footnote.get().first()
      let state-footnotes = table-footnote-state-footnotes.get()
      let table-counter = table-footnote-counter-table.get().first()
  
      let base-label = table-footnote-label + "-" + str(table-counter) + "-" + str(footnote-counter)
      let marker-label = label(base-label + "-marker")
      let footnote-label = label(base-label + "-footnote")
      let footnote-numbering = super(numbering(table-numbering-pattern, footnote-counter))
      let footnote-body = body
  
      let new-state = (marker-label, footnote-label, footnote-numbering, footnote-body)
      table-footnote-state-footnotes.update((..state-footnotes, new-state))
      
      [#link(footnote-label, footnote-numbering) #marker-label]
    }
}

#show table: it => {
  table-footnote-counter-footnote.update(0)
  table-footnote-state-footnotes.update(())
  table-footnote-counter-table.step()
  
  it

  context {
    let footnotes = table-footnote-state-footnotes.get()
    for (marker-label, footnote-label, footnote-numbering, footnote-body) in footnotes {
      align(left)[
        #link(marker-label, [#footnote-numbering #footnote-label]) #footnote-body
      ]
    }
  }
}

#set figure.caption(position: top)

#figure(
  table(
    columns: 2, 
    [a#table-footnote[This is a's footnote]], [b], 
    [c#table-footnote[And this is b's footnote]], [d]
  ),
  caption: [A table with letters]
)