3

I would like to modify the \chapter{} command such that I can include a (fixed height) image in the following sense (quick sketch I made in LibreOffice) with an orange border around it:

enter image description here

Is this possible using TikZ?

//edit: Here is what I get (the aspect ratio is messed up, sure, but that will be OK later on because I will select a picture that works):

enter image description here

The MWE is here:

\documentclass[12pt]{book}

\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\huge\bfseries}
  {\makebox[0cm][r]{\huge\bfseries}\thechapter.\hskip15pt}% label
  {0pt}
  {\tikz[remember picture,overlay]\node[inner sep=0pt] at ($(current page.north) +
  (0,-2cm)$) {\includegraphics[width=\paperwidth, height=4cm]{example-image-a}};
  }
  []
\begin{document}
\chapter{A Chapter}
\lipsum[4]
\end{document}

There are the following problems:

  • There is a weird line break between the chapter number and the title. Why?
  • If I adjust the height of the image to be, say, 8cm, it will cover the chapter numbering etc. How can I make sure it is always after the end of the image?
  • 1
    Packages titlesec, or with memoir or change \@makechapterhead etc. No need for TikZ, in my point of view – user31729 Dec 9 '17 at 21:44
  • Can you point me to a MWE? – Jens Dec 9 '17 at 21:53
  • Maybe tex.stackexchange.com/questions/159978/… could help. – user36296 Dec 9 '17 at 22:46
  • @samcarter: see my edited question above, it is almost what I want, but there are some issues. – Jens Dec 10 '17 at 0:01
  • Do you really need to draw the image using TiKz? Must it be a vector image? Is your book math/academic? Is your book an E-book? If the answer is no to all, then consider using the novel class. It specially deals with fixed-height chapter starts. But images must be raster grayscale for print to paper. You would create your image in (for example) GIMP. – user139954 Dec 10 '17 at 0:37
1

With the overlay, the box will be essentially invisible to TeX as far as the space it occupies is concerned.

\documentclass[12pt]{book}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{lipsum}

\titleformat{\chapter}
  {\huge\bfseries\printcurrentpicture}
  {}
  {0pt}
  {\makebox[0cm][r]{\thechapter.\hspace{15pt}}}
\titlespacing{\chapter}{0pt}{0pt}{20pt}
\newcommand{\printcurrentpicture}{%
  \vspace*{-\dimexpr\topskip+1in+\topmargin+\headheight+\headsep+\lineskip}%
  \moveleft\dimexpr\oddsidemargin+1in\vbox{%
    \hbox{%
      \includegraphics[width=\paperwidth]{\thechapterpicture}%
    }
    \vspace{20pt}
  }%
}
\newcommand{\chapterpicture}[1]{%
  \def\thechapterpicture{#1}%
}

\begin{document}

\chapterpicture{example-image-a}
\chapter{A Chapter}
\lipsum[4]

\end{document}

You'll have to define a suitable version for unnumbered chapters.

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.