使用 Overleaf 用 PDFLaTeX 自定义章节标题

使用 Overleaf 用 PDFLaTeX 自定义章节标题

描述:

你好,

我目前正在为我的本科论文编写模板,但遇到了一个我不知道如何解决的问题。我希望在每一章的开头都有这些漂亮的条纹,并且我希望它们从章节标题结束的地方一直延伸到页面顶部(我\epigraph也将它与修改相结合)。当章节标题只跨越一行时,没有问题,但当章节标题超过一行(2、3 等)时,我无法强制\tikzmark\titlesec显式选项)从最后一行开始。

下面提供的是我的 MWE。请原谅 tikz 的混乱,这是早期阶段,代码稍后会清理。我还提供了正确和不正确的图像。

梅威瑟:

\usepackage[newlinetospace,newparttoc,toctitles,explicit]{titlesec} % titlesec load
\usepackage{microtype} % \textls command

% PART FORMATTING %
    \titleformat{\part}[display]
        {\sffamily\color{ctublue}}%
        {\filleft\vspace{.5\textheight-8cm}\textls{PART}~\thepart}
        {0pt}
        {\filleft\huge\bfseries#1}%
        []

    \titleformat{name=\part,numberless}[display]
        {\sffamily\filleft\color{ctublue}}%
        {\vspace{.5\textheight-8cm}}
        {0pt}
        {\huge\bfseries#1}%
        []

% CHAPTER FORMATTING %
    \titleformat{\chapter}[display]%
        {\sffamily\color{ctublue}}
        {\textls{\MakeUppercase{\chaptertitlename}}~\thechapter}
        {0pt}%
        {\raggedright\color{ctublue}\bfseries\huge#1\tikzmark{CH1}
        \begin{tikzpicture}[overlay,remember picture,inner sep=0pt,outer sep=0pt]
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm]current page.west |- {pic cs:CH1}) -- (current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=11/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=11/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=22/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=22/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=33/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=33/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=44/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=44/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=55/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=55/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=66/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=66/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=77/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=77/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=88/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=88/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=99/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=99/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=110/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=110/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=121/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=121/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=132/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=132/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=143/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=143/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=154/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=154/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=165/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=165/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=176/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=176/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=187/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=187/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=198/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=198/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=209/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=209/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=220/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=220/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=231/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=231/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=242/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=242/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=253/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=253/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=264/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=264/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=275/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=275/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=286/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=286/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=297/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=297/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=308/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=308/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=319/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=319/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=330/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=330/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=341/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=341/2pt]current page.east |- {pic cs:CH1});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=352/2pt]current page.west |- {pic cs:CH1}) -- ([yshift=352/2pt]current page.east |- {pic cs:CH1});
        \end{tikzpicture}
        }
        []%

    \titleformat{name=\chapter,numberless}[display]
        {\sffamily\raggedright\color{ctublue}}
        {}
        {0pt}
        {\huge\bfseries#1\tikzmark{CH2}
        \begin{tikzpicture}[overlay,remember picture,inner sep=0pt,outer sep=0pt]
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm]current page.west |- {pic cs:CH2}) -- (current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=11/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=11/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=22/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=22/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=33/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=33/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=44/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=44/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=55/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=55/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=66/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=66/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=77/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=77/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=88/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=88/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=99/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=99/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=110/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=110/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=121/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=121/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=132/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=132/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=143/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=143/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=154/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=154/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=165/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=165/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=176/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=176/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=187/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=187/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=198/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=198/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=209/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=209/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=220/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=220/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=231/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=231/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=242/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=242/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=253/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=253/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=264/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=264/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=275/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=275/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=286/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=286/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=297/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=297/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=308/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=308/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=319/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=319/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=330/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=330/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=341/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=341/2pt]current page.east |- {pic cs:CH2});
            \draw[ctulightblue!50,line width=2pt] ([xshift=\textwidth+4cm,yshift=352/2pt]current page.west |- {pic cs:CH2}) -- ([yshift=352/2pt]current page.east |- {pic cs:CH2});
        \end{tikzpicture}
        }
        []

% SECTION FORMATTING %
    \titleformat{\section}[hang]
        {\sffamily\Large\color{ctublue}\filright}
        {}
        {0pt}
        {\color{ctublue}\bfseries\thesection\hspace{1pc}#1}
        [\vskip-5.5pt]

    \titleformat{name=\section,numberless}[hang]
        {\sffamily\Large\color{ctublue}\filright}
        {}
        {0pt}
        {\color{ctublue}\bfseries#1}
        [\vskip-5.5pt]

% SUBSECTION FORMATTING %
    \titleformat{\subsection}[hang]
        {\sffamily\large\color{ctublue}\filright}
        {}
        {0pt}
        {\bfseries\color{ctublue}\thesubsection\quad#1}
        []
    
    \titleformat{name=\subsection,numberless}[hang]
        {\sffamily\large\color{ctublue}\filright}
        {}
        {0pt}
        {\bfseries#1}
        []

% SUBSUBSECTION FORMATTING %
    \titleformat{\subsubsection}[hang]
        {\sffamily\large\color{ctublue}\filright}
        {}
        {0pt}
        {\bfseries#1}
        []

% PRETTY EPIGRAPH %
\newcommand{\epih}[4]{
\epigraphhead[#1]{\epigraph{\itshape#2}{\tikzmark{#4}#3}}

\begin{tikzpicture}[overlay,remember picture,inner sep=0pt,outer sep=0pt]
    \draw[ctulightblue!50,line width=2pt] ([xshift=12.5cm,yshift=16pt]current page.west |- {pic cs:#4}) -- ([yshift=16pt]current page.east |- {pic cs:#4});
\end{tikzpicture}
}

颜色定义如下:

\usepackage{xcolor}
    \definecolor{ctublue}{RGB}{4,100,188}
    \definecolor{ctulightblue}{cmyk}{.3,.13,0,0}
    \colorlet{ctulightbluebg}{ctulightblue!15!white}

图片: 正确的行为 在此处输入图片描述

不正确的行为 在此处输入图片描述

相关内容