Automatic change of the color for each part

Multi tool use
With reference to a question previously asked,
Replace part of the appendix of Legrand Orange Book with letters of the alphabet instead of arabic numbers
I would like to understand which commands are necessary to alternate or change randomly the colors of each part with between 10 colors chosen at my pleasure.
I have selected only the part of the .tex file that refers to Legrande Orange Book that I considered necessary for the correct compilation of the code that I reported.
To be more clear I would like each part to be coloured, at random, not with the same colour.
Here's an image of two snapshots made with paint.
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
end{document}
color typography parts
|
show 3 more comments
With reference to a question previously asked,
Replace part of the appendix of Legrand Orange Book with letters of the alphabet instead of arabic numbers
I would like to understand which commands are necessary to alternate or change randomly the colors of each part with between 10 colors chosen at my pleasure.
I have selected only the part of the .tex file that refers to Legrande Orange Book that I considered necessary for the correct compilation of the code that I reported.
To be more clear I would like each part to be coloured, at random, not with the same colour.
Here's an image of two snapshots made with paint.
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
end{document}
color typography parts
2
Off-topic: You have to loadusepackage[svgnames,dvipsnames]{xcolor}
beforeusepackage{tikz}
to avoid anOption clash
error.
– Phelype Oleinik
Jan 12 at 21:21
1
May I ask why do you want to introduce such a feature? Just because it is possible? Alternating colors for titles? This is not a proof of good typography.
– Christian Hupfer
Jan 12 at 21:54
At the moment, your document shows apricot-like colored rectangles only
– Christian Hupfer
Jan 12 at 21:56
@ChristianHupfer I like pastel colors and in my opinion it will also provide a better aesthetic for my book. I simply extrapolated the entire code. In summary, I only took the compilable part.
– Sebastiano
Jan 12 at 21:58
My code was edited and I putusepackage[svgnames,dvipsnames]{xcolor}
beforeusepackage{tikz}
and put typography.
– Sebastiano
Jan 12 at 22:01
|
show 3 more comments
With reference to a question previously asked,
Replace part of the appendix of Legrand Orange Book with letters of the alphabet instead of arabic numbers
I would like to understand which commands are necessary to alternate or change randomly the colors of each part with between 10 colors chosen at my pleasure.
I have selected only the part of the .tex file that refers to Legrande Orange Book that I considered necessary for the correct compilation of the code that I reported.
To be more clear I would like each part to be coloured, at random, not with the same colour.
Here's an image of two snapshots made with paint.
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
end{document}
color typography parts
With reference to a question previously asked,
Replace part of the appendix of Legrand Orange Book with letters of the alphabet instead of arabic numbers
I would like to understand which commands are necessary to alternate or change randomly the colors of each part with between 10 colors chosen at my pleasure.
I have selected only the part of the .tex file that refers to Legrande Orange Book that I considered necessary for the correct compilation of the code that I reported.
To be more clear I would like each part to be coloured, at random, not with the same colour.
Here's an image of two snapshots made with paint.
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
end{document}
color typography parts
color typography parts
edited Jan 12 at 22:01
Sebastiano
asked Jan 12 at 21:10
SebastianoSebastiano
9,60741858
9,60741858
2
Off-topic: You have to loadusepackage[svgnames,dvipsnames]{xcolor}
beforeusepackage{tikz}
to avoid anOption clash
error.
– Phelype Oleinik
Jan 12 at 21:21
1
May I ask why do you want to introduce such a feature? Just because it is possible? Alternating colors for titles? This is not a proof of good typography.
– Christian Hupfer
Jan 12 at 21:54
At the moment, your document shows apricot-like colored rectangles only
– Christian Hupfer
Jan 12 at 21:56
@ChristianHupfer I like pastel colors and in my opinion it will also provide a better aesthetic for my book. I simply extrapolated the entire code. In summary, I only took the compilable part.
– Sebastiano
Jan 12 at 21:58
My code was edited and I putusepackage[svgnames,dvipsnames]{xcolor}
beforeusepackage{tikz}
and put typography.
– Sebastiano
Jan 12 at 22:01
|
show 3 more comments
2
Off-topic: You have to loadusepackage[svgnames,dvipsnames]{xcolor}
beforeusepackage{tikz}
to avoid anOption clash
error.
– Phelype Oleinik
Jan 12 at 21:21
1
May I ask why do you want to introduce such a feature? Just because it is possible? Alternating colors for titles? This is not a proof of good typography.
– Christian Hupfer
Jan 12 at 21:54
At the moment, your document shows apricot-like colored rectangles only
– Christian Hupfer
Jan 12 at 21:56
@ChristianHupfer I like pastel colors and in my opinion it will also provide a better aesthetic for my book. I simply extrapolated the entire code. In summary, I only took the compilable part.
– Sebastiano
Jan 12 at 21:58
My code was edited and I putusepackage[svgnames,dvipsnames]{xcolor}
beforeusepackage{tikz}
and put typography.
– Sebastiano
Jan 12 at 22:01
2
2
Off-topic: You have to load
usepackage[svgnames,dvipsnames]{xcolor}
before usepackage{tikz}
to avoid an Option clash
error.– Phelype Oleinik
Jan 12 at 21:21
Off-topic: You have to load
usepackage[svgnames,dvipsnames]{xcolor}
before usepackage{tikz}
to avoid an Option clash
error.– Phelype Oleinik
Jan 12 at 21:21
1
1
May I ask why do you want to introduce such a feature? Just because it is possible? Alternating colors for titles? This is not a proof of good typography.
– Christian Hupfer
Jan 12 at 21:54
May I ask why do you want to introduce such a feature? Just because it is possible? Alternating colors for titles? This is not a proof of good typography.
– Christian Hupfer
Jan 12 at 21:54
At the moment, your document shows apricot-like colored rectangles only
– Christian Hupfer
Jan 12 at 21:56
At the moment, your document shows apricot-like colored rectangles only
– Christian Hupfer
Jan 12 at 21:56
@ChristianHupfer I like pastel colors and in my opinion it will also provide a better aesthetic for my book. I simply extrapolated the entire code. In summary, I only took the compilable part.
– Sebastiano
Jan 12 at 21:58
@ChristianHupfer I like pastel colors and in my opinion it will also provide a better aesthetic for my book. I simply extrapolated the entire code. In summary, I only took the compilable part.
– Sebastiano
Jan 12 at 21:58
My code was edited and I put
usepackage[svgnames,dvipsnames]{xcolor}
before usepackage{tikz}
and put typography.– Sebastiano
Jan 12 at 22:01
My code was edited and I put
usepackage[svgnames,dvipsnames]{xcolor}
before usepackage{tikz}
and put typography.– Sebastiano
Jan 12 at 22:01
|
show 3 more comments
1 Answer
1
active
oldest
votes
Changing the color on a random base can be done easily with pdflatex
or lualatex
and applying clist_rand_item:N
for example, which contains list of colors.
Use SebastianosColorList{Red,...,}
to store the color names and a colorlet{ocre}{RandomColor}
to change from ocre
to a random color.
The macro SebastianosRandSeed
sets the random number seed, with the given seed 12345678
and the used colors the sequence of part colors is
red, blue, yellow, brown, green (in pastel like variations)
Please note that random numbers are random in the sense that red
could be followed by red
as well, i.e. there is no guarantee that no repetition will occur.
Please note also that this code does not work with XeLaTeX
, since the random number generator code of expl3
is not working with XeLaTeX
.
I will update the code ...
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
usepackage{xparse}
ExplSyntaxOn
clist_new:N g_sebastiano_color_clist
NewDocumentCommand{SebastianosColorList}{+m}{
clist_gset:Nn g_sebastiano_color_clist {#1}
}
NewExpandableDocumentCommand{RandomColor}{}{
clist_rand_item:N g_sebastiano_color_clist
}
NewDocumentCommand{SebastianosRandSeed}{+m}{
sys_gset_rand_seed:n {#1}
}
ExplSyntaxOff
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
colorlet{ocre}{RandomColor}
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
SebastianosRandSeed{12345678}
SebastianosColorList{Red,Green,Yellow,Blue,Violet,Brown,Orange}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
part{Part Three}
part{Part Four}
part{Part Five}
end{document}
For me it is extraordinary and the effect is very beautiful indeed beautiful. Thank you very much with all my heart.
– Sebastiano
Jan 12 at 22:16
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f469877%2fautomatic-change-of-the-color-for-each-part%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Changing the color on a random base can be done easily with pdflatex
or lualatex
and applying clist_rand_item:N
for example, which contains list of colors.
Use SebastianosColorList{Red,...,}
to store the color names and a colorlet{ocre}{RandomColor}
to change from ocre
to a random color.
The macro SebastianosRandSeed
sets the random number seed, with the given seed 12345678
and the used colors the sequence of part colors is
red, blue, yellow, brown, green (in pastel like variations)
Please note that random numbers are random in the sense that red
could be followed by red
as well, i.e. there is no guarantee that no repetition will occur.
Please note also that this code does not work with XeLaTeX
, since the random number generator code of expl3
is not working with XeLaTeX
.
I will update the code ...
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
usepackage{xparse}
ExplSyntaxOn
clist_new:N g_sebastiano_color_clist
NewDocumentCommand{SebastianosColorList}{+m}{
clist_gset:Nn g_sebastiano_color_clist {#1}
}
NewExpandableDocumentCommand{RandomColor}{}{
clist_rand_item:N g_sebastiano_color_clist
}
NewDocumentCommand{SebastianosRandSeed}{+m}{
sys_gset_rand_seed:n {#1}
}
ExplSyntaxOff
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
colorlet{ocre}{RandomColor}
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
SebastianosRandSeed{12345678}
SebastianosColorList{Red,Green,Yellow,Blue,Violet,Brown,Orange}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
part{Part Three}
part{Part Four}
part{Part Five}
end{document}
For me it is extraordinary and the effect is very beautiful indeed beautiful. Thank you very much with all my heart.
– Sebastiano
Jan 12 at 22:16
add a comment |
Changing the color on a random base can be done easily with pdflatex
or lualatex
and applying clist_rand_item:N
for example, which contains list of colors.
Use SebastianosColorList{Red,...,}
to store the color names and a colorlet{ocre}{RandomColor}
to change from ocre
to a random color.
The macro SebastianosRandSeed
sets the random number seed, with the given seed 12345678
and the used colors the sequence of part colors is
red, blue, yellow, brown, green (in pastel like variations)
Please note that random numbers are random in the sense that red
could be followed by red
as well, i.e. there is no guarantee that no repetition will occur.
Please note also that this code does not work with XeLaTeX
, since the random number generator code of expl3
is not working with XeLaTeX
.
I will update the code ...
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
usepackage{xparse}
ExplSyntaxOn
clist_new:N g_sebastiano_color_clist
NewDocumentCommand{SebastianosColorList}{+m}{
clist_gset:Nn g_sebastiano_color_clist {#1}
}
NewExpandableDocumentCommand{RandomColor}{}{
clist_rand_item:N g_sebastiano_color_clist
}
NewDocumentCommand{SebastianosRandSeed}{+m}{
sys_gset_rand_seed:n {#1}
}
ExplSyntaxOff
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
colorlet{ocre}{RandomColor}
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
SebastianosRandSeed{12345678}
SebastianosColorList{Red,Green,Yellow,Blue,Violet,Brown,Orange}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
part{Part Three}
part{Part Four}
part{Part Five}
end{document}
For me it is extraordinary and the effect is very beautiful indeed beautiful. Thank you very much with all my heart.
– Sebastiano
Jan 12 at 22:16
add a comment |
Changing the color on a random base can be done easily with pdflatex
or lualatex
and applying clist_rand_item:N
for example, which contains list of colors.
Use SebastianosColorList{Red,...,}
to store the color names and a colorlet{ocre}{RandomColor}
to change from ocre
to a random color.
The macro SebastianosRandSeed
sets the random number seed, with the given seed 12345678
and the used colors the sequence of part colors is
red, blue, yellow, brown, green (in pastel like variations)
Please note that random numbers are random in the sense that red
could be followed by red
as well, i.e. there is no guarantee that no repetition will occur.
Please note also that this code does not work with XeLaTeX
, since the random number generator code of expl3
is not working with XeLaTeX
.
I will update the code ...
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
usepackage{xparse}
ExplSyntaxOn
clist_new:N g_sebastiano_color_clist
NewDocumentCommand{SebastianosColorList}{+m}{
clist_gset:Nn g_sebastiano_color_clist {#1}
}
NewExpandableDocumentCommand{RandomColor}{}{
clist_rand_item:N g_sebastiano_color_clist
}
NewDocumentCommand{SebastianosRandSeed}{+m}{
sys_gset_rand_seed:n {#1}
}
ExplSyntaxOff
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
colorlet{ocre}{RandomColor}
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
SebastianosRandSeed{12345678}
SebastianosColorList{Red,Green,Yellow,Blue,Violet,Brown,Orange}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
part{Part Three}
part{Part Four}
part{Part Five}
end{document}
Changing the color on a random base can be done easily with pdflatex
or lualatex
and applying clist_rand_item:N
for example, which contains list of colors.
Use SebastianosColorList{Red,...,}
to store the color names and a colorlet{ocre}{RandomColor}
to change from ocre
to a random color.
The macro SebastianosRandSeed
sets the random number seed, with the given seed 12345678
and the used colors the sequence of part colors is
red, blue, yellow, brown, green (in pastel like variations)
Please note that random numbers are random in the sense that red
could be followed by red
as well, i.e. there is no guarantee that no repetition will occur.
Please note also that this code does not work with XeLaTeX
, since the random number generator code of expl3
is not working with XeLaTeX
.
I will update the code ...
documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
usepackage[svgnames,dvipsnames]{xcolor}
usepackage{graphicx} % Required for including pictures
usepackage{lipsum} % Inserts dummy text
usepackage{tikz} % Required for drawing custom shapes
usepackage[english]{babel} % English language/hyphenation
definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
usepackage{mathptmx}
usepackage{xparse}
ExplSyntaxOn
clist_new:N g_sebastiano_color_clist
NewDocumentCommand{SebastianosColorList}{+m}{
clist_gset:Nn g_sebastiano_color_clist {#1}
}
NewExpandableDocumentCommand{RandomColor}{}{
clist_rand_item:N g_sebastiano_color_clist
}
NewDocumentCommand{SebastianosRandSeed}{+m}{
sys_gset_rand_seed:n {#1}
}
ExplSyntaxOff
%----------------------------------------------------------------------------------------
% BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------
usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
addbibresource{bibliography.bib} % BibTeX bibliography file
defbibheading{bibempty}{}
usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
usepackage{makeidx} % Required to make an index
makeindex % Tells LaTeX to create the files required for indexing
%----------------------------------------------------------------------------------------
% MAIN TABLE OF CONTENTS
%----------------------------------------------------------------------------------------
usepackage{titletoc} % Required for manipulating the table of contents
contentsmargin{0cm} % Removes the default margin
% Part text styling (this is mostly taken care of in the PART HEADINGS section of this file)
titlecontents{part}
[0cm] % Left indentation
{addvspace{20pt}bfseries} % Spacing and font options for parts
{}
{}
{}
% Chapter text styling
titlecontents{chapter}
[1.25cm] % Left indentation
{addvspace{12pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre!60}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Formatting of numbered sections of this type
{color{ocre}} % Formatting of numberless sections of this type
{color{ocre!60}normalsize;titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Section text styling
titlecontents{section}
[1.25cm] % Left indentation
{addvspace{3pt}sffamilybfseries} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{hfillcolor{black}thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Subsection text styling
titlecontents{subsection}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Figure text styling
titlecontents{figure}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for figures
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
% Table text styling
titlecontents{table}
[1.25cm] % Left indentation
{addvspace{1pt}sffamilysmall} % Spacing and font options for tables
{thecontentslabelhspace*{1em}} % Formatting of numbered sections of this type
{} % Formatting of numberless sections of this type
{ titlerule*[.5pc]{.};thecontentspage} % Formatting of the filler to the right of the heading and the page number
%----------------------------------------------------------------------------------------
% MINI TABLE OF CONTENTS IN PART HEADS
%----------------------------------------------------------------------------------------
% Chapter text styling
titlecontents{lchapter}
[0em] % Left indentation
{addvspace{15pt}largesffamilybfseries} % Spacing and font options for chapters
{color{ocre}contentslabel[Largethecontentslabel]{1.25cm}color{ocre}} % Chapter number
{}
{color{ocre}normalsizesffamilybfseries;titlerule*[.5pc]{.};thecontentspage} % Page number
% Section text styling
titlecontents{lsection}
[0em] % Left indentation
{sffamilysmall} % Spacing and font options for sections
{contentslabel[thecontentslabel]{1.25cm}} % Section number
{}
{}
% Subsection text styling (note these aren't shown by default, display them by searchings this file for tocdepth and reading the commented text)
titlecontents{lsubsection}
[.5em] % Left indentation
{sffamilyfootnotesize} % Spacing and font options for subsections
{contentslabel[thecontentslabel]{1.25cm}}
{}
{}
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
usepackage{fancyhdr} % Required for header and footer configuration
pagestyle{fancy} % Enable the custom headers and footers
renewcommand{chaptermark}[1]{markboth{sffamilynormalsizebfserieschaptername thechapter. #1}{}} % Styling for the current chapter in the header
renewcommand{sectionmark}[1]{markright{sffamilynormalsizethesectionhspace{5pt}#1}{}} % Styling for the current section in the header
fancyhf{} % Clear default headers and footers
fancyhead[LE,RO]{sffamilynormalsizethepage} % Styling 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
%fancyfoot[C]{thepage} % Uncomment to include a footer
renewcommand{headrulewidth}{0.5pt} % Thickness of the rule under the header
fancypagestyle{plain}{% Style for when a plain pagestyle is specified
fancyhead{}renewcommand{headrulewidth}{0pt}%
}
% Removes the header from odd empty pages at the end of chapters
makeatletter
renewcommand{cleardoublepage}{
clearpageifoddc@pageelse
hbox{}
vspace*{fill}
thispagestyle{empty}
newpage
fi}
%----------------------------------------------------------------------------------------
% SECTION NUMBERING IN THE MARGIN
%----------------------------------------------------------------------------------------
makeatletter
renewcommand{@seccntformat}[1]{llap{textcolor{ocre}{csname the#1endcsname}hspace{1em}}}
renewcommand{section}{@startsection{section}{1}{z@}
{-4ex @plus -1ex @minus -.4ex}
{1ex @plus.2ex }
{normalfontlargesffamilybfseries}}
renewcommand{subsection}{@startsection {subsection}{2}{z@}
{-3ex @plus -0.1ex @minus -.4ex}
{0.5ex @plus.2ex }
{normalfontsffamilybfseries}}
renewcommand{subsubsection}{@startsection {subsubsection}{3}{z@}
{-2ex @plus -0.1ex @minus -.2ex}
{.2ex @plus.2ex }
{normalfontsmallsffamilybfseries}}
renewcommandparagraph{@startsection{paragraph}{4}{z@}
{-2ex @plus-.2ex @minus .2ex}
{.1ex}
{normalfontsmallsffamilybfseries}}
%----------------------------------------------------------------------------------------
% PART HEADINGS
%----------------------------------------------------------------------------------------
% Numbered part in the table of contents
newcommand{@mypartnumtocformat}[2]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!20}{strutparbox[c][.7cm]{ecart}{color{ocre!70}Largesffamilybfseriescentering#1}}hskipespcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth-ecart-esp}{Largesffamilycentering#2}}%
}
% Unnumbered part in the table of contents
newcommand{@myparttocformat}[1]{%
setlengthfboxsep{0pt}%
noindentcolorbox{ocre!40}{strutparbox[c][.7cm]{linewidth}{Largesffamilycentering#1}}%
}
newlengthesp
setlengthesp{4pt}
newlengthecart
setlengthecart{1.2cm-esp}
newcommand{thepartimage}{}%
newcommand{partimage}[1]{renewcommand{thepartimage}{#1}}%
def@part[#1]#2{%
ifnum c@secnumdepth >-2relax%
refstepcounter{part}%
addcontentsline{toc}{part}{texorpdfstring{protect@mypartnumtocformat{thepart}{#1}}{partname~thepart --- #1}}
else%
addcontentsline{toc}{part}{texorpdfstring{protect@myparttocformat{#1}}{#1}}%
fi%
startcontents%
markboth{}{}%
{thispagestyle{empty}%
colorlet{ocre}{RandomColor}
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north] at (4cm,-3.25cm){color{ocre!40}fontsize{220}{100}sffamilybfseriesthepart};
node[anchor=south east] at (paperwidth-1cm,-paperheight+1cm){parbox[t][t]{8.5cm}{
printcontents{l}{0}{setcounter{tocdepth}{1}}% The depth to which the Part mini table of contents displays headings; 0 for chapters only, 1 for chapters and sections and 2 for chapters, sections and subsections
}};
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#2}};
end{tikzpicture}};
end{tikzpicture}}%
@endpart}
def@spart#1{%
startcontents%
phantomsection
{thispagestyle{empty}%
begin{tikzpicture}[remember picture,overlay]%
node at (current page.north west){begin{tikzpicture}[remember picture,overlay]%
fill[ocre!20](0cm,0cm) rectangle (paperwidth,-paperheight);
node[anchor=north east] at (paperwidth-1.5cm,-3.25cm){parbox[t][t]{15cm}{strutraggedleftcolor{white}fontsize{30}{30}sffamilybfseries#1}};
end{tikzpicture}};
end{tikzpicture}}
addcontentsline{toc}{part}{texorpdfstring{%
setlengthfboxsep{0pt}%
noindentprotectcolorbox{ocre!40}{strutprotectparbox[c][.7cm]{linewidth}{Largesffamilyprotectcentering #1quadmbox{}}}}{#1}}%
@endpart}
def@endpart{vfilnewpage
if@twoside
if@openright
null
thispagestyle{empty}%
newpage
fi
fi
if@tempswa
twocolumn
fi}
%----------------------------------------------------------------------------------------
% CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
% A switch to conditionally include a picture, implemented by Christian Hupfer
newififusechapterimage
usechapterimagetrue
newcommand{thechapterimage}{}%
newcommand{chapterimage}[1]{ifusechapterimagerenewcommand{thechapterimage}{#1}fi}%
newcommand{autodot}{.}
def@makechapterhead#1{%
{parindent z@ raggedright normalfont
ifnum c@secnumdepth >m@ne
if@mainmatter
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}thechapterautodot~#1strut};
end{tikzpicture}};
end{tikzpicture}
else
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
fifiparvspace*{270p@}}}
%-------------------------------------------
def@makeschapterhead#1{%
begin{tikzpicture}[remember picture,overlay]
node at (current page.north west)
{begin{tikzpicture}[remember picture,overlay]
node[anchor=north west,inner sep=0pt] at (0,0) {ifusechapterimageincludegraphics[width=paperwidth]{thechapterimage}fi};
draw[anchor=west] (Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{strutmakebox[22cm]{}};
draw[anchor=west] (Gm@lmargin+.3cm,-9cm) node {hugesffamilybfseriescolor{black}#1strut};
end{tikzpicture}};
end{tikzpicture}
parvspace*{270p@}}
makeatother
%----------------------------------------------------------------------------------------
% LINKS
%----------------------------------------------------------------------------------------
usepackage{hyperref}
hypersetup{hidelinks,backref=true,pagebackref=true,hyperindex=true,colorlinks=false,breaklinks=true,urlcolor=ocre,bookmarks=true,bookmarksopen=false}
usepackage{bookmark}
bookmarksetup{
open,
numbered,
addtohook={%
ifnumbookmarkget{level}=0 % chapter
bookmarksetup{bold}%
fi
ifnumbookmarkget{level}=-1 % part
bookmarksetup{color=ocre,bold}%
fi
}
}
SebastianosRandSeed{12345678}
SebastianosColorList{Red,Green,Yellow,Blue,Violet,Brown,Orange}
begin{document}
%----------------------------------------------------------------------------------------
% PART
%----------------------------------------------------------------------------------------
part{Part One}
part{Part Two}
part{Part Three}
part{Part Four}
part{Part Five}
end{document}
edited Jan 12 at 22:18
answered Jan 12 at 22:06


Christian HupferChristian Hupfer
149k14196391
149k14196391
For me it is extraordinary and the effect is very beautiful indeed beautiful. Thank you very much with all my heart.
– Sebastiano
Jan 12 at 22:16
add a comment |
For me it is extraordinary and the effect is very beautiful indeed beautiful. Thank you very much with all my heart.
– Sebastiano
Jan 12 at 22:16
For me it is extraordinary and the effect is very beautiful indeed beautiful. Thank you very much with all my heart.
– Sebastiano
Jan 12 at 22:16
For me it is extraordinary and the effect is very beautiful indeed beautiful. Thank you very much with all my heart.
– Sebastiano
Jan 12 at 22:16
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f469877%2fautomatic-change-of-the-color-for-each-part%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
yTWu7n6HNgsk,Tu4Z9z,iU2,TlHf8Mqli,9qZ,mEsdBtId Xvs5Y G3dW3wK0OqzcvKV HB4KwTUVAU4i JtP,LY
2
Off-topic: You have to load
usepackage[svgnames,dvipsnames]{xcolor}
beforeusepackage{tikz}
to avoid anOption clash
error.– Phelype Oleinik
Jan 12 at 21:21
1
May I ask why do you want to introduce such a feature? Just because it is possible? Alternating colors for titles? This is not a proof of good typography.
– Christian Hupfer
Jan 12 at 21:54
At the moment, your document shows apricot-like colored rectangles only
– Christian Hupfer
Jan 12 at 21:56
@ChristianHupfer I like pastel colors and in my opinion it will also provide a better aesthetic for my book. I simply extrapolated the entire code. In summary, I only took the compilable part.
– Sebastiano
Jan 12 at 21:58
My code was edited and I put
usepackage[svgnames,dvipsnames]{xcolor}
beforeusepackage{tikz}
and put typography.– Sebastiano
Jan 12 at 22:01