10

In a book, with the book documentclass, I'm typesetting I want to include a figure above the \chapter title. This however has turned out to be hard. With the following code:

\chapter{Uppväxt}

\begin{figure}[ht]
\includegraphics[width=\textwidth]{bilder/hus.jpg}
\end{figure}

\noindent
\lipsum

Produces the following result: A figure underneath a chapter.

Placing \figure above \chapter results in the image being put on the previous page due to the \clearduble command of \chapter, which is desirable for the rest of the book. Changing the options of \figure to [t] results in the figure being included on the next page. It seems like no other combination of positioning options seems to help either.

Can anyone think up a way of placing the figure above the chapter?

3
  • the answer to this depends on what \documentclass you are using, because they define \chapter in different ways. some classes even go to extra trouble to prevent floats from coming at the top of the first page of a chapter. my inclination is that this picture should be treated not as a float, but inserted via some explicit mechanism within the (altered) \chapter framework. but the particular mechanism that might be successful does depend strongly on the \documentclass. Commented Nov 12, 2014 at 13:20
  • You can use eso-pic or background or textpos packages and overlay the image.
    – user11232
    Commented Nov 12, 2014 at 13:29
  • @barbara beeton: I had Book as a tag on the post, but it was removed by lockstep - hence the ambiguity about the documentclass. Added back in the text instead.
    – Rovanion
    Commented Nov 12, 2014 at 13:31

1 Answer 1

13

The image appears to be part of the chapter head design so the most natural place to add it is in \@makechapterhead (or equivalent command in other classes.

enter image description here

This adds an image with name \chappic if that command is non empty.

\documentclass{book}
\usepackage{graphicx}
\makeatletter

\def\@makechapterhead#1{%
  \ifx\chappic\@empty
  \vspace*{50\p@}%
\else
  \vspace*{5\p@}% was 5
    \centerline{\includegraphics{\chappic}}%<<<<
\fi
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
\makeatother
\newcommand*\chappic{}

\begin{document}

\renewcommand*\chappic{house}
\chapter{house}

text ... text ... text ... text ... text ... text ... text ... text ... 
text ... text ... text ... text ... text ... text ... text ... text ... 
text ... text ... text ... text ... text ... text ... text ... text ... 

\renewcommand*\chappic{}
\chapter{no house}

text ... text ... text ... text ... text ... text ... text ... text ... 
text ... text ... text ... text ... text ... text ... text ... text ... 
text ... text ... text ... text ... text ... text ... text ... text ... 


\end{document}
7
  • This will include the image before every chapter which is not the desired effect. The image should only appear in one place in the book.
    – Rovanion
    Commented Nov 12, 2014 at 13:35
  • @Rovanion well to be exact it will include a figure with the same name as each chapter if it exists. It can be wrapped in a conditional so it only sometimes does that, I'll add a line... Commented Nov 12, 2014 at 13:39
  • @Rovanion updated with chapter 1 with an image and chapter 2 without Commented Nov 12, 2014 at 13:47
  • What does the command \interlinepenalty\@M do in the title? It messed up the rest of the text by inserting spaces between paragraphs.
    – Rovanion
    Commented Nov 18, 2014 at 20:20
  • @Rovanion it prevents page breaks between lines, oops the first one is not inside a group. Oh just remove it, sorry. Commented Nov 18, 2014 at 20:26

You must log in to answer this question.

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