我使用以下方法在所有页面上放置页脚:
\newcommand\Footer{
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=south, inner sep=0pt, outer sep=0pt] (footer)
at (current page.south) {\includegraphics[width=\paperwidth]{footer.png}};
\draw [fill=nicedarkblue, draw=none] (footer.north west) rectangle
($(footer.north east)+(0,0.1cm)$);
\node[anchor=east, inner sep=0pt, outer sep=0pt] (footerpage)
at ($(footer.east)-(1cm,0)$) {\textcolor{white}{{\sffamily\bfseries\thepage}}};
\end{tikzpicture}
}
\pagestyle{plain}
\AtBeginShipoutFirst{\Footer}
\AtBeginShipout{\Footer}
但它失败了,原因有三:
- 页码出现两次(“正常”页码和页脚页码)
- 页脚中的编号错误:我得到的是 1、1、2、3、4(而不是 1、2、3、4)
- 我最后毫无理由地多了一个空白页
如何解决这些问题?
编辑:这是整个文档
\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[margin=10pt,font=footnotesize,labelfont=bf]{caption}
\usepackage{lipsum}
\usepackage{soul}
\usepackage{ulem}
\usepackage{fancyhdr}
\usepackage{fancybox}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{array}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{icomma}
\usepackage{floatrow}
\usepackage{subfigure}
\usepackage{enumerate}
\usepackage{appendix}
\usepackage{pdfpages}
\usepackage{multicol}
\usepackage{sistyle}
\usepackage{wasysym}
\usepackage{textcomp}
\usepackage{cellspace}
\usepackage{color}
\usepackage{xcolor}
\usepackage{cancel}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}
\usepackage{tikzpagenodes}
\usepackage{lmodern}
\usepackage{epigraph}
\usepackage{xpatch}
\usepackage{calc}
\usetikzlibrary{calc}
\definecolor{nicedarkblue}{RGB}{0, 0, 102}
\definecolor{otherdarkblue}{RGB}{0, 32, 96}
\def\headergraphics{\includegraphics[width=\paperwidth]{header.png}}
\newlength\headerheight
\setlength\headerheight{\heightof{\headergraphics}}
\newlength\headerleftshift
\setlength\headerleftshift{2cm}
\newcommand\Header{
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north, inner sep=0pt, outer sep=0pt] (header) at (current page.north) {\headergraphics};
\node[anchor=north west, inner sep=0pt, outer sep=0pt] (headerleft) at ($(current page.north west)+(\headerleftshift,0cm)$) {\includegraphics[height=\headerheight]{headerleft.png}};
\draw [fill=white, draw=none] (header.north west) rectangle ($(header.south west)+(\headerleftshift,0cm)$);
\draw [fill=nicedarkblue, draw=none] (header.south west) rectangle ($(header.south east)-(0cm,0.1cm)$);
\end{tikzpicture}
}
\newcommand\Footer{
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=south, inner sep=0pt, outer sep=0pt] (footer) at (current page.south) {\includegraphics[width=\paperwidth]{footer.png}};
\draw [fill=nicedarkblue, draw=none] (footer.north west) rectangle ($(footer.north east)+(0cm,0.1cm)$);
\node[anchor=east, inner sep=0pt, outer sep=0pt] (footerpage) at ($(footer.east)-(1cm,0cm)$) {\textcolor{white}{{\sffamily\bfseries\thepage}}};
\end{tikzpicture}
}
\pagestyle{empty}
\AtBeginShipoutFirst{\Header\Footer}
\AtBeginShipout{\Header\Footer}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{hyperref}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\captionsetup{figurewithin=none}
\captionsetup{tablewithin=none}
\renewcommand{\subfigbottomskip}{-10pt}
\let\oldcite\cite
\renewcommand\cite[1]{\textsuperscript{\oldcite{#1}}}
\hypersetup{
colorlinks,%
citecolor=blue,%
filecolor=blue,%
linkcolor=blue,%
urlcolor=blue
}
\makeatletter
\long\def\@makefntextFB#1{%
\ifx\thefootnote\ftnISsymbol
\@makefntextORI{#1}%
\else
\rule\z@\footnotesep
\setbox\@tempboxa\hbox{\@thefnmark}%
\ifdim\wd\@tempboxa>\z@
\kern2em\llap{\@thefnmark.\kern0.5em}%
\fi
\hangindent2em\hangafter\@ne#1
\fi}
\makeatother
\newcommand*\eqbox[1]{
\definecolor{shadowcolor}{RGB}{0, 0, 102}\setlength\shadowsize{2pt}\shadowbox*{#1}
}
\begin{document}
\chapter*{First chapter}
Test
\chapter{Second chapter}
Test
\end{document}
问题依然存在\pagestyle{empty}
答案1
首先,移除\pagestyle{plain}
并放入\pagestyle{empty}
对于其他两个,请使用eso-pic
以下命令:
\newcommand\Header{% %%%<---- % added at end
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north, inner sep=0pt, outer sep=0pt] (header) at (current page.north) {\headergraphics};
\node[anchor=north west, inner sep=0pt, outer sep=0pt] (headerleft) at ($(current page.north west)+(\headerleftshift,0cm)$) {\includegraphics[height=\headerheight]{headerleft.png}};
\draw [fill=white, draw=none] (header.north west) rectangle ($(header.south west)+(\headerleftshift,0cm)$);
\draw [fill=nicedarkblue, draw=none] (header.south west) rectangle ($(header.south east)-(0cm,0.1cm)$);
\end{tikzpicture}% %%%<---- % added at end
}
\newcommand\Footer{% %%%<---- % added at end
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=south, inner sep=0pt, outer sep=0pt] (footer) at (current page.south) {\includegraphics[width=\paperwidth]{footer.png}};
\draw [fill=nicedarkblue, draw=none] (footer.north west) rectangle ($(footer.north east)+(0cm,0.1cm)$);
\node[anchor=east, inner sep=0pt, outer sep=0pt] (footerpage) at ($(footer.east)-(1cm,0cm)$) {\textcolor{white}{{\sffamily\bfseries\thepage}}};
\end{tikzpicture}% %%%<---- % added at end
}
\pagestyle{empty} %%%<---- changed
\usepackage{eso-pic} %%%<---- % new
\AddToShipoutPictureBG{\Header\Footer} %%%<---- % new
请注意我删除了
\AtBeginShipoutFirst{\Header\Footer}
\AtBeginShipout{\Header\Footer}
这是有问题的,并增加了
\usepackage{eso-pic} %%%<---- % new
\AddToShipoutPictureBG{\Header\Footer} %%%<---- % new
反而。
完整代码(不是 MWE)
\documentclass[12pt,a4paper,demo]{report} %%% remove demo in your file
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[margin=10pt,font=footnotesize,labelfont=bf]{caption}
\usepackage{lipsum}
\usepackage{soul}
\usepackage{ulem}
\usepackage{fancyhdr}
\usepackage{fancybox}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{array}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{icomma}
\usepackage{floatrow}
\usepackage{subfigure}
\usepackage{enumerate}
\usepackage{appendix}
\usepackage{pdfpages}
\usepackage{multicol}
\usepackage{sistyle}
\usepackage{wasysym}
\usepackage{textcomp}
\usepackage{cellspace}
\usepackage{color}
\usepackage{xcolor}
\usepackage{cancel}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}
\usepackage{tikzpagenodes}
\usepackage{lmodern}
\usepackage{epigraph}
\usepackage{xpatch}
\usepackage{calc}
\usetikzlibrary{calc}
\definecolor{nicedarkblue}{RGB}{0, 0, 102}
\definecolor{otherdarkblue}{RGB}{0, 32, 96}
\def\headergraphics{\includegraphics[width=\paperwidth,height=1cm]{header.png}}
\newlength\headerheight
\setlength\headerheight{\heightof{\headergraphics}}
\newlength\headerleftshift
\setlength\headerleftshift{2cm}
\newcommand\Header{%
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north, inner sep=0pt, outer sep=0pt] (header) at (current page.north) {\headergraphics};
\node[anchor=north west, inner sep=0pt, outer sep=0pt] (headerleft) at ($(current page.north west)+(\headerleftshift,0cm)$) {\includegraphics[height=\headerheight]{headerleft.png}};
\draw [fill=white, draw=none] (header.north west) rectangle ($(header.south west)+(\headerleftshift,0cm)$);
\draw [fill=nicedarkblue, draw=none] (header.south west) rectangle ($(header.south east)-(0cm,0.1cm)$);
\end{tikzpicture}%
}
\newcommand\Footer{%
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=south, inner sep=0pt, outer sep=0pt] (footer) at (current page.south) {\includegraphics[width=\paperwidth]{footer.png}};
\draw [fill=nicedarkblue, draw=none] (footer.north west) rectangle ($(footer.north east)+(0cm,0.1cm)$);
\node[anchor=east, inner sep=0pt, outer sep=0pt] (footerpage) at ($(footer.east)-(1cm,0cm)$) {\textcolor{white}{{\sffamily\bfseries\thepage}}};
\end{tikzpicture}%
}
\pagestyle{empty}
\usepackage{eso-pic}
\AddToShipoutPictureBG{\Header\Footer}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{hyperref}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\captionsetup{figurewithin=none}
\captionsetup{tablewithin=none}
\renewcommand{\subfigbottomskip}{-10pt}
\let\oldcite\cite
\renewcommand\cite[1]{\textsuperscript{\oldcite{#1}}}
\hypersetup{
colorlinks,%
citecolor=blue,%
filecolor=blue,%
linkcolor=blue,%
urlcolor=blue
}
\makeatletter
\long\def\@makefntextFB#1{%
\ifx\thefootnote\ftnISsymbol
\@makefntextORI{#1}%
\else
\rule\z@\footnotesep
\setbox\@tempboxa\hbox{\@thefnmark}%
\ifdim\wd\@tempboxa>\z@
\kern2em\llap{\@thefnmark.\kern0.5em}%
\fi
\hangindent2em\hangafter\@ne#1
\fi}
\makeatother
\newcommand*\eqbox[1]{
\definecolor{shadowcolor}{RGB}{0, 0, 102}\setlength\shadowsize{2pt}\shadowbox*{#1}
}
\begin{document}
\chapter*{First chapter}
Test
\chapter{Second chapter}
Test
\end{document}