重现精美的章节风格

重现精美的章节风格

我正在尝试在 LaTeX 中创建下面的章节样式,其中灰色框代表为每个章节选择的不同图像。我希望章节标题(在此示例中为“复数”)和章节编号(在此示例中为 9)在图片中显示的框部分中垂直居中。单词“Chapter”也应居中显示在两条虚线交叉处的黑色框中。我认为从 Bjornstrup 章节样式开始可能会更容易,看看我是否可以对其进行编辑以获得所需的效果。但是,我的尝试(如下)没有成功。如果有人能告诉我如何实现所需的输出,我将不胜感激。

\documentclass[a4paper,12pt]{report}
\usepackage{tikz}
\usepackage[Bjornstrup]{fncychap}
%%%% ******************************************************* added
\newcommand{\colortitlechap}{\color[rgb]{0.9,0.9,0.9}} % color of the chapter title <<<
\newcommand{\colornumberchap}{\color[rgb]{0.6,0.6,0.6}} % color of the chapter number <<<<
\newcommand{\colorbackchap}{\colorbox[rgb]{.129,0.1,0.82}} % color of the background rules <<<

\makeatletter

\renewcommand{\DOCH}{%
    \settowidth{\py}{\CNoV\thechapter}
    \addtolength{\py}{0pt}% 
    \colorbackchap{\rule{0pt}{40pt}\parbox[b]{\textwidth}{\hfill}}%
    \kern-\py\raise0pt%
    \hbox{\colornumberchap\CNoV\thechapter}
    \begin{tikzpicture}[overlay,remember picture]
        \draw[dotted, black, ultra thick] (2cm,0cm) -- (2cm,2.5cm);
        \draw[dotted, black, ultra thick] (0,1.2cm) -- (\textwidth,1.2cm);
    \end{tikzpicture}\\%
}

\renewcommand{\DOTI}[1]{%
    \nointerlineskip\raggedright%
    \fboxsep=\myhi%
    \vskip-1ex%
    \colorbackchap{\parbox[t]{\mylen}{\CTV\FmTi{\colortitlechap#1}}}\par\nobreak%
    \vskip 40\p@%
}

\renewcommand{\DOTIS}[1]{%
    \fboxsep=0pt%
    \colorbackchap{\rule{0pt}{40pt}\parbox[b]{\textwidth}{\hfill}}\\%
    \nointerlineskip\raggedright%
    \fboxsep=\myhi%
    \colorbackchap{\parbox[t]{\mylen}{\CTV\FmTi{\colortitlechap#1}}}\par\nobreak%
    \vskip 40\p@%
}

\makeatother
%%*******************************************************************************
\begin{document}

    \chapter{Introduccion}
    \section{One}   
    \chapter{Technical content}
    \section{Two}
    
\end{document}

在此处输入图片描述

答案1

我尝试改变\@makechapterhead定义(参考:https://tex.stackexchange.com/a/471456/133968)。对于任何了解的人来说,该代码几乎是不言自明的tikz

\documentclass{report}

\usepackage{newpxtext}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xcolor}

\colorlet{chapterbg}{cyan}

% https://tex.stackexchange.com/a/471456/133968
\makeatletter
\def\@makechapterhead#1{%
%    \vspace*{50\p@}%
%    {\parindent \z@ \raggedright \normalfont
%        \ifnum \c@secnumdepth >\m@ne
%        \huge\bfseries
%        % \@chapapp\space % removed
%        \thechapter
%        \nobreakspace{}% \par\nobreak\vskip 20\p@ % replaced
%        \fi
%        \interlinepenalty\@M
%        \huge % \Huge % replaced
%        \bfseries #1\par\nobreak
%        \vskip 40\p@
%    }
    {
        \begin{tikzpicture}[x=1cm, y=1cm]
            \pgfmathsetmacro\lw{\linewidth/1cm} % linewidth in cm
            \pgfmathsetmacro\boxw{\lw} % box width
            \pgfmathsetmacro\boxh{0.25*\lw} % box height
            \pgfmathsetmacro\hruleloc{0.3*\boxh} % location of horizontal rule
            \pgfmathsetmacro\vruleloc{0.75*\boxw} % location of horizontal rule
            \pgfmathsetmacro\figwidth{0.9*(\boxw-\vruleloc)} % figure width
            \pgfmathsetmacro\figheight{0.9*(\boxh-\hruleloc)} % figure height
            
            % outer box
            \fill [chapterbg] (0,0) rectangle (\boxw,\boxh);
            
            % horizontal and vertical lines
            \draw [very thick, dotted] (0,\hruleloc) -- +(\boxw,0);
            \draw [very thick, dotted] (\vruleloc,0) -- +(0,\boxh);
            
            % "chapter"
            \node at (\vruleloc,\hruleloc) [anchor=north west, fill=black] {\color{white}\bfseries\itshape Chapter};
            
            % figure placeholder
            \node (fig) [text width=\figwidth cm, text height=\figheight cm, fill=gray, inner sep=0pt] at ($0.5*(\vruleloc,\hruleloc)+0.5*(\boxw,\boxh)$) {};
            \draw (fig.south west) -- (fig.north east);
            \draw (fig.south east) -- (fig.north west);
            
            % chapter name and counter
            \node [align=center, text width=0.8*\vruleloc cm] at ($0.5*(0,\hruleloc) + 0.5*(0.8*\vruleloc,\boxh)$) {\bfseries \LARGE\itshape #1};
            \node [left, scale=2] at ($0.5*(\vruleloc,\hruleloc)+0.5*(\vruleloc,\boxh)$) {\Huge \bfseries \thechapter};
        \end{tikzpicture}
    }
}
\makeatother

\begin{document}
    
\chapter{A long title\\[2pt]with custom line breaks}
    
\end{document}

在此处输入图片描述

相关内容