更改小節顏色修改頁眉

更改小節顏色修改頁眉

這是我的問題:我正在嘗試重新建立我的大學模板。

我建立了一個article文檔,其中第一頁的頁首和頁尾與其他頁面不同。雖然有點髒,但是很管用…

第一頁的頁首比其他頁的頁首長。

然後我想更改我的部分、小節的顏色...我使用包titlesec來修改顏色,當我更改顏色時section,沒有問題,但是當我更改顏色時subsection,我的第二頁和後續頁面上的標題變得太大(就像第一頁上的那樣)。

該文件已上線GitHub。這是article_template,您可以運行my_document.tex

最小工作範例:

\documentclass[a4paper,12pt]{article}

% French or english language
\usepackage[english,french]{babel}

% To write special caracters
% to be used with Linux/Windows
\usepackage[utf8]{inputenc}

% Set the fonts
% Palatino for rm and math | Helvetica for ss | Courier for tt
\usepackage{mathpazo} % math & rm
\usepackage[scaled]{helvet} % ss
\usepackage{courier} % tt
%\normalfont % the default
\usepackage[T1]{fontenc}
% to write the text in sans serif
\renewcommand\familydefault{\sfdefault}

% Set the spacing
\usepackage{setspace}
\onehalfspacing

\usepackage[dvipsnames]{xcolor}

\colorlet{punct}{red!60!black}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{delim}{RGB}{20,105,176}
\colorlet{numb}{magenta!60!black}
\definecolor{blue_title}{RGB}{46,116,181}

\usepackage{titlesec}
\titleformat*{\section}{\normalfont\Large\bfseries\color{blue_title}}
%\titleformat*{\subsection}{\normalfont\large\bfseries\color{blue_title}}
%\titleformat*{\subsubsection}{\normalfont\normalsize\bfseries\color{blue_title}}


% set the margin
% Taille des marges
\usepackage[top=2cm, bottom=4cm, left=2.5cm , right=2.5cm, includehead, showframe]{geometry}
%\usepackage{geometry}
%\geometry{bindingoffset=1cm} % to bind pages
\usepackage{afterpage}

% to be able to use landscape
\usepackage{lscape}

% To skip indent at the begining of paragraphs
\usepackage[parfill]{parskip}

% For quotes adapted in the
\usepackage{csquotes}

% for bullet points
\usepackage{enumitem}

% Footnote definition
\usepackage[hang, bottom]{footmisc}

%Pour le header
\usepackage{fancyhdr}

\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\pagestyle{fancy}
    \fancyhf{}
    \setlength\headheight{45pt}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhead[L]{\includegraphics[width=1.56in, height=0.55in]{example-image}}
    \fancyhead[R]{\thepage}

\fancypagestyle{my_style}{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhead[L]{\includegraphics[width=5.5in, height=1in]{example-image}}
    \fancyfoot[C]{\includegraphics[width=6.7in, height=0.7in]{example-image}}
    }



\usepackage{graphicx}
\usepackage{lipsum}



\begin{document}
\selectlanguage{english}

\newgeometry{top=1.5cm, bottom=4cm, left=2.5cm , right=2.5cm, includehead}
\setlength\headheight{81pt}
\setlength\footskip{56pt}


\thispagestyle{my_style}
%\vspace*{0.5cm}
\Huge % size
\textbf{Magnificient Title}
%\rule{5cm}{0.2pt}

\large
\textcolor{gray}{
Subtitle --- \today
}

\setcounter{page}{1}
\afterpage{\aftergroup\restoregeometry}


\section*{Abstract}
\addcontentsline{toc}{section}{Abstract} % adds an entry to the table of contents
\lipsum[1-2]
\section{The First Section}
\subsection{With a sub secion}
\subsubsection*{and again}

\lipsum[1-10]
\end{document}

這樣,它就可以工作了:

第一頁: 第一頁有效

第二頁及以下: 第二頁很好(小節是黑色的)

請注意,在頭/settings_esc_template.tex,該行\titleformat*{\subsection}{\normalfont\large\bfseries\color{blue_title}}被註解。

現在,如果我通過取消註釋該行將小節(或子小節)置於藍色\titleformat*{\subsection}{\normalfont\large\bfseries\color{blue_title}},那麼我在第二頁上的標題就會改變...

第二頁的標題錯誤(藍色部分)

其行為與包相同sectsty

有人對這種行為有解釋嗎?

感謝您的幫助(並對我的英語錯誤表示歉意)!

答案1

無需對幾何進行複雜的重置。只需使用 \vspace 和 \enlargethispage 並粉碎圖像的高度,以便它們可以黏在頁面中:

\documentclass[a4paper,12pt]{article}

\usepackage[english,french]{babel}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[scaled]{helvet}
\renewcommand\familydefault{\sfdefault}
\usepackage[parfill]{parskip}
\usepackage{setspace}
\onehalfspacing

\usepackage{xcolor}
\usepackage{titlesec}
\titleformat*{\section}{\normalfont\Large\bfseries\color{blue}}
\titleformat*{\subsection}{\normalfont\large\bfseries\color{blue}}
\titleformat*{\subsubsection}{\normalfont\normalsize\bfseries\color{blue}}

%page layout of second and following pages, adapt the values if needed
\usepackage[top=2cm, bottom=4cm, left=2.5cm , right=2.5cm, 
           includehead, headheight=45pt, showframe]{geometry}

\usepackage{fancyhdr}

\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\pagestyle{fancy}
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhead[L]{\includegraphics[width=1.56in, height=0.55in]{example-image}}
    \fancyhead[R]{\thepage}

\fancypagestyle{my_style}{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    %raise the boxes and smash their height on page 1, adapt the values
    \fancyhead[L]{%
     \raisebox{-2cm}[0pt][0pt]{\includegraphics[width=5.5in, height=1in]{example-image}}}
    \fancyfoot[C]{%
     \raisebox{-0.5cm}[0pt][0pt]{\includegraphics[width=6.7in, height=0.7in]{example-image}}}
    }

\usepackage{graphicx}
\usepackage{lipsum}

\begin{document}
\selectlanguage{english}

\thispagestyle{my_style}
\vspace*{0.5cm}  %adapt to move the text down
\enlargethispage{-1cm} %adapt to shorten the first page if needed
\Huge % size
\textbf{Magnificient Title}
%\rule{5cm}{0.2pt}

\large
\textcolor{gray}{Subtitle --- \today}

\section*{Abstract}
\addcontentsline{toc}{section}{Abstract} % adds an entry to the table of contents
\lipsum[1-2]
\section{The First Section}
\subsection{With a sub secion}
\subsubsection*{and again}

\lipsum[1-10]
\end{document}

相關內容