使用 classicthesis 时重新定义章节标题

使用 classicthesis 时重新定义章节标题

在这个论坛的帮助下,我可以为我的章节标题创建一个漂亮的徽标。我想用这个替换 classicthesis 模板中的章节标题。我认为模板中的其他所有内容都非常好。不幸的是,我无法重新创建一个可以重现我所有错误的 MWE。上次我被责骂要提供 MWE,所以我尝试创建一个至少可以重现我在这项工作中遇到的 6 个基本问题的 MWE,我认为这些问题都是相互关联的。我用 xelatex 编译!

  1. 我需要能够使用普通和无编号的章节标题。我在标题中定义了它们,然后定义了:

    \newcommand\mylayout{
    \titlespacing*{\chapter}{-106pt}{40pt}{30pt}
    \titlespacing*{name=\chapter,numberless}{-106pt}{56pt}{30pt}
    }
    

在文档中我需要调用\mylayout。这似乎很愚蠢。是否可以全局覆盖 classicthesis 章节标题,\titleformat{\chapter}\titlespacing而不更改 sty 文件?

  1. 我希望章节标题全部大写,并且首字母更大。在经典论文模板中,我认为以下几行可以实现我想要的效果.....但是,如果我更改上述示例,则不会发生任何变化,或者代码不再起作用。

    \titleformat{\section}[display]  
    {\relax}{\textsc{\MakeTextLowercase{\thesection}\qquad#1}}{1em}{\spacedlowsmallcaps }
    

基本上,我希望章节标题与节标题具有相同的行为,但我希望文本采用更大的大写字母,并且第一个字母应该比章节标题中的所有其他字母都大。

  1. 目前,所有我在经典论文风格文件中定义的 \section 标题/名称都消失了,只有 \section 编号可见。
  2. 章节名称的高度不正确。它们显然应该以“自定义框”为中心(我将链接到相应的线程)。我需要经常编译,直到章节名称和编号的位置不再移动?MWE 中未重现的事实是,在我的实际文档中,只有第一章处于指定的高度,所有后续章节都有额外的偏移量。
  3. 对于目录和 Bib,我实际上不需要特殊框。目前我创建了一个% DIRTY WORKAROUND TO REMOVE BOX FOR TOC在文本中标记的框。有没有办法简单地创建一个额外的自定义命令来创建不带框的章节标题?

  4. 目前我收到以下错误:

    Package scrlayer Error: cannot define `\newpagestyle'. }
    

我认为这是由于\usepackage[explicit]{titlesec} 如果我改变它的位置,整个代码就会失败。一个特别的问题似乎是碎片\setlength{\textwidth}.......。但我需要具有这些尺寸的文档!

这是“MWE”。它很长,但如果我排除一些内容,我就无法重现实际问题。例如,标题页会改变行为:

            %!TEX TS-program = xelatex
            \documentclass[
            twoside,
                a4paper,
                footinclude=true,
                headinclude=true
            ]{scrbook}
            \KOMAoptions{fontsize=11pt}
            \usepackage{lipsum}
            \usepackage[explicit]{titlesec} % If use titlesec here, i get: Package scrlayer Error: cannot define `\newpagestyle'. }
            \usepackage[
            dottedtoc,
            floatperchapter,
            parts
            ]{classicthesis}
            %\usepackage[explicit]{titlesec} % if i use titlesec here everything is messed up
            \setlength{\textwidth}{146.8mm} 
            \setlength{\oddsidemargin}{11.6mm} 
            \setlength{\evensidemargin}{0.8mm} 
            \setlength{\topmargin}{-2.2mm} 
            \setlength{\textheight}{221.9mm} 
            \setlength{\headheight}{14pt}

            \usepackage{tikz}
            \usetikzlibrary{external}
            \usetikzlibrary{calc}
            \usepackage{xcolor}
            \usepackage{color}
            \usetikzlibrary{intersections}

            \newcommand{\mytemplatecolor}{black}
            \newcommand{\mylogocolor}{white}
            \newcommand{\mychapterlabelcolor}{white}
            \newcommand{\mychapterboxcolortoc}{white}
            \newcommand{\mychapterboxcolor}{\mytemplatecolor}

            % FANCY CHAPTER HEADERS

            \newsavebox{\logo}
            \savebox{\logo}{%
                    \begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
                    \path[draw=\mylogocolor,fill=\mylogocolor,line join=miter,line cap=round,miter
                    limit=4.00,nonzero rule,dash phase=3.000pt,line width=0.000pt]
                    (178.4915,651.0411) .. controls (178.0358,651.0411) and (177.5801,651.0411) ..
                    (177.1244,651.0411) .. controls (177.1244,652.6787) and (177.1244,654.3163) ..
                    (177.1244,655.9539) .. controls (177.5801,655.9539) and (178.0358,655.9539) ..
                    (178.4915,655.9539) .. controls (178.4915,654.3163) and (178.4915,652.6787) ..
                    (178.4915,651.0411) -- cycle;
                    \path[xscale=-1.000,yscale=1.000,draw=\mylogocolor,fill=\mylogocolor,line join=miter,line
                    cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
                    width=0.000pt,rounded corners=0.0000cm] (-182.0794,658.5070) rectangle
                    (-177.1244,660.6401);
                    \path[xscale=-1.000,yscale=1.000,draw=\mylogocolor,fill=\mylogocolor,line join=miter,line
                    cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
                    corners=0.0000cm] (-280.8165,679.2454) rectangle (-193.6939,684.6964);
                    \path[xscale=-1.000,yscale=1.000,fill=\mylogocolor,nonzero rule,rounded
                    corners=0.0000cm] (-280.8165,694.2955) rectangle (-177.1245,696.3244);
                    \path[xscale=-1.000,yscale=1.000,draw=\mylogocolor,fill=\mylogocolor,line join=miter,line
                    cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
                    width=0.000pt,rounded corners=0.0000cm] (-280.8165,716.4833) rectangle
                    (-177.1245,721.9073);
                    \path[xscale=-1.000,yscale=1.000,draw=\mylogocolor,fill=\mylogocolor,line join=miter,line
                    cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
                    corners=0.0000cm] (-185.6345,669.1724) rectangle (-177.1244,673.9126);
                    \end{tikzpicture}}


             %  titlesec with option explicit is needed here
            % Chapter
             \newcommand*\chapterlabel{}
            \titleformat{\chapter}[display]  
            {\Huge\bfseries\sffamily\color{\mytemplatecolor}}
            {\gdef\chapterlabel{\thechapter\ }}    
            {0pt} % separation between label and chapter-title
            {\begin{tikzpicture}[remember picture,overlay]
                    \node[yshift=-8cm,xshift=0cm] at (current page.north west)
                    {\begin{tikzpicture}[remember picture, overlay]
                            \path[name path=mainbox,fill=\mytemplatecolor,\mytemplatecolor] (0,0)        rectangle (35.5mm,15mm);% mainbox
                            \node[line width=0pt, above right=0mm, draw=none, inner sep=0pt] at (0,0) {\resizebox{!}{15mm}{\usebox{\logo}}};
                            \node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum height=30mm,inner sep=0mm] at (current page.north west)
                            {\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$\color{white}\chapterlabel}};  
                            \node[anchor=north west,yshift=-7.2cm,xshift=37mm,text     width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north west)
                            {\parbox[top][30mm][t]{\textwidth}{\color{\mytemplatecolor}#1}};
                            \end{tikzpicture}
                    };
                    \gdef\chapterlabel{} % code before the title body
            \end{tikzpicture}
            }
            \titleformat{name=\chapter,numberless}[display]
            {\Huge\bfseries\sffamily\color{\mytemplatecolor}}
            {\gdef\chapterlabel{\thechapter\ }}  
            {0pt} % separation between label and chapter-title
            {\begin{tikzpicture}[remember picture,overlay]
            \node[yshift=-8cm,xshift=0cm] at (current page.north west)
            {\begin{tikzpicture}[remember picture, overlay]
                    \path[name path=mainbox,fill=\mychapterboxcolor,\mychapterboxcolor] (0,0)        rectangle (35.5mm,15mm);% mainbox
                    \node[line width=0pt, above right=0mm, draw=none, inner sep=0pt] at (0,0) {\resizebox{!}{15mm}{\usebox{\logo}}};
                    \node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum height=30mm,inner sep=0mm] at (current page.north west)
                    {\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$}
                    };
                    \node[anchor=north west,yshift=-7.2cm,xshift=37mm,text     width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north west)
                    {\parbox[top][30mm][t]{\textwidth}{\color{\mychapterboxcolor}#1}};
                    %{\parbox[top][30mm][t]{\textwidth}{\color{white}#1}};
                    \end{tikzpicture}
            };
            \gdef\chapterlabel{} % code before the title body
            \end{tikzpicture}
            }


            \newcommand\mylayout{
            \titlespacing*{\chapter}{-106pt}{40pt}{30pt}
            \titlespacing*{name=\chapter,numberless}{-106pt}{56pt}{30pt}
            }



            % FANCY CHAPTER HEADERS END!

            \begin{document}
            \mylayout
            \frontmatter
            \begin{titlepage}
                    % if you want the titlepage to be centered, uncomment and fine-tune the line below (KOMA classes environment)
                    %\begin{addmargin}[-1cm]{-3cm}
                    \begin{center}
                            \large
                            \begingroup
                            \spacedlowsmallcaps{A Thesis}
                            \endgroup
                            \hfill
                            \vfill
                            \begingroup
                            A dissertation submitted to the\\
                            \spacedlowsmallcaps{Institute of riding Lighnings}
                            \endgroup
                            \vfill
                            \begingroup
                            for the degree of\\
                            \spacedlowsmallcaps{Master of puppets}
                            \endgroup
                            \vfill
                            \begingroup
                            accepted on the recommendation of\\
                            Prof.\ Dr.\ Lars U.\\
                            Prof.\ Dr.\ James H., co-examiner\\
                            Prof.\ Dr.\ Kirk H., co-examiner
                            \endgroup
                            \vfill
                    \end{center}     
            \end{titlepage}

            % DIRTY WORKAROUND TO REMOVE BOX FOR TOC 
            \begingroup
            \renewcommand*{\contentsname}{Table of contents}%
            \renewcommand*\chapterlabel{}
            \titleformat{name=\chapter,numberless}[display]  
            {\Huge\bfseries\sffamily\color{\mytemplatecolor}}
            {\gdef\chapterlabel{\thechapter\ }}         
            {0pt} % separation between label and chapter-title
            {\begin{tikzpicture}[remember picture,overlay]
                    \node[yshift=-8cm,xshift=0cm] at (current page.north west)
                    {\begin{tikzpicture}[remember picture, overlay]
                            \path[name path=mainbox,fill=\mychapterboxcolortoc,\mychapterboxcolortoc] (0,0)        rectangle (35.5mm,15mm);% mainbox
                            \node[line width=0pt, above right=0mm, draw=none, inner sep=0pt] at (0,0) {\resizebox{!}{15mm}{\usebox{\logo}}};
                            \node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum height=30mm,inner sep=0mm] at (current page.north west)
                            {\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$}
                            };  
                            \node[anchor=north west,yshift=-7.2cm,xshift=37mm,text     width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north west)
                            {\parbox[top][30mm][t]{\textwidth}{\color{\mychapterboxcolor}#1}};
                            %{\parbox[top][30mm][t]{\textwidth}{\color{white}#1}};
                            \end{tikzpicture}
                    };
                    \gdef\chapterlabel{} % code before the title body
            \end{tikzpicture}
            }
            \titlespacing{name=\chapter,numberless}{-106pt}{140pt}{-160pt}

            \tableofcontents
            \addcontentsline{toc}{chapter}{Table of contents}
            \cleardoublepage
            \phantomsection
            \addcontentsline{toc}{chapter}{List of figures} 
            \listoffigures\thispagestyle{plain}
            \endgroup
            % DIRTY WORKAROUND TO REMOVE BOX FOR TOC END!
            \mainmatter
            \mylayout
            \chapter{Methods}
            \lipsum[1]
            \section{section names are gone}
            Somehow the section names disappear?
            \par
            \lipsum[1]
            \section{section names are gone too}
            \lipsum[2]
            \lipsum[1]
            \chapter{More Results}
            \lipsum[1]
            \lipsum[2]
            \chapter{Even More Results}
            \lipsum[1]
            \section{section names are gone}
            Somehow the section names disappear?
            \par
            \lipsum[1]
            \section{section names are gone too}
            \lipsum[2]
            \lipsum[1]
            \chapter*{Numberless Results}
            \lipsum[1]
            \end{document}

以下是一个解决方案的链接以及我最初的 Ticks 问题 解决方案部分首字母大写蜱虫问题

答案1

很多事情都在发生。不过每次只发生一件事。

有一种方法可以将图片添加到classicthesis章节标题中。

因为该classicthesis包已经titlesec在内部调用,所以没有必要再次调用它(并且我们还需要保持其他所有classicthesis操作的完整性titlesec)。

章节中有两个\titleformats classicthesis,一个表示带线标题,另一个则不是。

插入章节徽标/图片(“设备”)的最佳位置\titleformat可能是在其参数的末尾<after-code>

一般而言:

\titleformat{\chapter}[display]
    {<format>}
    {<label>}
    {<sep>}
    {<before-code>}
    [<after-code>]

并且,因为它是一张 TikZ 图片,我们将使用通常的 调整它相对于其锚点的位置yshift= xshift=,得到:

带徽标的章节

(我用来自本网站 TikZ 问题的一个更简单、更实用的随机示例(添加了颜色,因此看起来让人联想到立方晶体结构)替换了原始的复杂徽标代码,并且我还删除了所有页面布局调整以获得更清晰的测试平台。根据需要将它们全部重新调整回来。)

yshift= xshift=由于两种章节样式的布局不同,因此每种样式的tikz也会不同。我们仅使用一种章节样式作为演示。

我们将把 tikz 图片存储在一个宏中,当在当前页面上实际排版章节和组装页面时,该宏\chaptikz将输入一个参数,即文本,作为页面锚点。current

\newcommand\chaptikz[1]{
      \begin{tikzpicture}[remember picture,overlay]
       \node
        at (#1 page.north west) {A};
    \usebox{\logo}
      \end{tikzpicture}%
  }

该命令的使用方式如下:

\chaptikz{current}

现在,不是打印未编号的\chapter*s 的徽标图像,我们需要某种新的 IF 来充当开关。有多种方法可以做到这一点。一种基本的方法是使用newif

\newif\ifmystar

使用 IF 可以像这样:

\ifmystar\else{\chaptikz{current}}\fi

如果有星号(这是带星号的章节(或目录)),则不执行任何操作,\else只执行我们的徽标。

使用 来登录\mystarfalse,使用 来注销\mystartrue

        \mystartrue
        \chapter*{Numberless Results}
        \mystarfalse

无徽标星标章节

此外,目录和图表列表是章节类的对象,因此关闭它们的徽标也很方便。

\mystartrue
            \tableofcontents
            \listoffigures
\mystarfalse

代码titleformat最终如下:

    \titleformat{\chapter}[display]%
    {\relax}%
    {\mbox{}\oldmarginpar{\vspace*{-3\baselineskip}\color{CTsemi}\chapterNumber\thechapter}}{0pt}%
    {\raggedright\spacedallcaps}%
[\normalsize\vspace*{.8\baselineskip}\titlerule\ifmystar\else{\chaptikz{current}}\fi]%

平均能量损失

 %!TEX TS-program = xelatex
            \documentclass[
            twoside,
                a4paper,
                footinclude=true,
                headinclude=true
            ]{scrbook}
            \KOMAoptions{fontsize=11pt}
            \usepackage{lipsum}
%            \usepackage[explicit]{titlesec} % If use titlesec here, i get: Package scrlayer Error: cannot define `\newpagestyle'. }
            \usepackage[
            dottedtoc,
            floatperchapter,
            parts,
%            linedheaders,
            ]{classicthesis}

            \usepackage{tikz}
            \usetikzlibrary{external}
            \usetikzlibrary{calc}
            \usepackage{xcolor}
            \usetikzlibrary{intersections}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.text}

            \newcommand{\mytemplatecolor}{blue}
            \newcommand{\mylogocolor}{yellow!32}
            \newcommand{\mychapterlabelcolor}{green}
            \newcommand{\mychapterboxcolortoc}{violet}
            \newcommand{\mychapterboxcolor}{\mytemplatecolor}

            \newsavebox{\logo}
            \savebox{\logo}{%
 \begin{tikzpicture}[scale=0.8,remember picture,overlay,yshift=5.5em,xshift=16em]
\tikzstyle{v}=[circle, minimum size=2mm,inner sep=0pt,draw,violet,fill=yellow]
\foreach \i in {1,...,8}
\foreach \j in {1,...,3}
\node[v]
(G-\i-\j) at (\i,\j) {};
\foreach \i in {1,...,8}
\foreach \j/\o in {1/2,2/3}
\draw[->, green]
(G-\i-\j) -- (G-\i-\o);
\foreach \i/\n in
{1/2,2/3,3/4,4/5,5/6,6/7,7/8}
\foreach \j/\o in {1/2,2/3} {
\draw[->,blue,thick] (G-\i-\j) -- (G-\n-\o);
\draw[->,red] (G-\n-\j) -- (G-\i-\o);
}
\end{tikzpicture}
}




\newcommand\chaptikz[1]{
             \begin{tikzpicture}[remember picture,overlay]
                    \node
                     at (#1 page.north west) {A};
                        \usebox{\logo}
            \end{tikzpicture}%
            }

%%\titleformat{<command>}[<shape>]
%   {<format>}
%   {<label>}
%   {<sep>}
%   {<before-code>}
%   [<after-code>]

%lined headers:
%    \titleformat{\chapter}[display]%
%    {\relax}%
%    {\raggedleft{\color{CTsemi}\chapterNumber\thechapter} \\ }%
%    {0pt}%
%    {\titlerule\vspace*{.9\baselineskip}\raggedright\spacedallcaps}%
%    [\normalsize\vspace*{.8\baselineskip}\titlerule\chaptikz{current}]%

\newif\ifmystar
\mystarfalse

    \titleformat{\chapter}[display]%
    {\relax}{\mbox{}\oldmarginpar{\vspace*{-3\baselineskip}\color{CTsemi}\chapterNumber\thechapter}}{0pt}%
    {\raggedright\spacedallcaps}[\normalsize\vspace*{.8\baselineskip}\titlerule\ifmystar\else{\chaptikz{current}}\fi]%


            \begin{document}
            \frontmatter
            \begin{titlepage}
                    \begin{center}
                            \large
                            \begingroup
                            \spacedlowsmallcaps{A Thesis}
                            \endgroup
                            \hfill
                            \vfill
                            \begingroup
                            A dissertation submitted to the\\
                            \spacedlowsmallcaps{Institute of Riding Lightning}
                            \endgroup
                            \vfill
                            \begingroup
                            for the degree of\\
                            \spacedlowsmallcaps{MP -- Master of Puppets}
                            \endgroup
                            \vfill
                            \begingroup
                            accepted on the recommendation of\\
                            Prof.\ Dr.\ XXX.\\
                            Prof.\ Dr.\ YYY., co-examiner\\
                            Prof.\ Dr.\ ZZZ H., co-examiner
                            \endgroup
                            \vfill
                    \end{center}     
            \end{titlepage}



\mystartrue
            \tableofcontents
            \listoffigures
\mystarfalse
            \mainmatter
            \chapter{Methods}
             qwerty
%             \chaptikz{current}
 <<<<<<<<<<<<<<<<<<<<
           \section{Section}
            Somehow the section names are section names.
            \par
            \lipsum[1]
            \section{Another Section}
            \lipsum[2]
            \lipsum[1]
            \chapter{More Results}
            \lipsum[1]
            \lipsum[2]
            \chapter{Even More Results}
            \lipsum[1]
            \mystartrue
            \chapter*{Numberless Results}
            \ifmystar{tr}\else{F}\fi \\ \lipsum[1]
            \mystarfalse
            \chapter{And Conclusion}
            \lipsum[1]            
\end{document}

相关内容