我使用tikz
和fancyhdr
将页码用彩色圆圈标记出来。现在我想改变一页的圆圈颜色。例如,第二页应该是蓝色。是否也可以设置选项,让颜色根据特定页码而改变。例如,前 10 页为蓝色,接下来的 20 页为红色,最后 15 页为黄色?
\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,rounded corners=2,fill=red,inner sep=1mm] (char) {#1};}}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[OR,EL]{}
\fancyfoot[OR,EL]{\circled{\textcolor{white}{\textbf{\thepage}}}}
\fancyfootoffset[OR,EL]{20mm} % nach außen verschieben
\addtolength{\headheight}{0mm} % nach unten verschieben
\newlength{\headshift}
\setlength{\headshift}{0cm}
\addtolength{\headsep}{\headshift}
\addtolength{\voffset}{-\headshift}
\renewcommand{\headrulewidth}{0pt}
\begin{document}
\lipsum
\lipsum
\end{document}
答案1
嗯,你可以简单地重新定义你的命令
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,rounded corners=2,fill=red,inner sep=1mm] (char) {#1};}}
如所须:
\renewcommand*\circled[1]{% <====================================================
\tikz[baseline=(char.base)]{%
\node[shape=circle,rounded corners=2,fill=blue,inner sep=1mm] (char) {#1};}%
% ^^^^^
}
完整的代码如下
\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{tikz}
\newcommand*\circled[1]{%
\tikz[baseline=(char.base)]{%
\node[shape=circle,rounded corners=2,fill=red,inner sep=1mm] (char) {#1};}%
}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[OR,EL]{}
\fancyfoot[OR,EL]{\circled{\textcolor{white}{\textbf{\thepage}}}}
\fancyfootoffset[OR,EL]{20mm} % nach außen verschieben
\addtolength{\headheight}{0mm} % nach unten verschieben
\newlength{\headshift}
\setlength{\headshift}{0cm}
\addtolength{\headsep}{\headshift}
\addtolength{\voffset}{-\headshift}
\renewcommand{\headrulewidth}{0pt}
\begin{document}
\lipsum
\renewcommand*\circled[1]{% <===========================================
\tikz[baseline=(char.base)]{%
\node[shape=circle,rounded corners=2,fill=blue,inner sep=1mm] (char) {#1};}%
}
\lipsum
\renewcommand*\circled[1]{% <===========================================
\tikz[baseline=(char.base)]{%
\node[shape=circle,rounded corners=2,fill=green,inner sep=1mm] (char) {#1};}%
}
\lipsum
\end{document}
结果如下: