Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to place background images behind all of my part titles, with the image spanning across two pages, e.g.:

 ___________ ___________
|           |           |
| Part 1    |           |
| Birds of  |           |
| South     |           |
| America   |           |

So far, I have created this code:

\definelayer[patternleft][x=0mm, y=0mm, width=\paperwidth, height=\paperheight]
\definelayer[patternright][x=0mm, y=0mm, width=\paperwidth, height=\paperheight]

\setlayer[patternleft]                {%
    \framed[frame=off, align=right]{%
        \clip[nx=2, ny=1, x=1, y=1]{%

\setlayer[patternright]                {%
    \framed[frame=off, align=left]{%
        \clip[nx=2, ny=1, x=2, y=1]{%

I then put it in the document like this:

\setupbackgrounds[page][background=patternleft] % sets background for verso
\part{Birds of South America}

\setupbackgrounds[page][background=patternright] % sets background for rector
\setupbackgrounds[page][background={}] % sets a blank background

    This is some text.

This has two problems:

  • The images are the same size as the twp pages, however, white space remains along the margins and fold.
  • This sometimes places the backgrounds on the wrong pages.

How can I improve this code so that the background graphic spans across verso and recto pages on the \part titles?

share|improve this question
Split the image into two part (see \clip) and use the left part as the background for one page and the right part as the background for the other page. –  Aditya Jun 12 '13 at 15:55

1 Answer 1

up vote 5 down vote accepted

To expand on the approach @Aditya was hinting at in his comment, you can chop whatever picture you choose as the background into fitting pieces using the \clip macro. First, set a partitioning grid using \setupclipping, e.g.:


This defines clipping to use two segments horizontally and four segments vertically. You can then address these parts using their coordinates:


This extracts the piece that is located at the third column of the fourth row of whatever the macro is applied to. Your doublesided background is a simpler problem as it requires only a single horizontal split:

%% left half:
%% right half:

Now you just have to draw these parts as the background. This is no problem in Context as all the elements that constitute the page layout are derived from \framed, inheriting its options. Thus, in order to draw an image as a page background you can use the same strategy as with \framed: wrap the content in an overlay and assign it to the background. The element that spans one entire page is called paper, and you can configure it via \setupbackgrounds:

\defineoverlay [background:overlay] [\backgroundcmd]
\setupbackgrounds [paper] [background=overlay:background]

What’s left is to define \backgroundcmd so that it clips the left or right half depending on whether the current page is recto or verso:


Combining everything, a solution could look like this:

doublesided page background

\setupexternalfigures [location={default}] %% figure search path
\setuppagenumbering [alternative=doublesided]


%% 1) a named figure for inclusion, scaled to twice the width of one
%%    page
\useexternalfigure [half_cow] [cow.pdf] [

%% 2) a command that draws the left or right portion of a figure,
%%    depending on whether the page is recto or verso.
%%    also, we install a counter to check if the background should be
%%    placed at all, since it is only desired with “\part” headings.
%%    this counter will be decremented with every invocation and reset
%%    whenever a new part begins.


  \setupclipping [nx=2,ny=1,]%
    \ifodd\pagenumber                           %% clip right half
    \else                                       %% clip left half
    \global \advance \cowcount \minusone

%% 3a) define an overlay that we can use as page background
\defineoverlay [pickhalfcow] [\pickhalfcow_cmd]

%% 3b) hook the overlay into the “paper” element of the layout
\setupbackgrounds [paper] [background=pickhalfcow]

\setuphead [part] [
  page=left, %% assumption: parts always begin verso

%% 4) define auxiliary macro that resets the background image counter


%% Ready. Here’s some code that generates a couple pages.

    \definedfont[name:IwonaMediumRegular at 22pt]

    \startpart[title=South America etc.]
        \input knuth \page

    \startpart[title=Birds And Such]
        \input knuth \page


Update: Hooked the code into the part headings.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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