回忆录章节风格,背景颜色分布在文本/数字上

回忆录章节风格,背景颜色分布在文本/数字上

向社会各界问好!

pdflatex我的目标是使用该类创建文档memoir,该类将具有\chapters、\sections 和\subsections 具有以下格式(字体并不重要,将标题放在彩色背景上很重要):

我的目标方向

即,\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}}}

其结果如下:

  1. 章节标题为黑客

章节标题有点问题

  1. 目录(白色背景上的白色文字,我选择了其中的一些):

在此处输入图片描述

我的黑客存在以下问题:

  • 我没有明确创建的章节的标题(例如内容)在白色背景上使用白色字体;

  • 我在目录中明确命名的章节标题也有蓝色背景,这是我不想要的。

  • 章节标题不包括章节编号。我的目标是使用、、(当使用 时),而不是IntroductionSyntax(即所有使用 创建的章节)作为章节标题\chapter1 Introduction2 Syntax3 Semantics\chapter\chapter*

我的问题如下:

  1. 我将如何创建章节标题,使其背景颜色跨越章节标题文本,包括章节编号。

  2. 在这种情况下(1)如何保持我未明确命名的章节(例如目录、图表列表、表格列表等)的格式一致?

  3. 如何避免背景颜色也显示在目录中?

提前感谢任何帮助/指点!

最小的例子如下:

\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}

第 1 页输出:

第 1 页输出


第 2 页输出:

第 2 页输出

相关内容