Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for footnote layout with columns

I have implemented a basic page layout algorithm for footnote placement. Basically:

  1. Layout a line of body text.
  2. If it contains footnote references, lay out footnotes line by line.
  3. Go to 1.

At every step, I check to see if the total height (body text + footnote text + gap) exceeds page height. If it does, I remove the most recently laid out line and the page is complete.

My question is: How do I deal with a situation where the body text is in two columns?

I would essentially need to know the total allowed body text height in advance in order to properly lay out the columns, but that cannot be known until I know the height of the footnote text.

I also can't just take the accumulated height of body text lines and divide by 2, due to varying line heights, line spacing, paragraph spacing, etc.

like image 341
yclevine Avatar asked Apr 01 '26 02:04

yclevine


1 Answers

You have 3 blocks – two for the columns and one for footnotes. Obviously (height of the column + height of the footnotes + gap) has to be lower than page height.

You can use your old algorithm for the first column. For the second column, when you add a footnote and it causes the first column to be too long, move lines from the end of the first column to the beginning of the second. If this makes the second column too long, move the line(s) back to the first column and remove the last footnote line.

like image 61
svick Avatar answered Apr 03 '26 18:04

svick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!