从这个 MWE 开始,
\documentclass[12pt,fleqn]{book}
\usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm,headsep=10pt,a4paper]{geometry} % Page margins
\usepackage{graphicx} % Required for including pictures
\usepackage{tikz} % Required for drawing custom shapes
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
\makeatletter
\renewcommand{\@seccntformat}[1]{\llap{\textcolor{ocre}{\csname the#1\endcsname}\hspace{1em}}}
\renewcommand{\section}{\@startsection{section}{1}{\z@}
{-4ex \@plus -1ex \@minus -.4ex}
{1ex \@plus.2ex }
{\normalfont\large\sffamily\bfseries}}
\renewcommand{\subsection}{\@startsection {subsection}{2}{\z@}
{-3ex \@plus -0.1ex \@minus -.4ex}
{0.5ex \@plus.2ex }
{\normalfont\sffamily\bfseries}}
\renewcommand{\subsubsection}{\@startsection {subsubsection}{3}{\z@}
{-2ex \@plus -0.1ex \@minus -.2ex}
{.2ex \@plus.2ex }
{\normalfont\small\sffamily\bfseries}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}
{-2ex \@plus-.2ex \@minus .2ex}
{.1ex}
{\normalfont\small\sffamily\bfseries}}
%----------------------------------------------------------------------------------------
% CHANGE THIS STYLE CHAPTER
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
\newif\ifusechapterimage
\usechapterimagetrue
\newcommand{\thechapterimage}{}%
\newcommand{\chapterimage}[1]{\ifusechapterimage\renewcommand{\thechapterimage}{#1}\fi}%
\newcommand{\autodot}{.}
\def\@makechapterhead#1{%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-9cm) node {\huge\sffamily\bfseries\color{black}\thechapter\autodot~#1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-9cm) node {\huge\sffamily\bfseries\color{black}#1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\fi\fi\par\vspace*{270\p@}}}
%-------------------------------------------
\def\@makeschapterhead#1{%
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-9cm) node {\huge\sffamily\bfseries\color{black}#1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\par\vspace*{270\p@}}
\makeatother
\begin{document}
\chapterimage{example-image-a}
\chapter{Text Chapter}
\section{Paragraphs of Text}\index{Paragraphs of Text}
\end{document}
仔细查看此代码,有一个圆角矩形,赭石色,不透明度与下图形成鲜明对比。
使用相同的结构代码,我无法使用 TikZ 来操作变体。事实上,要创建带有文本和赭石边框的圆角矩形,我使用 TikZ 的代码很复杂。
我想要一些不同形状的东西。例如,我怎样才能得到同样的图像?
使用与我的 MWE 相同的代码仅操作图形部分的变体?
我恳请您的宝贵帮助。
答案1
我仍然不知道我是否收到了这条信息,但这是基于这个答案。它制作了一些橙色框,其大小可调整为多行章节标题。虽然 TeX 代码不是特别有趣,但章节标题包含深刻的哲学信息,这就是为什么我完全理解一些用户可能需要允许他们将章节标题放在多行上的样式。;-)
\documentclass[12pt,fleqn]{book}
\usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm,headsep=10pt,a4paper]{geometry} % Page margins
\usepackage{lmodern}
\usepackage[explicit]{titlesec}
\usepackage{microtype}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\definecolor{myblue}{RGB}{0,82,155}
% from https://tex.stackexchange.com/a/169435/121799
\titleformat{\chapter}[display]
{\normalfont\bfseries\color{myblue}}
{%\filleft%
\begin{tikzpicture}
\node[inner xsep=0.5em,text
width={\textwidth-2em-2.5cm},align=left,font=\Large\sffamily]
(CC){#1};
\path let \p1=($(CC.north)-(CC.south)$) in
node[minimum width=2.5cm,minimum height={min(2.5cm,\y1)},left=1em of CC,
fill=orange,font=\Huge\sffamily\bfseries,text=blue] (TC) {\thechapter};
%{\chaptertitlename~\thechapter};
\end{tikzpicture}%
}
{10pt}
{}
\begin{document}
\pagestyle{empty}
\chapter{Those who can hibernate on a Monday can also hibernate on a Tuesday.}
\chapter{Those who can hibernate on a Monday can also hibernate on a Tuesday and
even on a Wednesday.}
\end{document}