我正在尝试寻找一种回忆录章节样式,使我将图像导入章节,例如使用撒切尔章节样式 - 但图像位于每个章节的中心,并保留所选的章节样式。
有一个例子如何将图像导入回忆录章节样式,但是在第一个例子中,所选的章节样式被覆盖,并且在第二个例子中,我无法为每个章节指定不同的图像。
我使用的基本的文档序言是:
\documentclass[12pt,msmallroyalvopaper]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{xparse}
\usepackage{lipsum}
\chapterstyle{thatcher}
第一个例子:
\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}
第二个例子:
[序言同上]
\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}
答案1
你可以这样做。我以为你想在每一章中更改图像。
\documentclass[12pt,msmallroyalvopaper, openany]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{xparse}
\usepackage{lipsum,mwe}
% usage: \setimage{<image file name>}
\providecommand\currentimage{}
\newcommand\setimage[1]{\def\currentimage{#1}}
\makeatletter
\makechapterstyle{thatcherimage}{%
\chapterstyle{default}
\renewcommand*{\chapterheadstart}{}% <-- this is the command to redefine, but we delay it so it doesn't print an image on the \tableofcontents page
\renewcommand*{\printchaptername}{%
\centerline{\chapnumfont{\@chapapp\ \thechapter}}}
\renewcommand*{\chapternamenum}{}
\renewcommand*{\chapnumfont}{\normalfont\scshape\MakeTextLowercase}
\renewcommand*{\printchapternum}{}
\renewcommand*{\afterchapternum}{%
\par\centerline{\parbox{0.5in}{\hrulefill}}\par}
\renewcommand*{\printchapternonum}{%
\vphantom{\chapnumfont \@chapapp 1}\par
\parbox{0.5in}{}\par}
\renewcommand*{\chaptitlefont}{\normalfont\large}
\renewcommand*{\printchaptertitle}[1]{%
\centering \chaptitlefont\MakeTextUppercase{##1}}}
\makeatother
\chapterstyle{thatcherimage}
\begin{document}
\tableofcontents
% To avoid conflicting with \tableofcontents, we delay the image
% commands until here
\renewcommand*{\chapterheadstart}{%
\par{\centering
\edef\xxx{\noexpand\includegraphics[width=2cm]{\currentimage}}\xxx
\par}\bigskip
}
% Note: the lines surrounding the \edef line are the 'formatting'
\setimage{example-image-a}
\chapter*{Starred Chapter}
\lipsum[1]
\setimage{example-image-b}
\chapter[1-OPT]{Chapter Using 1 Optional Argument}
\lipsum[1]
\setimage{example-image-c}
\chapter[2-OPT][2-OPTIONAL]{Chapter Using 2 Optional Arguments}
\lipsum[1]
\end{document}
尽管可能有点笨重,但这里有一个版本允许您选择性地为章节图像指定\label
和。(虽然我不知道为什么在这种情况下这样的和有意义。)\caption
\caption
关键命令是\setimage
,其工作方式如下:
\setimage(<label>)[<image file>][<caption>]
严格来说,所有参数都是可选的,但第二个命令只是“可选的”,因为不使用三种类型的括号(即,not \setimage(){}[]
)似乎更方便。
\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{doody,
author = {Doody, Terrence},
title = {Hemingway's Style and {Jake's} Narration},
year = 1974,
volume = 4,
number = 3,
pages = {212-225},
journal = {The Journal of Narrative Technique},
}
\end{filecontents}
\documentclass[msmallroyalvopaper, openany]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{xparse}
\usepackage{lipsum,mwe, capt-of}
\newif\ifnoimage
\newif\ifnolabel
\newif\ifnocaption
\providecommand\currentimage{}
\providecommand\currentlabel{}
\providecommand\currentcaption{}
\newcommand\ImagesOff{\noimagetrue\nolabeltrue\nocaptiontrue}
\NewDocumentCommand{\setimage}{d()oo}
{% usage: \setimage(<label>)[<image file>][<caption>]
\noimagefalse
\IfNoValueTF{#1}{\nolabeltrue}{\nolabelfalse\def\currentlabel{#1}}%
\def\currentimage{#2}%
\IfNoValueTF{#3}{\nocaptiontrue}{\nocaptionfalse\def\currentcaption{#3}}%
}
\makeatletter
\makechapterstyle{thatcherimage}{%
\chapterstyle{default}
% \renewcommand*{\chapterheadstart}{}
\renewcommand*{\chapterheadstart}{%
\begin{center}
\ifnoimage\else
\edef\xxx{\noexpand\includegraphics[width=2cm]{\currentimage}}%
\xxx
\fi
%
\ifnocaption \else
\edef\yyy{\noexpand\captionof{figure}{\currentcaption}}%
\yyy
\fi
\ifnolabel\else
{\label{\currentlabel}}%
\fi
\end{center}
}
\renewcommand*{\printchaptername}{%
\centerline{\chapnumfont{\@chapapp\ \thechapter}}}
\renewcommand*{\chapternamenum}{}
\renewcommand*{\chapnumfont}{\normalfont\scshape\MakeTextLowercase}
\renewcommand*{\printchapternum}{}
\renewcommand*{\afterchapternum}{%
\par\centerline{\parbox{0.5in}{\hrulefill}}\par}
\renewcommand*{\printchapternonum}{%
\vphantom{\chapnumfont \@chapapp 1}\par
\parbox{0.5in}{}\par}
\renewcommand*{\chaptitlefont}{\normalfont\large}
\renewcommand*{\printchaptertitle}[1]{%
\centering \chaptitlefont\MakeTextUppercase{##1}}}
\makeatother
\chapterstyle{thatcherimage}
\begin{document}
%\noimagetrue
\ImagesOff
\tableofcontents
% Should only include entries for:
% - example-image
% - example-image-b
\listoffigures
\setimage(fig:no)[example-image][No Letter]% all 3 args present
\chapter*{Image with 3 Arguments}
\lipsum[1]
\setimage(fig:a)[example-image-a]% no \caption; not in LOF
\chapter[1-OPT]{Image with label, no caption}
\lipsum[1]
\setimage()[example-image-b][The Letter B]% no \label; note: 'empty' \label
\chapter[2-OPT][2-OPTIONAL]{Image with cpation, no label }
\lipsum[1]
\setimage[example-image-c]% only the image; not in LOF
\chapter{Only Image}
{\ttfamily
\verb|\ref{fig:no}| (defined) $\to$ \ref{fig:no}\par
\verb|\ref{fig:a}| (defined) $\to$ \ref{fig:a}\par
\verb|\ref{fig:b}| (undefined) $\to$ \ref{fig:b}\par
\verb|\ref{fig:c}| (undefined) $\to$ \ref{fig:c}\par
}
\noimagetrue % <-- probably better to use \ImagesOff, but this works too
\bibliographystyle{abbrvnat}
\nocite{*}
\bibliography{\jobname}
\end{document}