亲爱的 LaTeX 用户们,大家好,
我对表格水平线的位置有困难。我在页脚中使用表格来获得带有页码的此类组合:
虽然对于奇数页来说一切都正常(如上所示),但对于偶数页来说,底线会向下移动,并且不与其他线相连:
我不知道哪里出了问题——奇数页和偶数页的表格代码相同。我很乐意得到任何帮助——这可能是一个细节,但真的很烦人。这是一个最小的工作示例:
\documentclass[12pt,a4paper,twoside]{book}
\usepackage[table]{xcolor}
\definecolor{red-fiz}{RGB}{194,0,11}
\usepackage{array,multirow}
\usepackage[left=3.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\setlength{\arrayrulewidth}{3pt}
\fancyhead{}
\fancyfoot{}
\fancyfoot[RO]{
\arrayrulecolor{red-fiz}
\begin{tabular}{m{0.91\textwidth}|m{0.03\textwidth}}
\cline{2-2}
& \multirow{2}{0.03\textwidth}{\thepage} \\ [0.03\textwidth]
\cline{1-1}
\end{tabular}}
\fancyfoot[LE]{
\arrayrulecolor{red-fiz}
\begin{tabular}{m{0.03\textwidth}|m{0.91\textwidth}}
\cline{1-1}\vspace{-10pt}
\multirow{2}{0.03\textwidth}{\thepage} & \\ [0.03\textwidth]
\cline{2-2}
\end{tabular}}
\begin{document}
\pagestyle{fancy}
\newpage\mbox{ }
\newpage\mbox{ }
\end{document}
另外,如您所见,目前使用额外的空格和 \vspace 将数字对齐到正方形的中心,但效果并不准确。有没有可能做得更好?
答案1
以下是使用的建议tikz
:
代码:
\documentclass[12pt,a4paper,twoside]{book}
\usepackage[left=3.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{tikz}
\definecolor{red-fiz}{RGB}{194,0,11}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}
\fancyfoot[RO]{%
\tikz[baseline=(n.base),line width=3pt,minimum size=2em]{
\node[anchor=base east](n)at(0,0){\thepage};
\draw[red-fiz]([xshift=-.5\pgflinewidth]n.north east)--(n.north west)
--(n.south west)--(n.south west-|({-\textwidth+.5\pgflinewidth},0);}%
}
\fancyfoot[LE]{%
\tikz[baseline=(n.base),line width=3pt,minimum size=2em]{
\node[anchor=base west](n)at(0,0){\thepage};
\draw[red-fiz]([xshift=.5\pgflinewidth]n.north west)--(n.north east)
--(n.south east)--(n.south east-|({\textwidth-.5\pgflinewidth},0);}%
}
\usepackage{blindtext}% dummy text
\begin{document}
\setcounter{page}{21}
\pagestyle{fancy}
\Blindtext[10]
\end{document}
答案2
以下是不使用 的替代方法tabular
。相反,使用 s 集合来设置规则\rule
(在框内构建并重复使用):
\documentclass[twoside]{book}
\usepackage{xcolor}
\definecolor{red-fiz}{RGB}{194,0,11}
\usepackage{geometry,graphicx}
\geometry{
margin=25mm,
left=35mm,
showframe,% Just for this example
paperheight=20\baselineskip% Just for this example
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\newlength{\frulewidth}\setlength{\frulewidth}{3pt}
\fancyhf{}% Clear fancy header/footer
\fancyfoot[RO]{%
\makebox[0pt][r]{\usebox{\footerrules}}% Rules
\makebox[0pt][r]{\makebox[0.1\textwidth][c]{\raisebox{.4\baselineskip}{\thepage}}}% Set the page number
}
\fancyfoot[LE]{%
\makebox[0pt][l]{\reflectbox{\usebox{\footerrules}}}% Rules
\makebox[0pt][l]{\makebox[0.1\textwidth][c]{\raisebox{.4\baselineskip}{\thepage}}}% Set the page number
}
\newsavebox{\footerrules}
\savebox{\footerrules}{% Construct the default (Right Odd page) rule
\color{red-fiz}% Rule colour
\rule{0.9\textwidth}{\frulewidth}% Lower horizontal
\makebox[0pt][r]{\rule{\frulewidth}{\dimexpr1.5\baselineskip+\frulewidth}}% Vertical
\rule[1.5\baselineskip]{0.1\textwidth}{\frulewidth}% Upper horizontal
}
\begin{document}
\newpage\mbox{}
\newpage\mbox{}
\end{document}