TransWikia.com

How to suppress specific chapter number (while keeping the design) in latex?

TeX - LaTeX Asked by albo on April 7, 2021

I want to suppress the preface number "0”, contents "0”, and index number "5”. Here is my 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]{leftvert#1rightvert}


%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
definput@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
defmarkxof#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}normalsizesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[normalsizethecontentslabel]{1.2cm}color{ocre}} % Chapter number
{}
{color{ocre!60}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{section}[2.2cm] % Indentation
{addvspace{5pt}sffamilysmallbfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.00cm}} % Section number
{}
{sffamilysmallhfillcolor{black}thecontentspage} % Page number
[]
% Subsection text styling
titlecontents{subsection}[2.6cm] % Indentation
{addvspace{1pt}sffamilyitshape} % 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}sffamilyfootnotesize} % 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
{footnotesizesffamily} % Font settings
{}
{}
{}

% Subsection text styling
titlecontents{lsubsection}[.5em] % Indentation
{normalfontfootnotesizesffamily} % Font settings
{}
{}
{}

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

usepackage{fancyhdr} % Required for header and footer configuration

pagestyle{fancy}
renewcommand{chaptermark}[1]{markboth{color{blue}sffamilysmallbfserieschaptername thechapter. #1}{}} % Chapter text font settings
renewcommand{sectionmark}[1]{markright{sffamilysmallthesectionhspace{5pt}#1}{}} % Section text font settings
fancyhf{} fancyhead[LE,RO]{color{blue}sffamilysmallthepage} % 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}{
clearpageifoddc@pageelse
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,;#2mathclose{[}}
newcommand{ud}{mathop{mathrm{{}d}}mathopen{}}
newcommand{intff}[2]{mathopen{[}#1,;#2mathclose{]}}
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
{smallbfsffamilycolor{ocre}}% % Theorem head font
{;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{smallsffamilycolor{ocre}thmname{#1}nobreakspacethmnumber{@ifnotempty{#1}{}@upn{#2}}% Theorem text (e.g. Theorem 2.1)
thmnote{nobreakspacethethm@notefontsffamilybfseriescolor{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
{smallbfsffamily}% Theorem head font
{;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{smallsffamily{color{ocre}tinyensuremath{blacksquare}}color{ocre}nobreakspacethmname{#1}nobreakspace
        thmnumber{@ifnotempty{#1}{}@upn{#2}}% Theorem text (e.g. Theorem 2.1)
thmnote{nobreakspacethethm@notefontsffamilybfseries---nobreakspace#3.}}% Optional theorem note

newtheoremstyle{blacknumbox} % Theorem style name
{0pt}% Space above
{0pt}% Space below
{normalfont}% Body font
{}% Indent amount
{smallbfsffamily}% Theorem head font
{;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{smallsffamilythmname{#1}nobreakspacethmnumber{@ifnotempty{#1}{}@upn{#2}}% Theorem text (e.g. Theorem 2.1)
thmnote{nobreakspacethethm@notefontsffamilybfseries---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}normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{0.3ex @plus.2ex }
{color{cyan}normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-1ex @plus -0.1ex @minus -.1ex}
{.2ex @plus.2ex }
{color{red}normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-1ex @plus-.2ex @minus .1ex}
{.1ex}
{normalfontsmallsffamilybfseries}}

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}scbfseriesLarge}
            {filleftsc{chaptertitlename} Hugethechapter}
            {1ex}
            {%titleruletitlerule
            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}
{normalfontLargefilleftbfseries}                    % 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}
parnormalfontfontsize{35}{35}sffamilyselectfont
%
{color{red}  HRule{1.15pt} }                 % Upper rule
{color{red}{bf Title}} [1.15cm]
parnormalfontfontsize{25}{25}rmfamilyselectfont
{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}
parnormalfontfontsize{35}{35}sffamilyselectfont
Titlepar % 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} 

2 Answers

This code produces the output that meets your three requirements.

Main changes:

(1) Uses imakeidx which allows easy redefinition of the index environment and, best of all, only requires one compilation.

(2) Eliminate the boxes of the chapters numbered with zero, including the index, while keeping the layout of the chapter heading.

A

bx

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]{leftvert#1rightvert}

%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
definput@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
defmarkxof#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}normalsizesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[normalsizethecontentslabel]{1.2cm}color{ocre}} % Chapter number
{}
{color{ocre!60}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{section}[2.2cm] % Indentation
{addvspace{5pt}sffamilysmallbfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.00cm}} % Section number
{}
{sffamilysmallhfillcolor{black}thecontentspage} % Page number
[]
% Subsection text styling
titlecontents{subsection}[2.6cm] % Indentation
{addvspace{1pt}sffamilyitshape} % 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}sffamilyfootnotesize} % 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
{footnotesizesffamily} % Font settings
{}
{}
{}

% Subsection text styling
titlecontents{lsubsection}[.5em] % Indentation
{normalfontfootnotesizesffamily} % Font settings
{}
{}
{}

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

usepackage{fancyhdr} % Required for header and footer configuration

pagestyle{fancy}
renewcommand{chaptermark}[1]{markboth{color{blue}sffamilysmallbfserieschaptername thechapter. #1}{}} % Chapter text font settings
renewcommand{sectionmark}[1]{markright{sffamilysmallthesectionhspace{5pt}#1}{}} % Section text font settings
fancyhf{} fancyhead[LE,RO]{color{blue}sffamilysmallthepage} % 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}{
clearpageifoddc@pageelse
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,;#2mathclose{[}}
newcommand{ud}{mathop{mathrm{{}d}}mathopen{}}
newcommand{intff}[2]{mathopen{[}#1,;#2mathclose{]}}
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
{smallbfsffamilycolor{ocre}}% % Theorem head font
{;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{smallsffamilycolor{ocre}thmname{#1}nobreakspacethmnumber{@ifnotempty{#1}{}@upn{#2}}% Theorem text (e.g. Theorem 2.1)
thmnote{nobreakspacethethm@notefontsffamilybfseriescolor{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
{smallbfsffamily}% Theorem head font
{;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{smallsffamily{color{ocre}tinyensuremath{blacksquare}}color{ocre}nobreakspacethmname{#1}nobreakspace
        thmnumber{@ifnotempty{#1}{}@upn{#2}}% Theorem text (e.g. Theorem 2.1)
thmnote{nobreakspacethethm@notefontsffamilybfseries---nobreakspace#3.}}% Optional theorem note

newtheoremstyle{blacknumbox} % Theorem style name
{0pt}% Space above
{0pt}% Space below
{normalfont}% Body font
{}% Indent amount
{smallbfsffamily}% Theorem head font
{;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{smallsffamilythmname{#1}nobreakspacethmnumber{@ifnotempty{#1}{}@upn{#2}}% Theorem text (e.g. Theorem 2.1)
thmnote{nobreakspacethethm@notefontsffamilybfseries---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}normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{0.3ex @plus.2ex }
{color{cyan}normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-1ex @plus -0.1ex @minus -.1ex}
{.2ex @plus.2ex }
{color{ocre}normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-1ex @plus-.2ex @minus .1ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
makeatother
    


%   titleformat{chapter}[frame]
%               {color{cyan}scbfseriesLarge}
%               {filleftsc{chaptertitlename} Hugethechapter}
%               {1ex}
%               {%titleruletitlerule
%               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}
{normalfontLargefilleftbfseries}                    % 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}
{normalfontLargefilleftbfseries}                    % 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 .3p@}%
    setlength{parfillskip}{z@ @plus 1fil}%
    setlength{columnsep}{0.75cm}
    begin{multicols}{2}%
        letitem@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}
parnormalfontfontsize{35}{35}sffamilyselectfont
%
{color{ocre}  HRule{1.15pt} }                 % Upper rule
{color{ocre}{bf Title}} [1.15cm]
parnormalfontfontsize{25}{25}rmfamilyselectfont
{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}
parnormalfontfontsize{35}{35}sffamilyselectfont
Titlepar % 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} 

Correct answer by Simon Dispa on April 7, 2021

Your preamble is a very big mess: you load packages in the wrong order and lose track of what you have already done, loading many of them more than once.

For instance, you're doing twice titleformat{chapter}.

You should dedicate some time to clean it up.

Anyway, here's how you can do for the unnumbered chapters.

titleformat{name=chapter}
  {normalfontLargefilleftbfseries} % 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}
  {normalfontLargefilleftbfseries} % format applied to label+text
  {}                                   % label
  {1pc}                                % horizontal separation between label and title body
  {Huge} % before the title body

Answered by egreg on April 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP