How to keep heading and rotated figure on the same page

== Thermodynamic properties of chemicals
#align(center, rotate(
  -90deg,
  reflow: true,

  [#figure(
    image("image.png", width: 80%),
    caption: "asdf"
) <fig_chems_Gf>],
)
)

I need to paste a rotated image directly below a heading, but the image keeps pagebreaking. How to ensure the image stays on the same page? There’s enough space. Thank you!

Could you provide more information?
Do you really want to rotate the image’s caption? Apart from the heading, image and caption, is there any other content on this page?

(A screenshot like this would be helpful)

Try reducing the width a little, it should stay on the page. Probably has to do with margins? This example should fit on a page:

== Thermodynamic properties of chemicals
#align(center, 
  rotate(-90deg, reflow: true,
    [#figure(
      rect(width: 24.1cm),
      caption: "asdf"
    ) <fig_chems_Gf>],
  )
)

With a width of 24.2cm it does not. But it does if you reduce the page margin.

Thank you for your replies. I don’t think it’s the image itself, perhaps the caption is pushing it on the next page.

edit: Also full code, I did not initially include the cation but it apparently plays a role here:

== Thermodynamic properties of chemicals
#align(center, rotate(
  -90deg,
  reflow: true,

  [#figure(kind:table,
    image("../figures_for_thesis_typst/appendix/chemicals_properties_mine_for_thesis.png",width: 95%),
    caption: flex-caption([Gibbs free energy of formation of chemicals included in macrochemical equation calculation. For each chemical, its name and elemental formula with dominant charge species are listed. Values of thermodynamic properties from various sources are listed per column. Columns in bold are manually selected values used for calculations. Gf, Gibbs free energy of formation, Hf, enthalpy of of formation, Hc, enthalpy of combustion, Sf, entropy of formation. Sources: @Roger2018HandbookBiology, @Toure2016DeterminationTools, @Caspi2014TheDatabases, @Amend1997GroupPressures, @Kleerebezem2010, @Perisanu2020TheAcids]
    ,
    [Values of thermodynamic properties of chemicals used in calculations])
) <fig_chems_Gf>],
)
)
#pagebreak()

Well done on identifying the caption is the culprit. Seems to me you are looking for How to make figure caption text have the same width as the figure? - #2 by slowjo which has a working solution:

#show figure: it => layout(sz => {
  let w = measure(
    it.body,
    width: sz.width,
  ).width
  set par(justify: true)
  show figure.caption: cap => box(width: w, align(left, emph(cap)))
  it
})

== Thermodynamic properties of chemicals
#align(center, rotate(
  -90deg,
  reflow: true,

  [#figure(
    kind: table,
    rect(width: 95%, height: 100%), //height added for MWE
    caption: lorem(65),
  ) <fig_chems_Gf>],
))

Edit: I’ve updated the code to reflect the fact you are using width: 95% as per How to make figure caption text have the same width as the figure? - #4 by slowjo.

Thanks for the screenshot and the code snippet, it really helps helping you quickly. If I may, providing a MWE that compiles and doesn’t require helpers to remove citations, code snippets such as flex-caption, etc. would ensure you get answers much faster.

1 Like

Thank you so much! I’ll try better next time, should have included more context.

1 Like