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.

  • I generally use \rule{0pt}{\testlen}\vspace{-\testlen}\newline\vspace{-\baselineskip} to force a page break unless there is \testlen left on the page. – John Kormylo Dec 16 '14 at 2:43
  • Hi @JohnKormylo - I want to prevent a page break, not force one. :) – Brian M. Hunt Dec 16 '14 at 3:38
  • By forcing a page break before \section you will prevent one after. – John Kormylo Dec 16 '14 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 '14 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 '14 at 19:20
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.