Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}{%
       \includegraphics[width=2in]{chantheader.jpg}}}
         \aliaspagestyle{chapter}{headings}
 }%
}
share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

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

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

\makechapterstyle{test1}{%
\renewcommand{\printchaptername}{}% suppress "Chapter" from heading
\renewcommand*{\printchapternum}{}% suppress numbering from heading
\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:

enter image description here

The page containing the chapter heading:

enter image description here

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{\printchaptername}{}% suppress "Chapter" from heading
\renewcommand*{\printchapternum}{}% suppress numbering from heading
\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}

enter image description here

openany was used only for the example.

share|improve this answer
    
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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.