
下面的程式碼為奇數側頁產生正確的間距,但為偶數側頁產生錯誤的間距。
正確的間距:
錯誤的間距:
當我嘗試從視覺上區分這兩個聲明時,我發現了三個差異:
- 我聲明為左頁腳而不是右頁腳。
- 我在偶數頁而不是奇數頁上聲明了頁腳。
- 我的聲明順序是相反的:我從
mark
第一個聲明中的 開始,然後\rlap
是它的旁邊。當我發出\llap
並跟隨我的時,會產生錯誤的間距mark
。
我可以在不發出 的情況下產生正確的間距\llap
,但我真的很想在那裡有我的頁碼。
如何去除\fancyfoot[LE]
聲明產生的多餘空間? / 如何在偶數頁上產生正確的間距,與奇數頁上的間距完全相同?
代碼:
\documentclass[twoside]{article}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{fancyhdr}
\newlength\titleindent
\setlength\titleindent{.25in}
\pagestyle{fancy}
\fancyhf{}
%\renewcommand{\sectionmark}[1]{\markboth{#1}{}}
%\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyfoot[RO]{%
\leftmark\strut\rlap{\hskip\titleindent\parbox{\titleindent}{\color{blue}\thepage\strut}}%
}%
\fancyfoot[LE]{%
\llap{\parbox{\titleindent}{\color{blue}\thepage\strut}}\leftmark\strut%
}%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{.4pt}
\begin{document}
\section{Section}
\lipsum\lipsum
\end{document}
答案1
正如egreg所說他的回答,\makebox
也用在這裡。
\documentclass[twoside]{article}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{fancyhdr}
\newlength\titleindent
\setlength\titleindent{.25in}
\pagestyle{fancy}
\fancyhf{}
%\renewcommand{\sectionmark}[1]{\markboth{#1}{}}
%\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyfoot[RO]{%
\leftmark\strut\makebox[0pt][l]{\hspace{\titleindent}\color{blue}\thepage\strut}%
}%
\fancyfoot[LE]{%
\makebox[0pt][r]{\color{blue}\thesection\hspace{\titleindent}}\leftmark\strut%
}%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{.4pt}
\begin{document}
\section{Section}
\lipsum\lipsum
\end{document}