如何在乳胶中抑制特定章节编号(同时保留设计)?

如何在乳胶中抑制特定章节编号(同时保留设计)?

我想隐藏序言编号“0”、内容“0”和索引编号“5”。这是我的 MWE

\documentclass[11pt]{book}
\usepackage[table]{xcolor}

\usepackage{enumerate}
\usepackage[shortlabels]{enumitem}
\usepackage{geometry}
     \geometry{a4paper, total={120mm,175mm},
             left=20mm,
             top=20mm,
             }
% Font Settings
\usepackage{avant} % Use the Avantgarde font for headings
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage[utf8]{inputenc} % Required for including letters with accents
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[sc]{mathpazo} % Use the Palatino font
\linespread{1.05}         % Palladio needs more leading (space between lines)
\usepackage{caption}
\usepackage{amscd,multicol}
\usepackage{textcomp,tikz}

%%% Bibliography
\usepackage[style=alphabetic,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
\addbibresource{./zbibliography.bib} % BibTeX bibliography file
\defbibheading{bibempty}{}

% Index
\usepackage{calc,epigraph,floatrow,systeme} % For simpler calculation - used for spacing the index letter headings correctly
%\renewcommand{\textflush}{flushepinormal}
\usepackage{makeidx} % Required to make an index
\makeindex % Tells LaTeX to create the files required for indexing

%----------------------------------------------------------------------------------------
\newcommand{\abs}[1]{\left\vert#1\right\vert}


%\usepackage{numcompress}
\usepackage{dsfont}
\usepackage{mathtools}
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}
%%%%%%%%%%%        %%%%%%%%%%%%%    %%%%%%%%%%%%     %%%%%%%%%%%%%%%%

\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}   % Horizontal rule

\usepackage{floatrow}

\usepackage{mathtools,stackengine}
\allowdisplaybreaks

%----------------------------------------------------------------------------------------
%   VARIOUS REQUIRED PACKAGES
%----------------------------------------------------------------------------------------

\usepackage{titlesec} % Allows customization of titles

\usepackage{graphicx} % Required for including pictures
\graphicspath{{Pictures/}{../Pictures/}} % Specifies the directory where pictures are stored
\makeatletter
\def\input@path{{Pictures/}{../Pictures/}}
\makeatother
\usepackage{wrapfig,lipsum,booktabs}
\usepackage{subfigure}

\usepackage{lipsum} % Inserts dummy text

\usepackage[english]{babel} % English language/hyphenation

\usepackage{enumitem} % Customize lists
\setlist{nolistsep} % Reduce spacing between bullet points and numbered lists

\usepackage{booktabs} % Required for nicer horizontal rules in tables

\usepackage{eso-pic} % Required for specifying an image background in the title page




%%%%%%% polynomial factorization style file %%%%%%%%%%%%%%%%%%%
\usepackage{polynom}


%%%%%%%%   Tikz draw matters   %%%%%%%%%%%%%%%%%%%%%

\usepackage{tikz} % Required for drawing custom shapes
\usetikzlibrary{arrows,decorations.markings,intersections, patterns,calc,angles,quotes,matrix,backgrounds,fit}% pgfplots.fillbetween}

\usepackage{pgfplots}

\usetikzlibrary{intersections,plotmarks}

\makeatletter
\def\markxof#1{
\pgf@process{#1}
\pgfmathparse{\pgf@x/\pgfplotsunitxlength +\pgfplots@data@scale@trafo@SHIFT@x)/10^\pgfplots@data@scale@trafo@EXPONENT@x}
}
\makeatother

%----------------------------------------------------------------------------------------
%   MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------

\usepackage{titletoc} % Required for manipulating the table of contents

\contentsmargin{0cm} % Removes the default margin
% Chapter text styling
\titlecontents{chapter}[1.25cm] % Indentation
{\addvspace{15pt}\normalsize\sffamily\bfseries} % Spacing and font options for chapters
{\color{ocre!60}\contentslabel[\normalsize\thecontentslabel]{1.2cm}\color{ocre}} % Chapter number
{}
{\color{ocre!60}\normalsize\sffamily\bfseries\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
% Section text styling
\titlecontents{section}[2.2cm] % Indentation
{\addvspace{5pt}\sffamily\small\bfseries} % Spacing and font options for sections
{\contentslabel[\thecontentslabel]{1.00cm}} % Section number
{}
{\sffamily\small\hfill\color{black}\thecontentspage} % Page number
[]
% Subsection text styling
\titlecontents{subsection}[2.6cm] % Indentation
{\addvspace{1pt}\sffamily\itshape} % Spacing and font options for subsections
{\contentslabel[\thecontentslabel]{1.20cm}} % Subsection number
{}
{\sffamily\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
[]
% Subsubsection text styling
\titlecontents{subsubsection}[3.0cm] % Indentation
{\addvspace{1pt}\sffamily\footnotesize} % Spacing and font options for subsubsections
{\contentslabel[\thecontentslabel]{1.20cm}} % Subsubsection number
{}
{\sffamily\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
[]

%----------------------------------------------------------------------------------------
%   MINI TABLE OF CONTENTS IN CHAPTER HEADS
%----------------------------------------------------------------------------------------

% Section text styling
\titlecontents{lsection}[0em] % Indendating
{\footnotesize\sffamily} % Font settings
{}
{}
{}

% Subsection text styling
\titlecontents{lsubsection}[.5em] % Indentation
{\normalfont\footnotesize\sffamily} % Font settings
{}
{}
{}

%----------------------------------------------------------------------------------------
%   PAGE HEADERS
%----------------------------------------------------------------------------------------

\usepackage{fancyhdr} % Required for header and footer configuration

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\color{blue}\sffamily\small\bfseries\chaptername\ \thechapter.\ #1}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{\sffamily\small\thesection\hspace{5pt}#1}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\color{blue}\sffamily\small\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark} % Print the current chapter name on the right side of even pages

\renewcommand{\headrulewidth}{0.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle 
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle 
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}

%----------------------------------------------------------------------------------------
%   THEOREM STYLES
%----------------------------------------------------------------------------------------

\usepackage{amsmath,amsfonts,amssymb,amsthm} % For math equations, theorems, symbols, etc

\newcommand{\intoo}[2]{\mathopen{]}#1\,;#2\mathclose{[}}
\newcommand{\ud}{\mathop{\mathrm{{}d}}\mathopen{}}
\newcommand{\intff}[2]{\mathopen{[}#1\,;#2\mathclose{]}}
\newtheorem{notation}{Notation}[chapter]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% dedicated to boxed/framed environements %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtheoremstyle{ocrenumbox}% % Theorem style name
{0pt}% Space above
{0pt}% Space below
{\normalfont}% % Body font
{}% Indent amount
{\small\bf\sffamily\color{ocre}}% % Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\color{ocre}\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries\color{black}---\nobreakspace#3.}} % Optional theorem note
\renewcommand{\qedsymbol}{$\blacksquare$}% Optional qed square

\newtheoremstyle{ocrenumex}% Theorem style name
{5pt}% Space above
{5pt}% Space below
{\normalfont}% Body font
{} % Indent amount
{\small\bf\sffamily}% Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily{\color{ocre}\tiny\ensuremath{\blacksquare}}\color{ocre}\nobreakspace\thmname{#1}\nobreakspace
        \thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries---\nobreakspace#3.}}% Optional theorem note

\newtheoremstyle{blacknumbox} % Theorem style name
{0pt}% Space above
{0pt}% Space below
{\normalfont}% Body font
{}% Indent amount
{\small\bf\sffamily}% Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries---\nobreakspace#3.}}% Optional theorem note

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{needspace}% http://ctan.org/pkg/needspace



%----------------------------------------------------------------------------------------
%   SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------

\makeatletter

\renewcommand{\section}{\@startsection{section}{1}{\z@}
{2ex \@plus 10ex \@minus -.2ex}
%{-2ex \@plus -1ex \@minus -.2ex}
%{10ex \@plus.2ex }
{1ex \@plus.2ex }
{\color{ocre}\normalfont\large\sffamily\bfseries}}
\renewcommand{\subsection}{\@startsection {subsection}{2}{\z@}
{-2ex \@plus -0.1ex \@minus -.2ex}
{0.3ex \@plus.2ex }
{\color{cyan}\normalfont\sffamily\bfseries}}
\renewcommand{\subsubsection}{\@startsection {subsubsection}{3}{\z@}
{-1ex \@plus -0.1ex \@minus -.1ex}
{.2ex \@plus.2ex }
{\color{red}\normalfont\small\sffamily\bfseries}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}
{-1ex \@plus-.2ex \@minus .1ex}
{.1ex}
{\normalfont\small\sffamily\bfseries}}

\usepackage{hyperref}
\hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor= ocre,bookmarks=true,bookmarksopen=false,pdftitle={Title},pdfauthor={Author}}

\titleformat{\chapter}[frame]
            {\color{cyan}\sc\bfseries\Large}
            {\filleft\sc{\chaptertitlename} \Huge\thechapter}
            {1ex}
            {%\titlerule\titlerule
            \vspace{0ex}%default is 0ex
            \centering }

\makeatother
%%%%%%%%%%thm-box%%%%%%%%%
\usepackage[many]{tcolorbox}

\definecolor{myblue}{RGB}{0,163,243}

\tcbset{mystyle/.style={
  breakable,
  enhanced,
  outer arc=0pt,
  arc=0pt,
  colframe=myblue,
  colback=myblue!20,
  attach boxed title to top left,
  boxed title style={
    colback=myblue,
    outer arc=0pt,
    arc=0pt,
    top=3pt,
    bottom=3pt,
    },
  fonttitle=\sffamily
  }
}

\newtcolorbox[auto counter,number within=section]{algorithm}[1][]{
  mystyle,
  title=Algorithm~\thetcbcounter,
  overlay unbroken and first={
      \path
        let
        \p1=(title.north east),
        \p2=(frame.north east)
        in
        node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
        at (title.east) {#1};
  }
}

\usepackage{titlesec}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\titleformat{\chapter}
{\normalfont\Large\filleft\bfseries}                    % format applied to label+text
{}                                                      % label
{1pc}                                                   % horizontal separation between label and title body
{%
    % draw a box around the chapter number
    \begin{tcolorbox}[
            enhanced,flushright upper,
            boxrule=1.4pt,
            colback=white,colframe=black!50!yellow,
            drop fuzzy midday shadow=black!50!yellow,
        width=2cm]
        \resizebox{1cm}{!}{\color{gray!80}\thechapter}%
    \end{tcolorbox}\Huge} % before the title body
[]                        % after the title body
\begin{document}


\frontmatter

\begingroup
\thispagestyle{empty}
\centering
\vspace*{0.75cm}
\par\normalfont\fontsize{35}{35}\sffamily\selectfont
%
{\color{red}  \HRule{1.15pt} }                 % Upper rule
{\color{red}{\bf Title}} \\[1.15cm]
\par\normalfont\fontsize{25}{25}\rmfamily\selectfont
{\Large John Doe%, \\[0.2cm]
}


\endgroup

\newpage
\thispagestyle{empty}

\noindent Copyright \copyright\ 2021  Publisher Here % Copyright notice

\newpage

\begingroup
\thispagestyle{empty}
\centering
\vspace*{1.0cm}
\par\normalfont\fontsize{35}{35}\sffamily\selectfont
Title\par % Book title
\vspace*{1.0cm}
\begin{center}
 {\huge \today}
 \vfill
\end{center}
\endgroup

\newpage

%
\chapter{Preface}
\tableofcontents % Print the table of contents itself
\pagestyle{fancy} % Print headers again

\linespread{1.13}
 \setlength{\parindent}{0pt}
 \setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}


\mainmatter


\pagenumbering{arabic}
 \setcounter{page}{1}

\chapter{chapter1}
\index{test}
\chapter{chapter2}
\chapter{chapter3}
\chapter{chapter4}
\chapter{chapter5}



\cleardoublepage
\phantomsection
\setlength{\columnsep}{0.75cm}
\addcontentsline{toc}{chapter}{\textcolor{ocre}{Index}}
\printindex

%----------------------------------------------------------------------------------------

\end{document} 

答案1

此代码产生满足您的三个要求的输出。

主要变化:

(1)用途imakeidx允许轻松重新定义索引环境,最重要的是只需要一次编译。

(2)删除编号为零的章节的框,包括索引,但保留章节标题的布局。

A

繁體

C

\documentclass[11pt]{book}
\usepackage[table]{xcolor}
\definecolor{ocre}{rgb}{0.69, 0.25, 0.21}% <<< added

\usepackage{enumerate}
\usepackage[shortlabels]{enumitem}
\usepackage{geometry}
     \geometry{a4paper, total={120mm,175mm},
             left=20mm,
             top=20mm,
             }
% Font Settings
\usepackage{avant} % Use the Avantgarde font for headings
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage[utf8]{inputenc} % Required for including letters with accents
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[sc]{mathpazo} % Use the Palatino font
\linespread{1.05}         % Palladio needs more leading (space between lines)
\usepackage{caption}
\usepackage{amscd,multicol}
\usepackage{textcomp,tikz}

%%% Bibliography
\usepackage[style=alphabetic,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
\addbibresource{./zbibliography.bib} % BibTeX bibliography file
\defbibheading{bibempty}{}

% Index
\usepackage{calc,epigraph,floatrow,systeme} % For simpler calculation - used for spacing the index letter headings correctly
%\renewcommand{\textflush}{flushepinormal}


%%  %\usepackage{makeidx} % Required to make an index
%%  %\makeindex % Tells LaTeX to create the files required for indexing



%----------------------------------------------------------------------------------------
\newcommand{\abs}[1]{\left\vert#1\right\vert}

%\usepackage{numcompress}
\usepackage{dsfont}
\usepackage{mathtools}
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}
%%%%%%%%%%%        %%%%%%%%%%%%%    %%%%%%%%%%%%     %%%%%%%%%%%%%%%%

\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}   % Horizontal rule

\usepackage{floatrow}

\usepackage{mathtools,stackengine}
\allowdisplaybreaks

%----------------------------------------------------------------------------------------
%   VARIOUS REQUIRED PACKAGES
%----------------------------------------------------------------------------------------

\usepackage{titlesec} % Allows customization of titles

\usepackage{graphicx} % Required for including pictures
\graphicspath{{Pictures/}{../Pictures/}} % Specifies the directory where pictures are stored
\makeatletter
\def\input@path{{Pictures/}{../Pictures/}}
\makeatother
\usepackage{wrapfig,lipsum,booktabs}
\usepackage{subfigure}

\usepackage{lipsum} % Inserts dummy text

\usepackage[english]{babel} % English language/hyphenation

\usepackage{enumitem} % Customize lists
\setlist{nolistsep} % Reduce spacing between bullet points and numbered lists

\usepackage{booktabs} % Required for nicer horizontal rules in tables

\usepackage{eso-pic} % Required for specifying an image background in the title page

%%%%%%% polynomial factorization style file %%%%%%%%%%%%%%%%%%%
\usepackage{polynom}

%%%%%%%%   Tikz draw matters   %%%%%%%%%%%%%%%%%%%%%

\usepackage{tikz} % Required for drawing custom shapes
\usetikzlibrary{arrows,decorations.markings,intersections, patterns,calc,angles,quotes,matrix,backgrounds,fit}% pgfplots.fillbetween}

\usepackage{pgfplots}

\usetikzlibrary{intersections,plotmarks}

\makeatletter
\def\markxof#1{
\pgf@process{#1}
\pgfmathparse{\pgf@x/\pgfplotsunitxlength +\pgfplots@data@scale@trafo@SHIFT@x)/10^\pgfplots@data@scale@trafo@EXPONENT@x}
}
\makeatother

%----------------------------------------------------------------------------------------
%   MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------

\usepackage{titletoc} % Required for manipulating the table of contents

\contentsmargin{0cm} % Removes the default margin
% Chapter text styling
\titlecontents{chapter}[1.25cm] % Indentation
{\addvspace{15pt}\normalsize\sffamily\bfseries} % Spacing and font options for chapters
{\color{ocre!60}\contentslabel[\normalsize\thecontentslabel]{1.2cm}\color{ocre}} % Chapter number
{}
{\color{ocre!60}\normalsize\sffamily\bfseries\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
% Section text styling
\titlecontents{section}[2.2cm] % Indentation
{\addvspace{5pt}\sffamily\small\bfseries} % Spacing and font options for sections
{\contentslabel[\thecontentslabel]{1.00cm}} % Section number
{}
{\sffamily\small\hfill\color{black}\thecontentspage} % Page number
[]
% Subsection text styling
\titlecontents{subsection}[2.6cm] % Indentation
{\addvspace{1pt}\sffamily\itshape} % Spacing and font options for subsections
{\contentslabel[\thecontentslabel]{1.20cm}} % Subsection number
{}
{\sffamily\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
[]
% Subsubsection text styling
\titlecontents{subsubsection}[3.0cm] % Indentation
{\addvspace{1pt}\sffamily\footnotesize} % Spacing and font options for subsubsections
{\contentslabel[\thecontentslabel]{1.20cm}} % Subsubsection number
{}
{\sffamily\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
[]

%----------------------------------------------------------------------------------------
%   MINI TABLE OF CONTENTS IN CHAPTER HEADS
%----------------------------------------------------------------------------------------

% Section text styling
\titlecontents{lsection}[0em] % Indendating
{\footnotesize\sffamily} % Font settings
{}
{}
{}

% Subsection text styling
\titlecontents{lsubsection}[.5em] % Indentation
{\normalfont\footnotesize\sffamily} % Font settings
{}
{}
{}

%----------------------------------------------------------------------------------------
%   PAGE HEADERS
%----------------------------------------------------------------------------------------

\usepackage{fancyhdr} % Required for header and footer configuration

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\color{blue}\sffamily\small\bfseries\chaptername\ \thechapter.\ #1}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{\sffamily\small\thesection\hspace{5pt}#1}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\color{blue}\sffamily\small\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark} % Print the current chapter name on the right side of even pages

\renewcommand{\headrulewidth}{0.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle 
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle 
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}

%----------------------------------------------------------------------------------------
%   THEOREM STYLES
%----------------------------------------------------------------------------------------

\usepackage{amsmath,amsfonts,amssymb,amsthm} % For math equations, theorems, symbols, etc

\newcommand{\intoo}[2]{\mathopen{]}#1\,;#2\mathclose{[}}
\newcommand{\ud}{\mathop{\mathrm{{}d}}\mathopen{}}
\newcommand{\intff}[2]{\mathopen{[}#1\,;#2\mathclose{]}}
\newtheorem{notation}{Notation}[chapter]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% dedicated to boxed/framed environements %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtheoremstyle{ocrenumbox}% % Theorem style name
{0pt}% Space above
{0pt}% Space below
{\normalfont}% % Body font
{}% Indent amount
{\small\bf\sffamily\color{ocre}}% % Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\color{ocre}\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries\color{black}---\nobreakspace#3.}} % Optional theorem note
\renewcommand{\qedsymbol}{$\blacksquare$}% Optional qed square

\newtheoremstyle{ocrenumex}% Theorem style name
{5pt}% Space above
{5pt}% Space below
{\normalfont}% Body font
{} % Indent amount
{\small\bf\sffamily}% Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily{\color{ocre}\tiny\ensuremath{\blacksquare}}\color{ocre}\nobreakspace\thmname{#1}\nobreakspace
        \thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries---\nobreakspace#3.}}% Optional theorem note

\newtheoremstyle{blacknumbox} % Theorem style name
{0pt}% Space above
{0pt}% Space below
{\normalfont}% Body font
{}% Indent amount
{\small\bf\sffamily}% Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries---\nobreakspace#3.}}% Optional theorem note

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{needspace}% http://ctan.org/pkg/needspace
    
%----------------------------------------------------------------------------------------
%   SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------

\makeatletter   
\renewcommand{\section}{\@startsection{section}{1}{\z@}
{2ex \@plus 10ex \@minus -.2ex}
%{-2ex \@plus -1ex \@minus -.2ex}
%{10ex \@plus.2ex }
{1ex \@plus.2ex }
{\color{ocre}\normalfont\large\sffamily\bfseries}}
\renewcommand{\subsection}{\@startsection {subsection}{2}{\z@}
{-2ex \@plus -0.1ex \@minus -.2ex}
{0.3ex \@plus.2ex }
{\color{cyan}\normalfont\sffamily\bfseries}}
\renewcommand{\subsubsection}{\@startsection {subsubsection}{3}{\z@}
{-1ex \@plus -0.1ex \@minus -.1ex}
{.2ex \@plus.2ex }
{\color{ocre}\normalfont\small\sffamily\bfseries}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}
{-1ex \@plus-.2ex \@minus .1ex}
{.1ex}
{\normalfont\small\sffamily\bfseries}}
\makeatother
    


%   \titleformat{\chapter}[frame]
%               {\color{cyan}\sc\bfseries\Large}
%               {\filleft\sc{\chaptertitlename} \Huge\thechapter}
%               {1ex}
%               {%\titlerule\titlerule
%               \vspace{0ex}%default is 0ex
%               \centering }


%%%%%%%%%%thm-box%%%%%%%%%
\usepackage[many]{tcolorbox}

\definecolor{myblue}{RGB}{0,163,243}

\tcbset{mystyle/.style={
  breakable,
  enhanced,
  outer arc=0pt,
  arc=0pt,
  colframe=myblue,
  colback=myblue!20,
  attach boxed title to top left,
  boxed title style={
    colback=myblue,
    outer arc=0pt,
    arc=0pt,
    top=3pt,
    bottom=3pt,
    },
  fonttitle=\sffamily
  }
}

\newtcolorbox[auto counter,number within=section]{algorithm}[1][]{
  mystyle,
  title=Algorithm~\thetcbcounter,
  overlay unbroken and first={
      \path
        let
        \p1=(title.north east),
        \p2=(frame.north east)
        in
        node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
        at (title.east) {#1};
  }
}

\usepackage{titlesec}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
    
%%%**************************************  changed and added
\titleformat{name=\chapter,numberless}
{\normalfont\Large\filleft\bfseries}                    % format applied to label+text
{}                                                      % label
{1pc}                                                   % horizontal separation between label and title body
{%
    % draw a box around the chapter number
        \vspace*{3ex}
    \begin{tcolorbox}[bicolor,
        colbacklower=white, boxrule=0pt,frame hidden,
        colback=white,
        width=2cm]
        \resizebox{1cm}{!}{\color{white}\thechapter}%
    \end{tcolorbox}\Huge}
[]                        % after the title body
    
\titleformat{name=\chapter}
{\normalfont\Large\filleft\bfseries}                    % format applied to label+text
{}                                                      % label
{1pc}                                                   % horizontal separation between label and title body
{%
    % draw a box around the chapter number
    \begin{tcolorbox}[
        enhanced,flushright upper,
        boxrule=1.4pt,
        colback=white,colframe=black!50!yellow,
        drop fuzzy midday shadow=black!50!yellow,
        width=2cm]
        \resizebox{1cm}{!}{\color{gray!80}\thechapter}%
    \end{tcolorbox}\Huge} % before the title body
[]                        % after the title body
                    
%% Make index   
\usepackage[original]{imakeidx}  % <<<< added   
\makeindex[title=Index]     

%Redefine the index environment
\makeatletter
\renewenvironment{theindex}{%
    \renewcommand{\leftmark}{Index}             
    \chapter*{\color{ocre} \Huge Index}     
    \setlength{\parskip}{\z@ \@plus .3\p@}%
    \setlength{\parfillskip}{\z@ \@plus 1fil}%
    \setlength{\columnsep}{0.75cm}
    \begin{multicols}{2}%
        \let\item\@idxitem
    }{\end{multicols}\clearpage}   
\makeatother

%%%**************************************  end changed and added
\usepackage{hyperref}
\hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor= red,bookmarks=true,bookmarksopen=false,pdftitle={Title},pdfauthor={Author}}


\linespread{1.13}

\begin{document}

\frontmatter

\begingroup
\thispagestyle{empty}
\centering
\vspace*{0.75cm}
\par\normalfont\fontsize{35}{35}\sffamily\selectfont
%
{\color{ocre}  \HRule{1.15pt} }                 % Upper rule
{\color{ocre}{\bf Title}} \\[1.15cm]
\par\normalfont\fontsize{25}{25}\rmfamily\selectfont
{\Large John Doe%, \\[0.2cm]
}       
\endgroup

\newpage
\thispagestyle{empty}

\noindent Copyright \copyright\ 2021  Publisher Here % Copyright notice

\newpage

\begingroup
\thispagestyle{empty}
\centering
\vspace*{1.0cm}
\par\normalfont\fontsize{35}{35}\sffamily\selectfont
Title\par % Book title
\vspace*{1.0cm}
\begin{center}
 {\huge \today}
 \vfill
\end{center}
\endgroup

\newpage

\chapter*{Preface}
\addcontentsline{toc}{chapter}{\textcolor{ocre}{Preface}}
\tableofcontents % Print the table of contents itself
\pagestyle{fancy} % Print headers again

\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}

\mainmatter

\pagenumbering{arabic}
 \setcounter{page}{1}

\chapter{chapter1}
\index{test}
\chapter{chapter2}
\chapter{chapter3}
\chapter{chapter4}
\chapter{chapter5}  

\cleardoublepage
\addcontentsline{toc}{chapter}{\textcolor{ocre}{Index}}
\printindex

%-------------------------------------------------------------

\end{document} 

答案2

你的序言非常混乱:你按照错误的顺序加载包并且忘记了你已经做了什么,其中许多包被加载了多次。

例如,你做了两次\titleformat{chapter}

你应该花一些时间把它清理干净。

无论如何,以下是您可以对未编号章节进行的操作。

\titleformat{name=\chapter}
  {\normalfont\Large\filleft\bfseries} % format applied to label+text
  {}                                   % label
  {1pc}                                % horizontal separation between label and title body
  {%
   % draw a box around the chapter number
   \begin{tcolorbox}[
     enhanced,
     flushright upper,
     boxrule=1.4pt,
     colback=white,
     colframe=black!50!yellow,
     drop fuzzy midday shadow=black!50!yellow,
     width=2cm,
   ]
   \resizebox{1cm}{!}{\color{gray!80}\thechapter}%
   \end{tcolorbox}\Huge
  } % before the title body

\titleformat{name=\chapter,numberless}
  {\normalfont\Large\filleft\bfseries} % format applied to label+text
  {}                                   % label
  {1pc}                                % horizontal separation between label and title body
  {\Huge} % before the title body

相关内容