更新命令 \chapter

更新命令 \chapter

我用一个完整的例子尝试了这个命题,但是章节没有被修改。

\documentclass[%
    paper=A4,                   % paper size --> A4 is default in Germany
    twoside=true,               % onesite or twoside printing
    openright,                  % doublepage cleaning ends up right side
    parskip=full,               % spacing value / method for paragraphs
    chapterprefix=true,         % prefix for chapter marks
    10pt,                       % font size
    headings=normal,            % size of headings
    bibliography=totoc,         % include bib in toc
    listof=totoc,               % include listof entries in toc
    titlepage=on,               % own page for each title page
    captions=tableabove,        % display table captions above the float env
    draft=false,                % value for draft version
 ]{scrreprt}%

 \usepackage{tikz}
 \usepackage{xcolor}

 \definecolor{ctcolormain}{cmyk}{1,.60,0,.40}
 \definecolor{ctcolorblack}{gray}{0}

 \newcommand\chapterpagedecoration{%
 \begin{tikzpicture}[remember picture,overlay,shorten >= -10pt]

 \coordinate (aux1) at ([yshift=-15pt]current page.north east);
 \coordinate (aux2) at ([yshift=-410pt]current page.north east);
 \coordinate (aux3) at ([xshift=-4.5cm]current page.north east);
 \coordinate (aux4) at ([yshift=-150pt]current page.north east);

 \begin{scope}[ctcolormain!40,line width=12pt,rounded corners=12pt]
 \draw
 (aux1) -- coordinate (a)
  ++(225:5) --
  ++(-45:5.1) coordinate (b);
 \draw[shorten <= -10pt]
  (aux3) --
  (a) --
  (aux1);
 \draw[opacity=0.6,ctcolormain,shorten <= -10pt]
  (b) --
  ++(225:2.2) --
  ++(-45:2.2);
\end{scope}
\draw[ctcolormain,line width=8pt,rounded corners=8pt,shorten <= -10pt]
  (aux4) --
  ++(225:0.8) --
  ++(-45:0.8);
 \begin{scope}[ctcolormain!70,line width=6pt,rounded corners=8pt]
 \draw[shorten <= -10pt]
  (aux2) --
  ++(225:3) coordinate[pos=0.45] (c) --
  ++(-45:3.1);
 \draw
  (aux2) --
  (c) --
  ++(135:2.5) --
  ++(45:2.5) --
  ++(-45:2.5) coordinate[pos=0.3] (d);   
 \draw 
  (d) -- +(45:1);
 \end{scope}
 \end{tikzpicture}%
}

 \let\cchapter\chapter
 \makeatletter
 \def\mchapter{% 
 \@ifstar{\@Starred}{\@nonStarred}%
 }
 \def\@Starred{%
 \@ifnextchar[%
 {\GenericWarning{}{Warning: A starred chapter can not have parameters. I am going to ignore them!}\@StarredWith}%
 {\@StarredWithout}%
 }      
 \def\@StarredWith[#1]#2{%
 \cchapter*{#2}%
 }
 \def\@StarredWithout#1{
 \cchapter*{#1}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\cchapter[#1]{#2}%
\clearpage
\refstepcounter{chapter}
\pagestyle{empty}

\begin{titlepage}

\noindent

\parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright \color{ctcolormain}
\titlefont Chapitre \thechapter \newline \newline \newline
\color{ctcolorblack} \subtitlefont #1}

 \null\vfill
 \vspace*{1cm}
\noindent
\hfill
\begin{minipage}{1\linewidth}
    \begin{abstract}\parbox[b]{\dimexpr\textwidth-2.5em\relax}{
#2}\end{abstract}
 \end{minipage}

 \chapterpagedecoration
 \end{titlepage}

 \addcontentsline{toc}{chapter}{\thechapter\hspace{1em}#1}
 \clearpage
 \pagestyle{plain}
}
\def\@nonStarredWithout#1{%
 \cchapter{#1}%
}
\makeatother

 \begin{document}

 \cchapter{First}{first comment}

 \cchapter{Second}

 \end{document}

我究竟做错了什么 ?

答案1

编辑原帖评论后

带有您的装饰的完整代码:

\documentclass[%
    paper=A4,                   % paper size --> A4 is default in Germany
    twoside=true,               % onesite or twoside printing
    openright,                  % doublepage cleaning ends up right side
    parskip=full,               % spacing value / method for paragraphs
    chapterprefix=true,         % prefix for chapter marks
    10pt,                       % font size
    headings=normal,            % size of headings
    bibliography=totoc,         % include bib in toc
    listof=totoc,               % include listof entries in toc
    titlepage=on,               % own page for each title page
    captions=tableabove,        % display table captions above the float env
    draft=false,                % value for draft version
 ]{scrreprt}%

 \usepackage{tikz}
 \usepackage{xcolor}

 \definecolor{ctcolormain}{cmyk}{1,.60,0,.40}
 \definecolor{ctcolorblack}{gray}{0}

 \newcommand\chapterpagedecoration{%
 \begin{tikzpicture}[remember picture,overlay,shorten >= -10pt]

 \coordinate (aux1) at ([yshift=-15pt]current page.north east);
 \coordinate (aux2) at ([yshift=-410pt]current page.north east);
 \coordinate (aux3) at ([xshift=-4.5cm]current page.north east);
 \coordinate (aux4) at ([yshift=-150pt]current page.north east);

 \begin{scope}[ctcolormain!40,line width=12pt,rounded corners=12pt]
 \draw
 (aux1) -- coordinate (a)
  ++(225:5) --
  ++(-45:5.1) coordinate (b);
 \draw[shorten <= -10pt]
  (aux3) --
  (a) --
  (aux1);
 \draw[opacity=0.6,ctcolormain,shorten <= -10pt]
  (b) --
  ++(225:2.2) --
  ++(-45:2.2);
\end{scope}
\draw[ctcolormain,line width=8pt,rounded corners=8pt,shorten <= -10pt]
  (aux4) --
  ++(225:0.8) --
  ++(-45:0.8);
 \begin{scope}[ctcolormain!70,line width=6pt,rounded corners=8pt]
 \draw[shorten <= -10pt]
  (aux2) --
  ++(225:3) coordinate[pos=0.45] (c) --
  ++(-45:3.1);
 \draw
  (aux2) --
  (c) --
  ++(135:2.5) --
  ++(45:2.5) --
  ++(-45:2.5) coordinate[pos=0.3] (d);   
 \draw 
  (d) -- +(45:1);
 \end{scope}
 \end{tikzpicture}%
 %\cleardoublepage% Uncomment if you want the content to start in next page after an empty one.
}

 \let\cchapter\chapter
 \makeatletter
 \def\mchapter{% 
 \@ifstar{\@Starred}{\@nonStarred}%
 }
 \def\@Starred{%
 \@ifnextchar[%
 {\GenericWarning{}{Warning: A starred chapter can not have parameters. I am going to ignore them!}\@StarredWith}%
 {\@StarredWithout}%
 }      
 \def\@StarredWith[#1]#2{%
 \cchapter*{#2}%
 \chapterpagedecoration
 }
 \def\@StarredWithout#1{
 \cchapter*{#1}%
 \chapterpagedecoration
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\cchapter[#1]{#2}%
\chapterpagedecoration
}
\def\@nonStarredWithout#1{%
 \cchapter{#1}%
 \chapterpagedecoration
}
\makeatother

 \begin{document}
 \tableofcontents

 \mchapter{First chapter}

 Some content

 \mchapter[Second changed toc title]{Second with other toc title}

 Some content 

 \mchapter*{Third Starred}

 Some content

 \section{test section}

 \mchapter{Fourth numbered 3}

 Final content

 \end{document}

旧答案

根据我在这里的回答:https://tex.stackexchange.com/a/380116/120578

您可以使用以下代码重新定义章节或部分或任何您想要的内容:

\let\oldchapter\chapter
\makeatletter
\def\mchapter{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred chapter can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%
\oldchapter*{#2}%
}
\def\@StarredWithout#1{
\oldchapter*{#1}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldchapter[#1]{#2}%
}
\def\@nonStarredWithout#1{%
\oldchapter{#1}%
}
\makeatother

在这段代码中,您可以做任何您想做的事情,并且您可以拥有一个带有可选参数的附加带星号的章节,以供其他用途,例如与章节原始名称不同的页眉。

此方法可处理分段命令的任何类型的更改。

相关内容