
我想在一本書的頁首中添加徽標。徽標應位於奇數/偶數頁的左側或右側角。請幫我修正我的程式碼:
\documentclass[
paper=a4, % it's the default anyway
fontsize=12pt,
twoside
]{book}
\usepackage[paperwidth=7.25in, paperheight=9.5in,bindingoffset=.75in]{geometry}
\usepackage{fancyhdr}
\usepackage{makeidx} % allows index generation
\usepackage[demo]{graphicx}
\pagestyle{fancy}
{%
\fancyhead[L]{\includegraphics[width=1.5cm,height=1.5cm,keepaspectratio]{logo.eps}}
\fancyhead[R]{\includegraphics[width=1.5cm,height=1.5cm,keepaspectratio]{logo.eps}}}
\setlength{\headheight}{47.0pt}
\addtolength{\topmargin}{-4\baselineskip}
\usepackage{lipsum}
\begin{document}
\lipsum
\newpage
\lipsum
\end{document}
答案1
包fancyhdr
在預設情況下使用一些已棄用的命令。但在使用\fancyhf
並清除預設值之後,這不再重要了(謝謝艾格雷格)。
我建議使用scrlayer-scrpage
KOMA-bundlea 中的軟體包。語法非常相似。\lehead
代表左偶數頭,\rohead
為右奇數頭。頁尾\lofoot
(等)的命名約定類似\cefoot
。
\documentclass{book}
\usepackage[paperwidth=7.25in,
paperheight=9.5in,bindingoffset=.75in]{geometry}
\usepackage[headsepline]{scrlayer-scrpage}
\usepackage{mwe}
\lehead{\includegraphics[height=1.5cm,keepaspectratio]{example-image-a}}
\rohead{\includegraphics[height=1.5cm,keepaspectratio]{example-image-b}}
\setlength{\headheight}{47.0pt}
\begin{document}
\lipsum[1-20]
\end{document}
注意:book
設定外頭的頁碼。scrlayer-scrpage
如果用戶請求,包將覆蓋它。包fancyhdr
只是覆蓋書籍的設置,無需用戶互動。
答案2
fancyhdr
提供O
dd 和E
ven 頁面放置以及在頁面的L
左側或右側之間進行選擇。R
因此,對於dd 頁面L
上的左端,請使用,而對於ven 頁面上的右端,請使用:O
LO
R
E
RE
\documentclass[twoside]{book}
\usepackage[paperwidth=7.25in, paperheight=9.5in,bindingoffset=.75in]{geometry}
\usepackage{fancyhdr,graphicx,lipsum}
\pagestyle{fancy}
\fancyhead[LO]{\includegraphics[width=1.5cm,height=1.5cm,keepaspectratio]{example-image-a}}
\fancyhead[RE]{\includegraphics[width=1.5cm,height=1.5cm,keepaspectratio]{example-image-b}}
\setlength{\headheight}{47.0pt}
\begin{document}
\lipsum[1-20]
\end{document}
請注意,book
文檔類別問題\thispagestyle{plain}
位於每個\chapter
.在這些情況下,您將遺失fancy
頁面樣式,除非您重新發布\pagestyle{fancy}
或重新定義plain
。