
\documentclass[twoside,11pt]{book}
\usepackage{fancyhdr,xcolor,lipsum}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\colorlet{myfancycolor}{black}
\fancypagestyle{mystyle}{
\renewcommand*\footrulewidth{1pt}
\fancyfoot[OR]{%
\color{myfancycolor}\rule{2em}{2em}\raisebox{0.5em}{\hspace{-2em}\color{white}\makebox[2em][c]{\textsf{\thepage}}}%
\vspace*{-0.8em}%
}
\fancyfoot[OL]{%
\leftmark
}
\fancyfoot[EL]{%
\color{myfancycolor}\rule{2em}{2em}\raisebox{0.5em}{\hspace{-2em}\color{white}\makebox[2em][c]{\textsf{\thepage}}}%
\vspace*{-0.8em}%
}
\fancyfoot[ER]{%
\rightmark
}
}
\pagestyle{mystyle}
\begin{document}
\frontmatter
\chapter{PREFACE}
\lipsum[1-2]
\tableofcontents
\mainmatter
\chapter{LALALA}
\lipsum[1-3]
\end{document}
我希望盒子頁碼如下:
我嘗試將 的值更改\raisebox
為 -1 em、-2 em,但它無法更改佈局。
如何讓盒子頁碼對齊?
答案1
您可以刪除\renewcommand\footrulewidth{1pt}
並建立自己的\hrule
(即不由\hrule
使用過的套件產生)。您\hrule
可以緊跟其後,因此和\hbox
之間沒有空格。例如,它可以如下所示:\hrule
\hbox
\fancyfoot[EL]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
答案2
把整件事情放在另一個\raisebox
:
\raisebox{4pt}[2em]{\color{myfancycolor}\rule{2em}{2em}\raisebox{0.5em}{\hspace{-2em}\color{white}\makebox[2em][c]{\textsf{\thepage}}}%
\vspace*{-0.8em}}