你能帮我得到和照片一样的效果吗?我希望在页眉中显示章节标题和一个带有章节编号的小框,使用特定颜色和相同颜色的条带。在页脚中,我希望有一个矩形,其颜色与页眉中带有页码的框相同。第二章、第三章和第四章的页眉和页脚相同,只是颜色不同。提前谢谢您。我非常感谢您的帮助,这对我的论文有帮助。
ps 对于无数的章节,例如简介、目录、表格列表...我想要相同的页脚和页眉,颜色为黑色,当然页眉框中不包含章节编号。
\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{emptypage} %
\usepackage[french]{babel}
\usepackage[top=3cm,bottom=1cm,left=2.5cm,
right=2.5cm,headheight=26pt,headsep=25pt,heightrounded]{geometry}
\frenchbsetup{FrenchFootnotes=false}
\usepackage[hang,flushmargin]{footmisc}
\usepackage{enumerate} % personnaliser les listes
\usepackage[babel,french=guillemets]{csquotes}
\usepackage{graphicx}
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{5}
\usepackage[titles]{tocloft}
\graphicspath{{\images}}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{xfrac}
\usepackage{refcount}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{tikzpagenodes}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xspace}
\usepackage{array}
\definecolor{c1}{rgb}{0,0,1} %blue
\definecolor{c2}{rgb}{0,0.3,0.9} %light blue
\definecolor{c3}{rgb}{0.3,0,0.9} %red blue
\usepackage{setspace} %interligne 1.5
\usepackage[parfill]{parskip}
\usepackage{calc}
\usepackage{titlesec}
\usepackage{shorttoc}
\usepackage{enumitem} % modifier et personaliser les puces des listes
\usepackage{pifont} % les symboles pour les listes
\usepackage{etoolbox}
\usepackage{sectsty} %
\allsectionsfont{\raggedright}
\AtBeginEnvironment{footcitedquote}{\singlespacing\small}
\AtBeginEnvironment{fancyquotes}{\small}
\usepackage[hyperfootnotes=false,colorlinks=true,breaklinks]{hyperref}
\hypersetup{
linkcolor={c1}, %internal links
citecolor={c2}, %citations
urlcolor={c3}, %external links
}
% format chapitre
\titleformat{\chapter}[display]{\bfseries\LARGE}{}{0pt}%
{\raisebox{-5mm}[0pt][0pt]{%
\begin{minipage}{20mm}
\centering{\mdseries\footnotesize\textsc{chapitre}}\\
[2pt]%
\rule{10mm}{30mm}\hspace{-10mm}%
\raisebox{25mm}{\parbox{10mm}{\centering\textcolor{white}
{\thechapter}}}%
\end{minipage}}%
\rule{\textwidth-20mm}{.4pt}\\%
\hspace*{25mm}\MakeUppercase} [\vspace*{10mm}]
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{12pt}}
\titleformat{name=\chapter, numberless}[hang]
{\Huge\bfseries}{\hsp\textcolor{gray75}{|}\hsp}{0pt}
{\Huge\bfseries}
% Page style
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]
{\markboth{\MakeUppercase{#1}}{}} % just the chapter title
without chapter1
\renewcommand*{\sectionmark}[1]{\markright{#1}{}} %
\fancyhead{}
\fancyfoot{}
\fancyhead[LO]{
\bf{\thechapter} \space
\makebox[0pt][r]{\space\smash{\vheadline}}%
\space\footnotesize \bf \leftmark
}
\fancyhead[RE]{%
\footnotesize\bf\rightmark\space
\makebox[0pt][l]{\smash{\vheadline}\space}%
}
\fancyfoot[RE,RO]{\MakeUppercase{\chaptername}\ \thechapter\
{\vrule height 13pt width 2pt} \ \thepage }
\voffset-10mm
\renewcommand*\headrulewidth{0pt}
\newcommand*\vheadline{\textcolor{gray75}{\rule[-1pt]{3pt}
{1000pt}}}
%========= CHAPTER HEADINGS
\definecolor{ocre}{RGB}{52,177,201}
\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}
\definecolor{chapnumberbg}{RGB}{26,40,105}
\definecolor{chapname}{RGB}{100,117,158}
\titleformat{\chapter}[display]
{\normalfont}
{}
{0pt}
{\stepcounter{chapshift}
\begin{tikzpicture}
\node[
draw=chapname,
rounded corners,
outer sep=0pt,
inner sep=6pt,
rotate=90,
line width=1pt,
font=\Large\color{chapnumberbg}\bfseries
]
(chapname)
{\chaptertitlename};
\node[
fill=chapnumberbg,
minimum width=2cm,
minimum height=2.3cm,
rounded corners,
anchor=west,
font=\color{white}\fontsize{40}{48}\selectfont\bfseries
]
at ([xshift=6pt]chapname.south)
(chapnumber)
{\thechapter};
\node[
anchor=west,
text width=\textwidth-4cm,
font=\bfseries\LARGE
]
at ([xshift=10pt]chapnumber.east)
{#1};
\fill[
overlay,
draw=none,
line width=0pt,
rounded corners=1pt,
left color=chapnumberbg,
right color=chapnumberbg!10
]
([yshift=-3pt]chapname.north west) rectangle ++
(\textwidth,-3pt);
\end{tikzpicture}%
}
\titleformat{name=\chapter,numberless}[display]
{\normalfont}
{}
{0pt}
{%
\begin{tikzpicture}
\node[
anchor=west,
inner sep=0pt,
outer sep=0pt,
text width=\textwidth,
font=\bfseries\LARGE
]
(chaptitle)
{#1};
\fill[
overlay,
draw=none,
line width=0pt,
rounded corners=1pt,
left color=chapnumberbg,
right color=chapnumberbg!10
]
([yshift=-3pt]chaptitle.south west) rectangle ++
(\textwidth,-3pt);
\end{tikzpicture}%
}
\begin{document}
\chapter*{Introduction générale}
\lipsum[1-7]
\chapter{Revue de littérature}
\lipsum[1-7]
\section{Définition}
\lipsum[1-7]
\chapter{Les hypothèses}
\lipsum[1-7]
\chapter*{Conslusion générale}
\lipsum[1-7]
\appendix
\chapter{Annexes A}
\lipsum[1-7]
\chapter{Annexes B}
\lipsum[1-7]
\end{document}
答案1
您可以像这样创建页眉和页脚:
\documentclass[a4paper,12pt]{book}
\usepackage[top=3cm,bottom=3cm,left=2.5cm,right=2.5cm,headheight=22pt,headsep=25pt,heightrounded,footskip=1.5cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{lipsum}
% Page style
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\colorlet{myfancycolor}{blue!60!black}
\makeatletter
\def\headrule{\color{myfancycolor}{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
\hrule\@height\headrulewidth\@width\headwidth
\vskip-\headrulewidth}}
\makeatother
\fancypagestyle{mystyle}{
\renewcommand*\headrulewidth{2pt}
\fancyfoot[OR]{%
\color{myfancycolor}%
\rule[-6pt]{100pt}{20pt}%
\hspace*{-90pt}%
\begin{minipage}[b]{0.5cm}%
\color{white}%
\textsf{\thepage}%
\end{minipage}%
}%
\fancyfoot[EL]{%
\hspace*{-75pt}%
\color{myfancycolor}%
\rule[-6pt]{100pt}{20pt}%
\hspace*{-25pt}%
\begin{minipage}[b]{0.5cm}%
\color{white}%
\hfill%
\textsf{\thepage}%
\end{minipage}%
}%
\fancyhead[OR]{%
\raisebox{0.5em}{\sffamily\nouppercase{\rightmark}}\space\color{myfancycolor}\rule{2em}{2em}\raisebox{0.5em}{\hspace{-2em}\color{white}\makebox[2em][c]{\textsf{\thechapter}}}%
\vspace*{-0.5em}%
}
\fancyhead[EL]{%
\color{myfancycolor}\rule{2em}{2em}\raisebox{0.5em}{\hspace{-2em}\color{white}\makebox[2em][c]{\textsf{\thechapter}}}\color{black}\raisebox{0.5em}{\space\sffamily\nouppercase{\rightmark}}%
\vspace*{-0.5em}%
}
}
\fancypagestyle{plain}{%
\renewcommand*\headrulewidth{0pt}
\fancyhf{}%
\fancyfoot[OR]{%
\color{myfancycolor}%
\rule[-6pt]{100pt}{20pt}%
\hspace*{-90pt}%
\begin{minipage}[b]{0.5cm}%
\color{white}%
\textsf{\thepage}%
\end{minipage}%
}%
\fancyfoot[EL]{%
\hspace*{-75pt}%
\color{myfancycolor}%
\rule[-6pt]{100pt}{20pt}%
\hspace*{-25pt}%
\begin{minipage}[b]{0.5cm}%
\color{white}%
\hfill%
\textsf{\thepage}%
\end{minipage}%
}%
}
\fancypagestyle{unnumbered}{%
\fancyhead[OR]{%
\raisebox{0.5em}{\sffamily\nouppercase{\rightmark}}\space\color{myfancycolor}\rule{2em}{2em}%
\vspace*{-0.5em}%
}
\fancyhead[EL]{%
\color{myfancycolor}\rule{2em}{2em}\color{black}\raisebox{0.5em}{\space\sffamily\nouppercase{\rightmark}}%
\vspace*{-0.5em}%
}
}
\pagestyle{mystyle}
\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
\renewcommand*{\sectionmark}[1]{} %
\begin{document}
\pagestyle{unnumbered}
\chapter*{Introduction générale}
\markboth{Introduction générale}{Introduction générale}
\colorlet{myfancycolor}{blue!60!black}
\lipsum[1-7]
\chapter{Revue de littérature}
\pagestyle{mystyle}
\colorlet{myfancycolor}{red!60!black}
\lipsum[1-7]
\section{Définition}
\lipsum[1-7]
\chapter{Les hypothèses}
\colorlet{myfancycolor}{green!60!black}
\lipsum[1-7]
\chapter*{Conslusion générale}
\pagestyle{unnumbered}
\markboth{Conslusion générale}{Conslusion générale}
\colorlet{myfancycolor}{orange!60!black}
\lipsum[1-7]
\lipsum[1-7]
\appendix
\pagestyle{mystyle}
\chapter{Annexes A}
\pagestyle{fancy}
\colorlet{myfancycolor}{cyan!60!black}
\lipsum[1-7]
\chapter{Annexes B}
\colorlet{myfancycolor}{yellow!60!black}
\lipsum[1-7]
\end{document}