# how to import images into Memoir chapter style

Another Memoir style I'm trying to create... I grabbed bits of code from here and there and I almost have it working, but the imported image isn't centered over the chapter title... spent many hours on this before coming to you...I'm trying! I would appreciate if someone could fix it and suggest any clean up to any blunders I've made.. Also, I would like to suppress all chapter numbers in the document (but keep them in the toc) is there a good way to do that, or do I just need to use the asterisk.

in brief... what I'm trying to do is get an image over centered text with some numbers in there that I can tweak to adjust the v spacing between the image and title and between the title and the first paragraph.

\makechapterstyle{test1}{%
\chapterstyle{default}
\chapterstyle{article}%
\renewcommand*{\printchapternonum}{%
%    \vphantom{\printchaptername \chapnumfont 1}
\afterchapternum
}
\renewcommand*{\afterchapternum}{%
\vspace*{\beforechapskip}
\smash{%
\raisebox{0cm}{%
}%
}

-

You can try something like this (the code contains some explanatory comments):

\documentclass{memoir}
\usepackage{graphicx}
\usepackage{lipsum}

\makechapterstyle{test1}{%
\renewcommand*{\chaptitlefont}{\normalfont\bfseries\LARGE\centering}% title formatting
\renewcommand\afterchapternum{%
\centering\includegraphics[width=2in]{ctanlion}\vskip1em}% add the image and some additional vertical spacing (1em) between the image and the title
\setlength\beforechapskip{-10pt}% adjust vertical space before the image
\setlength\afterchapskip{30pt}% adjust vertical space after the title
}
\chapterstyle{test1}

\begin{document}

\tableofcontents*
\chapter{Test Chapter}
\lipsum[2]

\end{document}


The ToC:

The page containing the chapter heading:

CTAN lion drawing by Duane Bibby.

In a comment, a redefinition of \chapter has been requested, so as to have an additional mandatory argument to specify the image for each chapter. The code below shows this redefinition with the help of the xparse package (I used xparse to easily handle the two optional arguments for \chapter in memoir); the new syntax is

\chapter[ToC entry][Header text]{image file}{Heading in the document body}

\documentclass[openany]{memoir}
\usepackage{graphicx}
\usepackage{xparse}
\usepackage{lipsum}

\newcommand\chapterimage{}
\makechapterstyle{test1}{%
\renewcommand*{\chaptitlefont}{\normalfont\bfseries\LARGE\centering}% title formatting
\renewcommand\afterchapternum{%
\centering\chapterimage\vskip1em}% add the image and some additional vertical spacing (1em) between the image and the title
\setlength\beforechapskip{-10pt}% adjust vertical space before the image
\setlength\afterchapskip{30pt}% adjust vertical space after the title
}
\chapterstyle{test1}

% Redefinition of \chapter; now it has an additional mandatory argument
% for the name of the image file to be used for each chapter
\let\oldchapter\chapter
\RenewDocumentCommand\chapter{O{}O{}mm}{%
\if\detokenize{#3}\relax\relax
\gdef\chapterimage{}
\else
\gdef\chapterimage{\includegraphics[width=2in]{#3}}
\fi%
\oldchapter[#1][#2]{#4}}

\begin{document}

\tableofcontents*
\chapter{example-image-a}{Test chapter one}
\lipsum[4]
\chapter{example-image-b}{Test chapter two}
\lipsum[4]

\end{document}


openany was used only for the example.

-
Thank you very much. Very helpful for this project and for helping me understand what is going on with the code. – user23034 Dec 14 '12 at 19:17
This works great, but I'd love it to be able to take an argument so that each chapter can have an image of its own. I've tried messing around with it, but I can't get it to work... Something like: \chapter{image}{Chapter Name} Would be great... – Kristian Nordestgaard Aug 24 '13 at 21:25
@KristianNordestgaard will every chapter have an image? – Gonzalo Medina Aug 24 '13 at 22:15
@GonzaloMedina Yes, in my document they will. – Kristian Nordestgaard Aug 24 '13 at 22:30
@KristianNordestgaard please see my updated answer. – Gonzalo Medina Aug 24 '13 at 23:30