切片计数器

切片计数器

我正在使用 TiZ 定义我的章节和节样式,但节的编号在每一章之后都会重置。我想在章节之后连续编号我的节。

我使用>remset.sty:

\makeatletter
\@removefromreset{section}{chapter}
\makeatother

但是,当我为章节设置计数器时,它从新页面开始,而不是像未设置计数器时那样从章节旁边开始。

我为章节和部分定义的代码:

%CHAPTER DESIGN
\renewcommand{\thechapter}{\Roman{chapter}}
\titleformat{\chapter}[display]
    {\normalfont\huge\filleft}
    {}
    {20pt}
    {\begin{tikzpicture}[remember picture,overlay]
            \coordinate (A) at ([xshift=1cm,yshift=-1cm]current page.north west);
            %\draw (A)--++(5cm,0)--++(0,-5cm)--++(-5cm,0)--cycle;
            \node[above,brown] (chapname) at ([xshift=2.5cm,yshift=-4.8cm]A) {\chapnamefont C\;H\;Ư\;Ơ\;N\;G};
            \node[above=10pt,brown] (chapnum) at (chapname.north) {\chapnumfont \thechapter};
            \draw[dash pattern = on 2pt off 2pt,line width=2pt,orange] ([xshift=0.2cm,yshift=-0.2cm]chapname.south east)--++(0,5cm);
            \path ([xshift=0.4cm,yshift=2.6cm]chapname.south east) node[right,align=left] {
                        \begin{minipage}{15cm}
                                \begin{flushleft}
                                \chapterfont #1
                                \end{flushleft}
                        \end{minipage}
                        };
        \end{tikzpicture}
    }
\titlespacing*{\chapter}{0pt}{10pt}{0pt}

%SECTION DESIGN
\definecolor{xanh}{RGB}{2, 84, 100}
\definecolor{cam}{RGB}{229, 124, 35}
\renewcommand{\thesection}{\arabic{section}}
\titleformat{\section}[block]
{\normalfont\filleft}
{}
{20pt}
{%
\begin{tikzpicture}
    \coordinate (A) at (0,0);
    \draw[line width=2pt, xanh] (A) circle (1pt)--++(1.5cm,0cm) --++(0.866025cm,-0.5cm)--++(0.866025cm,0.5cm)--++(15cm,0cm) circle (1pt);
    \draw[line width=1.5pt,xanh,fill=cam] ([xshift=1.5cm,yshift=0.3cm]A)--++(0cm,1cm)--++(0.866025cm,0.5cm)--++(0.866025cm,-0.5cm)--++(0,-1cm)--++(-0.866025cm,-0.5cm)--cycle;
    \node[above,align=center] at ([xshift=0.75cm]A) {\Large\color{cam} Bài};
    \node[above right,align=left] at ([xshift=3.5cm]A) {
                            \begin{minipage}{14cm}
                                \bfseries\color{cam}\LARGE\MakeUppercase{ #1}
                            \end{minipage}};
    \node at ([xshift=2.366025cm,yshift=0.8cm]A) {\LARGE\bfseries\sffamily\color{white}\thesection};
\end{tikzpicture}
}%
\titlespacing*{\section}{0pt}{5pt}{5pt}
%FIRST SECTION OF CHAPTER NEXT TO CHAPTER, ELSE STARTS AT NEW PAGE
\pretocmd{\section}{%
  \ifnum\value{section}=0 \else\clearpage\fi
}{}{}

答案1

remreset是一个过时的软件包。

另外,除非真的需要,否则最好不要使用选项explicittitlesec而您的情况并非如此。但是请注意,未编号的章节会以奇怪的方式排版,如下例所示。您应该提供代码numberless(请参阅手册titlesec)。

\documentclass[a4paper]{book}
\usepackage[vietnamese]{babel}
\usepackage{titlesec}
\usepackage{tikz}

\counterwithout{section}{chapter}

\renewcommand{\thechapter}{\Roman{chapter}}
\newcommand{\chapterfont}{}% ???
\newcommand{\chapnamefont}{}% ???
\newcommand{\chapnumfont}{}% ???

\titleformat{\chapter}[display]
  {\normalfont\huge\filleft}
  {}
  {20pt}
  {\makechaptertitle}

\newcommand{\makechaptertitle}[1]{%
  \begin{tikzpicture}[remember picture,overlay]
    \coordinate (A) at ([xshift=1cm,yshift=-1cm]current page.north west);
    %\draw (A)--++(5cm,0)--++(0,-5cm)--++(-5cm,0)--cycle;
    \node[above,brown] (chapname) at ([xshift=2.5cm,yshift=-4.8cm]A)
      {\chapnamefont C\;H\;Ư\;Ơ\;N\;G};
    \node[above=10pt,brown] (chapnum) at (chapname.north)
      {\chapnumfont \thechapter};
    \draw[dash pattern = on 2pt off 2pt,line width=2pt,orange]
      ([xshift=0.2cm,yshift=-0.2cm]chapname.south east)--++(0,5cm);
    \path ([xshift=0.4cm,yshift=2.6cm]chapname.south east) node[right,align=left]
      {%
        \begin{minipage}{15cm}
        \raggedright
        \chapterfont #1
        \end{minipage}%
      };
  \end{tikzpicture}
}
\titlespacing*{\chapter}{0pt}{10pt}{0pt}

%SECTION DESIGN
\definecolor{xanh}{RGB}{2, 84, 100}
\definecolor{cam}{RGB}{229, 124, 35}

\renewcommand{\thesection}{\arabic{section}}

\titleformat{\section}[block]
  {\normalfont\filleft}
  {}
  {20pt}
  {\makesectiontitle}

\newcommand{\makesectiontitle}[1]{%
  \begin{tikzpicture}
    \coordinate (A) at (0,0);
    \draw[line width=2pt, xanh] (A) circle (1pt)
      --++(1.5cm,0cm) --++(0.866025cm,-0.5cm)--++(0.866025cm,0.5cm)--++(15cm,0cm)
      circle (1pt);
    \draw[line width=1.5pt,xanh,fill=cam] ([xshift=1.5cm,yshift=0.3cm]A)
      --++(0cm,1cm)--++(0.866025cm,0.5cm)--++(0.866025cm,-0.5cm)--++(0,-1cm)
      --++(-0.866025cm,-0.5cm)--cycle;
    \node[above,align=center] at ([xshift=0.75cm]A) {\Large\textcolor{cam}{Bài}};
    \node[above right,align=left] at ([xshift=3.5cm]A)
      {%
        \begin{minipage}{14cm}
        \bfseries\color{cam}\LARGE\MakeUppercase{ #1}
        \end{minipage}%
      };
    \node at ([xshift=2.366025cm,yshift=0.8cm]A)
      {\LARGE\bfseries\sffamily\textcolor{white}{\thesection}};
  \end{tikzpicture}
}
\titlespacing*{\section}{0pt}{5pt}{5pt}

%FIRST SECTION OF CHAPTER NEXT TO CHAPTER, ELSE STARTS AT NEW PAGE
\AddToHook{cmd/section/before}{\ifnum\value{section}=0 \else\clearpage\fi}

\begin{document}

\tableofcontents

\chapter{Test chapter}

\section{Test section}

Some text

\section{Test section in new page}

\end{document}

有更好的方法可以代替\@removefromreset\pretocmd

我提供了虚拟定义。对于您的下一个问题,请确保示例代码已准备好所有内容,以便可以编译而无需猜测(例如,我还必须猜测越南语)。

在此处输入图片描述

相关内容