1

Using ConteXt, how could one prevent a page break between a heading and an image or text + image? For example, given:

 \section{With a Chart}
 \placefigure[here] {}{\externalfigure[Chart.pdf]}

 % or

 \section{With a Chart}
 \placefigure[right] {}{\externalfigure[Chart.pdf][width=5cm]}
 Hello, world ...

The above sequences regularly result in a page break between the section heading.

I noticed a couple related questions, but nothing exactly on this - what I would think as a trivial situation that might have a more straightforward answer than I have seen in the other questions.

9
  • I generally use \rule{0pt}{\testlen}\vspace{-\testlen}\newline\vspace{-\baselineskip} to force a page break unless there is \testlen left on the page. Dec 16, 2014 at 2:43
  • Hi @JohnKormylo - I want to prevent a page break, not force one. :) Dec 16, 2014 at 3:38
  • By forcing a page break before \section you will prevent one after. Dec 16, 2014 at 14:28
  • 1
    @BrianM.Hunt: The equivalent of @JohnKormylo's code in ConTeXt will be \setuphead[setion][before={\testpage[4]}] which will check if there are at least space for 4 lines on the page; if not, it will issue a page break.
    – Aditya
    Dec 16, 2014 at 19:06
  • 2
    For why LaTeX and ConTeXt behave differently wrt page breaks after sections, see this thread. It is hard to test without a minimal example, but you can also try: \setuphead[after={\blank[samepage]}] or \placefigure[force,here] or \placefigure[always,here]
    – Aditya
    Dec 16, 2014 at 19:20

1 Answer 1

2

The first heading-figure splitting can be remedied by using force in the location parameter. As for the second, I have found no solution and I don't think there is an easy one, because the wrapped figures mess quite a bit with how paragraphs are built and it's not easy to interact with this.

\starttext

\input knuth
\input knuth
\input knuth
\input knuth

\startsection[title={With a Chart}]

  \startplacefigure[location={force,here}]
    \externalfigure[Chart.pdf]
  \stopplacefigure

  \input knuth
  \input knuth
  \input knuth

\stopsection

\startsection[title={With a Chart}]

  \startplacefigure[location={force,right}]
    \externalfigure[Chart.pdf][width=5cm]
  \stopplacefigure

  Hello, world ...

\stopsection

\stoptext

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .