我正在尝试排版一本书的章节标题。它需要在文本章节编号的右侧包含自定义图像。我目前尝试使用多列来实现这一点,例如
\begin{multicols}{2}
{\let\clearpage\relax
\chapter[Introduction]{Intro this is a long chapter title}}
\vfill
\columnbreak
{\let\clearpage\relax
\vspace{3.5cm}
\hspace{2cm}
\includegraphics[width=6.4cm, right]{periodicTable.jpg}
}
\end{multicols}
... Here comes section and more text
输出结果如下:
我试图让图形与“第 1 章”字符串垂直对齐(在同一基线上),并且标题文本不换行。
我估计有人必须以某种方式重新定义章节代码,但不知道该怎么做。任何指点都值得赞赏。
答案1
extbook.cls
使用类似的章节结构book.cls
。下面我对其进行了修改,以便通过新创建的用户界面插入指定的图像\chapterimage[<opt>]{<image>}
:
\documentclass[14pt,openany]{extbook}
\usepackage{graphicx}
\makeatletter
\newcommand{\@chapterimage}{}
\newcommand{\chapterimage}[2][]{\renewcommand{\@chapterimage}{\includegraphics[#1]{#2}}}
\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\huge\bfseries \@chapapp\space \thechapter
\hfill\smash{\@chapterimage}% Insert image
\gdef\@chapterimage{}% Remove image definition
\par\nobreak
\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
\makeatother
\begin{document}
\chapterimage[width=150pt]{example-image}
\chapter[Introduction]{Intro this is a long chapter title that spans multiple lines}
... Here comes section and more text
\chapter[Another chapter]{Another long chapter title that spans multiple lines}
... Here comes section and more text
\end{document}