如何为每个页眉添加自定义颜色

如何为每个页眉添加自定义颜色

以下是我的笔记中的典型一页

在此处输入图片描述

我想为每个部分添加独特的侧面颜色。例如,对于第 3 部分,我想使用蓝色作为

在此处输入图片描述

理想情况下,我还希望文本和颜色(以及纸张的边缘)之间能够有固定的距离。

请注意,我为每一页都设置了标题,其中包括子节编号和节名。例如,上文中我们有“这是排列的标志”一节,当前页面由第三子节组成。

到目前为止,我已经使用了花式标头,但似乎无法添加此功能。有人知道我该如何实现这一点吗?

如果您需要有关我当前设置的更多信息,请告诉我。

这是我的模板

\documentclass[12pt]{article}

 

\usepackage{fancyhdr,lipsum}
\usepackage{eso-pic,graphicx}
\usepackage[a4paper,bindingoffset=0in,%
            left=0.5in,right=0.5in,top=0.8in,bottom=1in,%
            footskip=.5in]{geometry}

\newcommand{\newsection}[1]{%
  \fancyhead[C]{\bfseries\LARGE \thesection~#1}% Clear
}

\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\usepackage{seqsplit}
\usepackage{libertine}
\usepackage{amsmath} % Imports amsmath
\usepackage{blindtext}
\usepackage{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{physics} %Allows for differentials
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage[most]{tcolorbox}
\usepackage{enumitem}
\usepackage{empheq}
\usepackage{graphicx,wrapfig,lipsum}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{color}
\usepackage{tikz}
\usepackage{eso-pic,graphicx}
\usepackage{xcolor,soul}
\usepackage{xpatch}

\makeatletter
\AtBeginDocument{\xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}}
\makeatother


%Defines the Customr Colors
\definecolor{bl2}{HTML}{0b4973} %These are the blue colours
\definecolor{bl1}{HTML}{dce8eb}
\definecolor{g1}{HTML}{dcebdd} %These are the green colours
\definecolor{g2}{HTML}{0b731c}
\definecolor{r1}{HTML}{ebdcdc} %These are the red colours
\definecolor{r2}{HTML}{730b0b}
\definecolor{br1}{HTML}{ebe8dc} %These are the brown colours
\definecolor{br2}{HTML}{734b0b}
\definecolor{br3}{HTML}{4c3c16}

\definecolor{p2}{HTML}{520b73}
\definecolor{p1}{HTML}{664f71}

%Defines the Custom Color Boxes
%1.1 Theorem - Blue
\newtcolorbox{bluetheorem}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=bl2,
title code={
\path[fill=bl1] (title.south west) rectangle (title.north east);
\path[draw=bl2,solid,line width=0.75mm]
([xshift=5mm]title.south west) -- ([xshift=-5mm]title.south east);
},
boxrule=0pt,frame hidden,
borderline west={4pt}{0pt}{bl2},
colback=bl1,
colbacktitle=bl1,
opacityback=0.6
}

%1.2 Definition - Blue
\newtcolorbox{bluedefinition}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=bl2,
boxrule=0pt,frame hidden,
opacityback=0,
%borderline west={10pt}{5pt}{blue,opacity=0.5},
overlay={
      \draw[line width=10pt,bl2,opacity=0.5]
          ([shift={(0mm,-2mm)}]interior.north west)
          --([shift={(0mm,2mm)}]interior.south west);
        }
}

%2.1 Theorem - Green
\newtcolorbox{greentheorem}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=g2,
title code={
\path[fill=g1] (title.south west) rectangle (title.north east);
\path[draw=g2,solid,line width=0.75mm]
([xshift=5mm]title.south west) -- ([xshift=-5mm]title.south east);
},
boxrule=0pt,frame hidden,
borderline west={4pt}{0pt}{g2},
colback=g1,
colbacktitle=g1,
opacityback=0.6
}

%2.2 Definition - Green
\newtcolorbox{greendefinition}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=g2,
boxrule=0pt,frame hidden,
opacityback=0,
%borderline west={10pt}{5pt}{blue,opacity=0.5},
overlay={
      \draw[line width=10pt,g2,opacity=0.5]
          ([shift={(0mm,-2mm)}]interior.north west)
          --([shift={(0mm,2mm)}]interior.south west);
        }
}

%3.1 Theorem - Red
\newtcolorbox{redtheorem}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=r2,
title code={
\path[fill=r1] (title.south west) rectangle (title.north east);
\path[draw=r2,solid,line width=0.75mm]
([xshift=5mm]title.south west) -- ([xshift=-5mm]title.south east);
},
boxrule=0pt,frame hidden,
borderline west={4pt}{0pt}{r2},
colback=r1,
colbacktitle=r1,
opacityback=0.6
}

%3.2 Definition - Red
\newtcolorbox{reddefinition}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=r2,
boxrule=0pt,frame hidden,
opacityback=0,
%borderline west={10pt}{5pt}{blue,opacity=0.5},
overlay={
      \draw[line width=10pt,r2,opacity=0.5]
          ([shift={(0mm,-2mm)}]interior.north west)
          --([shift={(0mm,2mm)}]interior.south west);
        }
}

%4.1 Theorem - Brown
\newtcolorbox{browntheorem}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=br2,
title code={
\path[fill=br1] (title.south west) rectangle (title.north east);
\path[draw=br2,solid,line width=0.75mm]
([xshift=5mm]title.south west) -- ([xshift=-5mm]title.south east);
},
boxrule=0pt,frame hidden,
borderline west={4pt}{0pt}{br2},
colback=br1,
colbacktitle=br1,
opacityback=0.6
}

%4.2 Definition - Brown
\newtcolorbox{browndefinition}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=br2,
boxrule=0pt,frame hidden,
opacityback=0,
%borderline west={10pt}{5pt}{blue,opacity=0.5},
overlay={
      \draw[line width=10pt,br2,opacity=0.5]
          ([shift={(0mm,-2mm)}]interior.north west)
          --([shift={(0mm,2mm)}]interior.south west);
        }
}

%5.1 Theorem - Purple
\newtcolorbox{purpletheorem}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=p2,
title code={
\path[fill=p1] (title.south west) rectangle (title.north east);
\path[draw=p2,solid,line width=0.75mm]
([xshift=5mm]title.south west) -- ([xshift=-5mm]title.south east);
},
boxrule=0pt,frame hidden,
borderline west={4pt}{0pt}{p2},
colback=p1,
colbacktitle=p1,
opacityback=0.6
}

%5.2 Definition - Purple
\newtcolorbox{purpledefinition}{
enhanced,
fonttitle=\sffamily\bfseries,
coltitle=p2,
boxrule=0pt,frame hidden,
opacityback=0,
%borderline west={10pt}{5pt}{blue,opacity=0.5},
overlay={
      \draw[line width=10pt,p2,opacity=0.5]
          ([shift={(0mm,-2mm)}]interior.north west)
          --([shift={(0mm,2mm)}]interior.south west);
        }
}

\newtheoremstyle{break}
  {\topsep}{\topsep}%
  {\upshape}{}%
  {\bfseries}{}%
  {\newline}{}%

\theoremstyle{break}

\newtheorem{theorem}{Theorem}[section] %This defines the \begin{Theorem} commands
\newtheorem{corollary}{Corollary}[theorem] %This defines the \begin{Corollary} commands
\newtheorem{lemma}[theorem]{Lemma} %This defines the \begin{Lemma} commaands and formating


\theoremstyle{definition} %This changes the theorem style. In this case, we want the following theorem to have style of a definition as it won't change the formating.
\newtheorem*{example}{Example}
\newtheorem*{remark}{Remark}

\renewcommand{\baselinestretch}{0.9} % This deals with the dimentions of the page.



\title{Algebra and Geometry} % Title

\usepackage{hyperref}

\hypersetup{
    colorlinks=false, %set true if you want colored links
  linktoc=all,     %set to all if you want both sections and subsections linked
    linkcolor=blue,  %choose some color if you want links to stand out
}

\newcommand{\tcb}[1]{\textcolor{bl2}{#1}} %Use this for colouring blue text
\newcommand{\inc}[2]{\includegraphis[#1]{#2}} %shorthand for includegraphis


\begin{document}


\AddToShipoutPictureBG*{\includegraphics[width=\paperwidth,height=\paperheight]{whitelinesa1.png}}

\maketitle

\tableofcontents
\newpage
\newsection{Template} 
\sethlcolor{bl1} %For the first chapter (here in the commands we have \newsection) we will use blue.

\AddToShipoutPictureBG*{\includegraphics[width=\paperwidth,height=\paperheight]{whitelinesblue.png}}


\section{Commands}

\begin{flushleft}

 
testing

\end{flushleft}



\end{document}

最终结果如下 以下是我笔记中的屏幕截图。

在此处输入图片描述

答案1

间隙目前设置为 0.1 英寸。请注意,边缘处有额外的 0.1 英寸间隙,以容纳超大边框艺术。

\documentclass[]{article}
\usepackage{xcolor}
\usepackage[a4paper,bindingoffset=0in,%
            left=0.5in,right=0.5in,top=0.8in,bottom=1in,%
            footskip=.5in]{geometry}
\usepackage{graphicx}
\usepackage{lipsum}

\newsavebox{\titlebox}

\makeatletter
\def\ps@mystyle{\def\@oddfoot{\hfill\thepage\hfill}% fancyhdr is for sissies
  \let\@evenfoot\@oddfoot
  \def\@evenhead{\hspace{0.1in}\hfill
    \textcolor{blue}{\rule{\dimexpr 0.5\textwidth-0.3in-0.5\wd\titlebox}{\ht\titlebox}}\hfill
    \usebox\titlebox\hfill
    \textcolor{blue}{\rule{\dimexpr 0.5\textwidth-0.3in-0.5\wd\titlebox}{\ht\titlebox}}\hfill
    \hspace{0.1in}}%
  \let\@oddhead=\@evenhead
  \def\sectionmark##1{\global\setbox\titlebox=\hbox{\bfseries\LARGE \thesection~##1}}%
}
\makeatother
\pagestyle{mystyle}
\AddToHook{shipout/background}{% no package needed (other than graphicx)
  \put(0.1in,-0.6in){\includegraphics[width=0.5in,height=0.5in]{example-image-a}}
  \put(\dimexpr \paperwidth-0.6in,-0.6in){\includegraphics[width=0.5in,height=0.5in]{example-image-b}}
}

\begin{document}
\section{This is sign of permutation}
\lipsum[1-4]
\end{document}

此版本使用 TikZ。棘手之处在于尝试对齐基线而不是中心。它还使用\rightmark而不是全局。如果一页上\titlebox有两个,将显示第一个,而将显示第二个。\section\rightmark\titlebox

\autocolor为每一页选择不同的颜色(直到用完\or)。

\documentclass[]{article}
\usepackage{xcolor}
\usepackage[a4paper,bindingoffset=0in,%
            left=0.5in,right=0.5in,top=0.8in,bottom=1in,%
            footskip=.5in]{geometry}
\usepackage{tikz}
\usepackage{lipsum}

\newsavebox{\titlebox}
\newcommand{\autocolor}{\ifcase\value{page}\relax white\or red\or green\or blue\else white\fi}

\makeatletter
\def\ps@mystyle{\def\@oddfoot{\hfill\thepage\hfill}% fancyhdr is for sissies
  \let\@evenfoot\@oddfoot
  \def\@evenhead{\savebox\titlebox{\rightmark}\hfill\tikz
    [every node/.style={inner sep=0pt}]
    {\node[anchor=base] (title) {\usebox\titlebox};
    \node[fill={\autocolor},opacity=0.5,
      minimum height=\ht\titlebox,
      minimum width={0.5\textwidth-0.3in-0.5\wd\titlebox},
      left=0.5em, yshift=0.5\dp\titlebox] at (title.west){};
    \node[fill={\autocolor},opacity=0.5,
      minimum height=\ht\titlebox,
      minimum width={0.5\textwidth-0.3in-0.5\wd\titlebox},
      right=0.5em, yshift=0.5\dp\titlebox] at (title.east){};
    }\hfill}% end of \@evenhead
  \let\@oddhead=\@evenhead
  \def\sectionmark##1{\markright{\bfseries\LARGE \thesection~##1}}%
}
\makeatother
\pagestyle{mystyle}
\AddToHook{shipout/background}{% no package needed (other than graphicx)
  \put(0.1in,-0.6in){\includegraphics[width=0.5in,height=0.5in]{example-image-a}}
  \put(\dimexpr \paperwidth-0.6in,-0.6in){\includegraphics[width=0.5in,height=0.5in]{example-image-b}}
}

\begin{document}
\section{This is sign of permutation}
\lipsum[1-4]
\end{document}

相关内容