12

I am preparing a book with memoir. The book has three parts. I would like to have the Part title raised and to insert an image directly below the title. I am able to raise the Part title to the upper portion of the page, and to add an image, but the image falls on the following (normally blank) page (see minimum example, below).

How can I get the image to appear on the same page as the Part title, directly under it?

Here is the minimum example:

\documentclass[12pt,letterpaper]{memoir} %
\usepackage[T1]{fontenc}
\usepackage{eso-pic}
\usepackage[english]{babel}
\usepackage[demo]{graphicx}


\makeatletter
\renewcommand*{\beforepartskip}{\null\vskip-2cm}
\renewcommand*{\afterpartskip}{\par\vskip-5cm%
\@afterindentfalse\@afterheading}
\makeatother


\begin{document}

% \frontmatter
%
%
% \mainmatter

\part{This is the first part}
\AddToShipoutPicture*{%
% By default, eso-pic's zero coordinate is in the lower left corner
\put(\LenToUnit{3.5in},\LenToUnit{5.5in}){%
\includegraphics[height=25mm,keepaspectratio]{figs/PA-500942}%
}
}

\part{This is the second part}

\end{document}
9

Using the same technique as in this question Adding a figure to a Part Page it's much easier to do with memoir:

First we define a command to set the image name for each part. This command takes the same arguments as the \includegraphics command from the graphicx package. Then we add the image to the memoir class \printparttitle command. You can play with the \vfil commands to change the vertical spacing as you require it.

\documentclass{memoir}
\usepackage[demo]{graphicx}
\makeatletter
% define a user command to choose the image
% this command also creates an internal command to insert the image
\def\@partimage{}
\newcommand{\partimage}[2][]{\gdef\@partimage{\includegraphics[#1]{#2}}}
\renewcommand{\printparttitle}[1]{\parttitlefont #1\vfil\@partimage\vfil\gdef\@partimage{}}
\makeatother
\begin{document}
\partimage{foo.png}
\part{A part}
\partimage[width=\textwidth]{bar.png}
\part{Another part}
\end{document}

output of first part page

| improve this answer | |
  • This is wonderful. Thanks very much for this answer! – David Jan 10 '12 at 14:25
  • LaTeX newbie here. Your example code works nicely with pdflatex. However, my project has subfiles. I inserted the code between \makeatletter ... \makeatother in the top-level main file and then I get the error ! Undefined control sequence. \printparttitle ...ttitlefont #1\vfil \@partimage \vfil when compiling. What am I missing? Thx – Laryx Decidua Jan 11 '18 at 10:26
  • 1
    @LaryxDecidua You can add \gdef\@partimage{} after the second \vfil, so a missing \partimage before a subsequent \part command will get things back on track and nothing will be printed. – egreg Jan 11 '18 at 16:27
  • 1
    @egreg Thanks for this. I've added that to the answer. – Alan Munn Jan 11 '18 at 16:38
  • 1
    @LaryxDecidua See edit. Add \def\@partimage{} before the definition of \partimage. – Alan Munn Jan 11 '18 at 17:05
0

This is not an answer, but rather a follow-up to my comments to @Alan Munn's answer. I made it an answer so that I can include code examples.

My problem was not that I used the subfiles package, but rather the fact that I did not always add an image to the part page. Here is a simplified example: the part page includes an image and it works as advertised (practically the same as Alan's example):

\documentclass{memoir}
\usepackage[demo]{graphicx}

\makeatletter
% define a user command to choose the image
% this command also creates an internal command to insert the image
\newcommand{\partimage}[2][]{\gdef\@partimage{\includegraphics[#1]{#2}}}
\renewcommand{\printparttitle}[1]{\parttitlefont #1\vfil\@partimage\vfil}
\makeatother

\begin{document}
\partimage{foo.png} % this works beautifully!
\part{A part}
Lorem ipsum.
\end{document}

However, if I comment out the \partimage command because I do not want to add any images to the Part page:

...
\begin{document}
%%%%% \partimage{foo.png}
\part{A part}
Lorem ipsum.
\end{document}

then I get the following error:

! Undefined control sequence.
\printparttitle ...ttitlefont #1\vfil \@partimage 
                                                  \vfil 
l.15 \part{A part}

This probably happens because \printparttitle expects a \partimage, or so it seems to me (please correct if I am wrong here).

As I am new to LaTeX, I cannot propose an elegant solution. Possible hacks: One could invoke \partimage{some_dummy_image.jpg} with the dummy image being a 10x10 pixel white box. Or maybe one can rewrite the \partimage command so that it does nothing if invoked as \partimage{} (this I can't do due to lack of knowledge).

Summary: use Alan's solution if you always decorate the Parts pages with images.

| improve this answer | |
  • 3
    See my comment to Alan Munn's answer. – egreg Jan 11 '18 at 16:28

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.