向社会各界问好!
pdflatex
我的目标是使用该类创建文档memoir
,该类将具有\chapter
s、\section
s 和\subsection
s 具有以下格式(字体并不重要,将标题放在彩色背景上很重要):
即,\chapter*{Features}
具有分布在整个线宽上的彩色背景,并且如果有数字,它也位于彩色背景上。
经过一番谷歌搜索后,我得到了类似的东西:
\renewcommand\chaptitlefont{%
\huge\bfseries%
\leavevmode\color{white}%
}
\renewcommand\printchapternum{
\huge\bfseries%
\leavevmode\color{white}%
{\thechapter}
}
与定义章节的组合如下:
\chapter*{\colorbox{my-blue}{\strut\rlap{\textbf{Executive Summary}}\hspace{\linewidth}\hspace{-2\fboxsep}}}
其结果如下:
- 章节标题为黑客:
- 目录(白色背景上的白色文字,我选择了其中的一些):
我的黑客存在以下问题:
我没有明确创建的章节的标题(例如内容)在白色背景上使用白色字体;
我在目录中明确命名的章节标题也有蓝色背景,这是我不想要的。
章节标题不包括章节编号。我的目标是使用、、(当使用 时),而不是
Introduction
和Syntax
(即所有使用 创建的章节)作为章节标题\chapter
1 Introduction
2 Syntax
3 Semantics
\chapter
\chapter*
我的问题如下:
我将如何创建章节标题,使其背景颜色跨越章节标题文本,包括章节编号。
在这种情况下(1)如何保持我未明确命名的章节(例如目录、图表列表、表格列表等)的格式一致?
如何避免背景颜色也显示在目录中?
提前感谢任何帮助/指点!
最小的例子如下:
\documentclass[a4paper,12pt,oneside]{memoir}
\usepackage[english]{babel}
\usepackage{xcolor}
\definecolor{my-blue}{RGB}{0,150,226}
\renewcommand\chaptitlefont{%
\huge\bfseries%
\leavevmode\color{white}%
}
\renewcommand\printchapternum{
\huge\bfseries%
\leavevmode\color{white}%
{\thechapter}
}
\begin{document}
\frontmatter
\pagenumbering{arabic}
\tableofcontents*
\clearpage
\chapter*{\colorbox{my-blue}{\strut\rlap{\textbf{Summary}}\hspace{\linewidth}\hspace{-2\fboxsep}}}
\chapter{\colorbox{my-blue}{\strut\rlap{\textbf{Introduction}}\hspace{\linewidth}\hspace{-2\fboxsep}}}
\chapter{Syntax}
\chapter{Semantics}
\end{document}
答案1
这是一个tikz
修补一堆memoir
类内部宏的解决方案。
\documentclass[openany]{memoir}
\usepackage{tikz}
\usepackage{xpatch}
\definecolor{my-blue}{RGB}{0,150,226}
\chapterstyle{reparticle}
\renewcommand*{\chaptitlefont}{\normalfont\Large\bfseries\color{white}}
\setsecheadstyle{\Large\bfseries\memRTLraggedright\color{white}}
\setsubsecheadstyle{\large\bfseries\memRTLraggedright\color{white}}
\makeatletter
\newcommand{\@selyunin@box}[1]{%
\tikz\node[fill=my-blue, inner sep=1mm, text width=\linewidth-2mm]{#1\strut\par};}
% numbered chapters
\xpatchcmd{\@makechapterhead}
{\ifm@m@And
\printchaptername \chapternamenum \printchapternum
\afterchapternum
\else
\printchapternonum
\fi
\interlinepenalty\@M
\printchaptertitle{#1}}
{\@selyunin@box{%
\ifm@m@And
\printchaptername \chapternamenum \printchapternum
\afterchapternum
\else
\printchapternonum
\fi
\interlinepenalty\@M
\printchaptertitle{#1}}}
{}
{}
% unnumbered chapters
\xpatchcmd{\@makeschapterhead}
{\printchaptertitle{#1}}
{\@selyunin@box{\printchaptertitle{#1}}}
{}
{}
% TOC, LOF, and LOT headings
\xpatchcmd{\@tocmaketitle}
{\@nameuse{printtoctitle}{\contentsname}}
{\@selyunin@box{\@nameuse{printtoctitle}{\contentsname}}}
{}
{}
\xpatchcmd{\@lofmaketitle}
{\@nameuse{printloftitle}{\contentsname}}
{\@selyunin@box{\@nameuse{printloftitle}{\contentsname}}}
{}
{}
\xpatchcmd{\@lotmaketitle}
{\@nameuse{printlottitle}{\contentsname}}
{\@selyunin@box{\@nameuse{printlottitle}{\contentsname}}}
{}
{}
% numbered sections
\xpatchcmd{\M@sect}
{\@hangfrom{\hskip #3\relax\@svsec}%
\interlinepenalty \@M #9\@@par}
{\@selyunin@box{%
\@hangfrom{\hskip #3\relax\@svsec}%
\interlinepenalty \@M #9}}
{}
{}
% unnumbered sections
\xpatchcmd{\@mem@old@ssect}
{\@hangfrom{\hskip #1}%
\interlinepenalty \@M #5\@@par}
{\@selyunin@box{%
\@hangfrom{\hskip #1}%
\interlinepenalty \@M #5}}%
{}
{}
\makeatother
\begin{document}
\tableofcontents
\chapter{Chapter heading}
\section{Section heading}
\subsection{Subsection heading}
\section{A very long section heading that needs to go on to the next line}
\subsection{A very long subsection heading that needs to go on to the next line}
\section*{Starred section heading}
\subsection*{Starred subsection heading}
\section*{A very long starred section heading that needs to go on to the next line}
\subsection*{A very long starred subsection heading that needs to go on to the next line}
\chapter{A very long chapter heading that needs to go on to the next line}
\chapter*{Starred chapter heading}
\chapter*{A very long starred chapter heading that needs to go on to the next line}
\appendix
\chapter{Appendix chapter heading}
\section{Appendix section heading}
\subsection{Appendix subsection heading}
\section{A very long appendix section heading that needs to go on to the next line}
\subsection{A very long appendix subsection heading that needs to go on to the next line}
\section*{Starred appendix section heading}
\subsection*{Starred appendix subsection heading}
\section*{A very long starred appendix section heading that needs to go on to the next line}
\subsection*{A very long starred appendix subsection heading that needs to go on to the next line}
\chapter{A very long appendix chapter heading that needs to go on to the next line}
\chapter*{Starred appendix chapter heading}
\chapter*{A very long starred appendix chapter heading that needs to go on to the next line}
\end{document}