How to replace chapter boilerplate with full-page image?

1,990

Solution 1

I would define a new command \picturechapter that does it all.

Pre Solution step only for demonstration

Only to have a complete minimal working example, we first make a PDF with all the chapter page pictures. You don't need this in real world, where you already have the chapter page pictures!

% This is only an example file to generate the pictures to be used
% at the following MWE. If you already have picture files (either
% one PDF with one picture per page or one file per picture) you
% won't need this file!!!
\documentclass{article}
\usepackage{graphicx,xcolor,eso-pic}
\begin{document}
  \pagestyle{empty}
  \centering
  \AddToShipoutPicture{%
    \AtPageLowerLeft{%
      \color{green}\rule{\paperwidth}{\paperheight}%
    }%
  }%
  \vspace*{\fill}\rotatebox{45}{\Huge Chapter page 1}\vspace*{\fill}\newpage
  \vspace*{\fill}\rotatebox{45}{\Huge Chapter page 2}\vspace*{\fill}\newpage
  \vspace*{\fill}\rotatebox{45}{\Huge Chapter page 3}\vspace*{\fill}\newpage
  \vspace*{\fill}\rotatebox{45}{\Huge Chapter page 4}\vspace*{\fill}\newpage
\end{document}

Save this with the name chapterpages.tex and do pdflatex chapterpages to make chapterpages.pdf. This step has been done only to have a test base for the following suggested solution!

Solutions Suggestion

Now let's define a new command \picturechapter that loads one page chapterpages.pdf to be our chapter picture page, but set up toc entry and running head line like a real \chapter would:

\documentclass{book}
\usepackage{pdfpages}

\usepackage[english]{babel}
\usepackage{blindtext}% For demo only (see below)

\usepackage{hyperref}% to show, that even hyperlinks work

% New switch to decide, if the chapter pictures are chapter-1,
% chapter-2 ... chapter-A, chapter-B ... or the pictures are
% the pages of one file chapterpages.pdf. If you have e.g. an
% appendix you have to use \singlepicturestrue
\newif\ifsinglepagepictures

% At this example we use one file chapterpags.pdf:
\singlepagepicturesfalse

\newcommand*{\picturechapter}[1]{%
  \cleardoublepage
  \refstepcounter{chapter}%
  \ifsinglepagepictures
    \includepdf[page=1,
      pagecommand={%
        \thispagestyle{empty}%
        \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
        \chaptermark{#1}%
      }%
    ]{chapter-\thechapter}%
  \else
    \includepdf[page=\arabic{chapter},
      pagecommand={%
        \thispagestyle{empty}%
        \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
        \chaptermark{#1}%
      }%
    ]{chapterpages}%
  \fi
}

\begin{document}
\tableofcontents
\picturechapter{This is my fist picture chapter}
\blindtext

\let\chapter\picturechapter% for demo purpose only to make \blinddocument use
                           % \picturechapter
\blinddocument
\blinddocument
\blinddocument
\end{document}

After processing this file with pdflatex you get an example pdf with green chapter starting picture pages, that are shown at the table of contents with the headings "1 This is my first picture page", "2 Heading on level 0 (chapter)", "2 Heading on level 0 (chapter)", "3 Heading on level 0 (chapter)". Even the hyper links from the table of contents to the green pages are working. The running head at the pages following the green chapter pages are set too.

The suggested solution has been testes with book and scrbook (a KOMA-Script class). But is should work also with report or scrreprt or almost every class with \chapter. To use it with an article class, you have to replace chapter by section and \chaptermark by \sectionmark.

Alternative 1 to the shown suggestion (one file per picture)

If you want to use not a single file chapterpages.pdf with all the pictures, but single files chapter-1.png, chapter-2.jpg, chapter-3.pdf etc. you simply have to replace \singlepicturesfalse by \singlepicturestrue. In this case it would even work with appendix with numbers A, B, C etc. The corresponding file names would be chapter-A.png, chapter-B.png etc.

Alternative 2 (be independent from chapter counter) NOTE: If you redefine \thechapter using \singlepicturesturetrue, you have to redefine your chapter pictures too. To avoid this, you may use your own counter:

\newcounter{chapterpicture}
\newcommand*{\picturechapter}[1]{%
  \cleardoublepage
  \refstepcounter{chapter}%
  \stepcounter{chapterpicture}% use next chapter picture file
  \ifsinglepagepictures
    \includepdf[page=1,
      pagecommand={%
        \thispagestyle{empty}%
        \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
        \chaptermark{#1}%
      }%
    ]{chapter-\thechapterpicture}%
  \else
    \includepdf[page=\thechapterpicture,
      pagecommand={%
        \thispagestyle{empty}%
        \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
        \chaptermark{#1}%
      }%
    ]{chapterpages}%
  \fi
}

In this case the pictures at the appendix would be names chapter-9.png, chapter-10.pdf etc (if the last chapter before the appendix has been 8).

Alterative 3: (each picture file has it's own name independent from the number of the chapter)

As an alternative you may define a command with a second argument: the name of the chapter picture (you cannot test this with the example above because \blinddocument will not set the second argument):

\newcommand*{\picturechapter}[2]{%
  \cleardoublepage
  \refstepcounter{chapter}%
  \includepdf[page=1,
    pagecommand={%
      \thispagestyle{empty}%
      \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
      \chaptermark{#1}%
    }%
  ]{#2}%
}

Usage would be:

\picturechapter{My chapter heading}{filename}

Advantage of this solution would be, that you don't need to rename chapter picture files, if you move, remove or insert chapters into the document.

Solution 2

Instead of disabling the heading commands and placing your own heading commands in the body text, I recommend customizing the default heading commands. Use \makeatletter and \makeatother, otherwise you would get that mentioned error "Missing \begin{document}" because of the @ character in the macro names.

For example:

\makeatletter
\renewcommand*{\@makechapterhead}[1]{
  \AddToShipoutPicture*{\centering\includegraphics[width=\paperwidth]{\chapterimage}}
}
\makeatother

Similarly, \@makeschapterhead produces the headings when \chapter* is used, and can be redefined.

Further have a look at the titlesec package, which can be used for customizing heading format and spacing, so you would not have to redefine internal class macros as above.

Share:
1,990

Related videos on Youtube

fluffy
Author by

fluffy

Updated on August 01, 2022

Comments

  • fluffy
    fluffy over 1 year

    Let's say I am producing a book (using \documentclass{book}) where instead of displaying the chapter name textually, I am inserting an image that includes the chapter text. How can I still start a new chapter and set the chapter name (for headings and TOC) without actually displaying that it's a new chapter?

    The code I have right now is:

    \chapter{My Chapter Title}
    \AddToShipoutPicture*{\centering \includegraphics[width=\paperwidth]{chapter-1.png}}
    \phantom{asdf}
    

    where chapter-1.png is of course my full-page image, and the \phantom{asdf} is apparently necessary for \AddToShipoutPicture to work right.

    Based on "How to format the chapter heading" I tried both of these in my preamble, and neither one worked:

    % Generated "LaTeX error: Missing \begin{document}"
    \renewcommand{\@makechapterhead}[1]{
        \vfill
    }
    
    % Had no effect
    \def\@makeschapterhead#1{
        \vfill
    }
    

    Is there something else I can do to change the \chapter template, or even an internal variable that it can set? I'm pretty new to customizing TeX layouts, and have previously only used the predefined styles for thesis et al, so I'm a bit lost.

  • fluffy
    fluffy almost 12 years
    Thanks! How do I define \chapterimage? Just doing \chapter[chapterimage=foo.png]{ChapterTitle} didn't work (I got a macro error, "Undefined control sequence \chapterimage"). Also I'm including my individual chapters in separate .tex files, if that makes a difference.
  • fluffy
    fluffy almost 12 years
    For now just doing \def\chapterimage{chapter-1.png} \chapter{Chapter Title} seems to work. Thanks!
  • fluffy
    fluffy almost 12 years
    That certainly seems to be the proper TeX-y way to do it: overwrought, overly complicated, and requires a Makefile to update things correctly. ;)
  • Schweinebacke
    Schweinebacke almost 12 years
    @fluffy: This doesn't need a Makefile! Note, that you need the fist file only for this example to have picture files. We don't have your picture files, so we need some. You have picture files (and in your question named them chapter-1.png etc.). So need only change switch \singlepagepicturefalse to \singlepagepicturetrue to use your your already existing picture files running the second document at my answer. And in difference to your idea with overwriting definition of \@makechapterhead it does not overwrite anything.
  • egreg
    egreg almost 12 years
    @fluffy I don't agree: the last piece of code (which I'd have presented first) is simple and practical.
  • fluffy
    fluffy almost 12 years
    @egreg Yeah, the last \picturechapter macro is pretty decent. +1 for that. When I commented on this answer only the first example code was here. I definitely like \picturechapter a lot better than the other ones.
  • Schweinebacke
    Schweinebacke almost 12 years
    @fluffy: As you can see at the revision list all the examples where there at the first version of my answer. Later and because of your sarcastic comment I've only added the headlines and some sentence to make clear, that no Makefile or something like this will be needed for my suggestions.
  • fluffy
    fluffy almost 12 years
    Oh, so it is, thanks. Sorry about that. I think I just got overwhelmed by the verbosity of the first two approaches that I must have overlooked the third.
  • fluffy
    fluffy almost 12 years
    So, I finally tried switching over to this method (since it seems a bit cleaner), but I couldn't figure out how to use \AddToShipoutPicture or \includegraphics or whatever instead of \includepdf (since my images are in .png format, not .pdf).
  • Schweinebacke
    Schweinebacke almost 12 years
    @fluffy: Package pdfpages can handle .png, because it uses \includegraphics internally. Otherwise the example filenames I've given would be wrong but they are not.
  • fluffy
    fluffy almost 12 years
    Okay, good to know. I guess I should have just tried it straight away. Sorry to be such a bother.