mirror of
https://github.com/C0ffeeCode/typst-dhbw-technik-template.git
synced 2025-12-28 15:22:18 +01:00
feat: Pagebreak headings if the page is too far advanced
Can be configured using the `heading_pagebreak_percentage` property
This commit is contained in:
parent
edb1a55ada
commit
9b6fe813df
4 changed files with 29 additions and 1 deletions
Binary file not shown.
|
|
@ -26,6 +26,13 @@ you can supply it if it is not "Introduction" using the `first_chapter_title` pa
|
|||
caption: [Code example explaining how to configure language and a different first chapter]
|
||||
)
|
||||
|
||||
// By default, the template will *not* apply a pagebreak
|
||||
// on non-top-level headings to avoid headings without content
|
||||
// on the same page but can be enabled.
|
||||
// The threshold percentage on the page can be configured
|
||||
// by providing the `heading_pagebreak_percentage` propery like `0.7` or `none`.
|
||||
// Top-level headings will always have a (weak) pagebreak.
|
||||
|
||||
== Bibliography
|
||||
|
||||
As for bibliography / reference listing,
|
||||
|
|
|
|||
21
template.typ
21
template.typ
|
|
@ -140,6 +140,12 @@
|
|||
// This is required to generate the content section correctly
|
||||
first_chapter_title: "Introduction",
|
||||
|
||||
// Factor of page location when to pagebreak headings
|
||||
// to avoid a heading without content on the same page.
|
||||
// Can be disabled by setting it to none
|
||||
// WARNING: can result in "layout did not converge within 5 attempts" issue
|
||||
heading_pagebreak_percentage: none,
|
||||
|
||||
// set automatically by using the template via `#show: thesis.with(...)
|
||||
body,
|
||||
) = [
|
||||
|
|
@ -207,6 +213,21 @@
|
|||
// (weak = no pagebreak on already blank pages)
|
||||
if it.level == 1 {
|
||||
pagebreak(weak: true)
|
||||
} else if heading_pagebreak_percentage != none {
|
||||
// If a heading would start at the very end of a page,
|
||||
// it would not look right => pagebreak
|
||||
context {
|
||||
let here_abs = here().position().y
|
||||
let here_rel = here_abs.abs / page.height
|
||||
|
||||
if here_rel > heading_pagebreak_percentage {
|
||||
// Write but hide to assess location correctly
|
||||
// Hidden will not have any influence
|
||||
// on the output besides correct calculation
|
||||
hide[#here_abs.abs #page.height rel: #here_rel%]
|
||||
pagebreak(weak: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
|
|
|
|||
|
|
@ -36,4 +36,4 @@ but I am too lazy to explain.
|
|||
|
||||
= Summary and Conclusion
|
||||
|
||||
#lorem(100)
|
||||
#lorem(250)
|
||||
|
|
|
|||
Loading…
Reference in a new issue