如何设置文档以将页码写在行的中间?
通过花哨的页面样式,我遇到了如下情况:
--------------------- % this is a line after the body of my document
1 % this is another line with the page number, centered
但我希望出现如下的情况:
--------- 1 --------- % this is only a line after the body of my document
我该怎么做?第一个解决方案可能涉及 tikz,但是否需要它或者还有其他解决方案?
答案1
我会用\Vhrulefill
宏来实现这一点(Gonzalo Medina 在垂直居中的水平规则填充了行的其余部分?)
我附加了一个工作示例:
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\def\Vhrulefill{\leavevmode\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}
\fancyfoot{\Vhrulefill~\thepage~\Vhrulefill}
\begin{document}
\lipsum
\end{document}
答案2
可能的解决方案基于以下软件包:
基本上,通过tikzpagenodes
它可以访问current page footer area
:
\newcommand{\myfooterstyle}[2][]{%
\tikz[remember picture,overlay]{%
\draw[#1]
($(current page footer area.south west)!0.25!(current page footer area.north west)$)
--
($(current page footer area.south)!0.25!(current page footer area.north)-(#2,0)$)
($(current page footer area.south)!0.25!(current page footer area.north)+(#2,0)$)
--
($(current page footer area.south east)!0.25!(current page footer area.north east)$)
;
}%
}
强制参数指定规则与页码的距离,而可选参数允许您访问可能的自定义项,如颜色或规则宽度。由于选项的存在,[remember picture, overlay]
需要运行两次编译。
然后,通过该background
包,每次都会执行该命令:
\AddEverypageHook{%
\myfooterstyle{1em}
\BgMaterial}
完整代码:
\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage[contents={}]{background}
\usepackage{lipsum}% for dummy text
\newcommand{\myfooterstyle}[2][]{%
\tikz[remember picture,overlay]{%
\draw[#1]
($(current page footer area.south west)!0.25!(current page footer area.north west)$)
--
($(current page footer area.south)!0.25!(current page footer area.north)-(#2,0)$)
($(current page footer area.south)!0.25!(current page footer area.north)+(#2,0)$)
--
($(current page footer area.south east)!0.25!(current page footer area.north east)$)
;
}%
}
\AddEverypageHook{%
\myfooterstyle{1em}
\BgMaterial}
\begin{document}
\lipsum[1-8]
\end{document}
外观:
答案3
重新定义你自己的风格:
\renewcommand{\@evenfoot}%
{\hfil\thepage\hfil}
\renewcommand{\@oddfoot}%
{\hfil\thepage\hfil}