如何在章节标题顶部添加图片。示例快照如下(此处圆圈为图片):
SWE 是:
\documentclass[12pt]{book}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[display]
{\bfseries\Large}
% {\filright\MakeUppercase{\chaptertitlename}\Huge\thechapter}
{}
{1ex}
{\titlerule\vspace{1ex}\filcenter #1}
[\vspace{1ex}\titlerule]
\begin{document}
\chapter{A Chapter}
\lipsum[4]
\end{document}
答案1
\documentclass[12pt]{book}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[display]
{\bfseries\Large}
% {\filright\MakeUppercase{\chaptertitlename}\Huge\thechapter}
{}
{1ex}
{\tikz[remember picture,overlay]\node[inner sep=0pt] at ($(current page.north) +
(-0.75cm,-2.5in)$) {\includegraphics[width=4cm]{example-image-a}};
\vspace{1ex}\titlerule\\\filcenter #1
}
[\vspace{1ex}\titlerule]
\begin{document}
\chapter{A Chapter}
\lipsum[4]
\end{document}
答案2
尝试定义一个宏,称为 ,\mychapter
其中为每个章节添加 3 张图片。可以通过\put(x,y)
将 (0,0) 置于物理页面的左下角来更改位置以满足个人需要。当前位置是手动设置的。\AddToShipoutPicture
在生成页面时(即发货时)将图片插入页面。
代码
\documentclass[12pt]{book}
\usepackage{lipsum}
\usepackage{wallpaper} % Or \usepackage{eso-pic,graphicx}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[display]
{\bfseries\Large}
% {\filright\MakeUppercase{\chaptertitlename}\Huge\thechapter}
{}
{1ex}
{\titlerule\vspace{1ex}\filcenter #1}
[\vspace{1ex}\titlerule]
\newcommand{\mychapter}[1]{
\chapter{#1}
\AddToShipoutPicture*{%
\put(100,580){\includegraphics[scale=0.1]{example-image-a}}
\put(150,580){\includegraphics[scale=0.1]{example-image-b}}
\put(200,580){\includegraphics[scale=0.1]{example-image-c}}
}}
\begin{document}
\mychapter{A Chapter}
\lipsum[4]
\section{blah blah blah}
\mychapter{The Second Chapter}
\lipsum[4]
\section{blah blah blah}
\mychapter{The third Chapter}
\lipsum[4]
\section{blah blah blah}
\end{document}