Board logo

標題: [LaTeX] 版面設定→頁首、頁尾(fancyhdr 套件) [打印本頁]

作者: weiye    時間: 2008-3-12 10:05     標題: [LaTeX] 版面設定→頁首、頁尾(fancyhdr 套件)

先引用 fancyhdr 套件,以設定頁首、頁尾
複製內容到剪貼板
代碼:
\usepackage{fancyhdr}
\pagestyle{fancy}
一、簡單快速設定

在頁首、頁尾的左、中、右都放一些文字,
頁尾的中間顯示 "第 X 頁"。
複製內容到剪貼板
代碼:
\lhead{頁首左邊的文字}
\chead{頁首中間的文字}
\rhead{頁首右邊的文字}

\lfoot{頁尾左邊的文字}
\cfoot{第~\thepage~頁}
\rfoot{頁尾右邊的文字}
如果有設定邊界(geometry 套件),看起來會比較好看。

二、奇數、偶數頁不同設定

下面的 E, O, L, C, R, H, F 分別表示偶數、奇數、置中、置右、置左、頁首、頁尾
複製內容到剪貼板
代碼:
\fancyhead{} % 清除所有頁首設定
\fancyhead[RO,LE]{\bfseries 頁首的``奇數頁右''及``偶數頁左''}
\fancyfoot{} % 清除所有頁尾設定
\fancyfoot[LE,RO]{第~\thepage~頁}      % 頁碼放在偶數頁的左邊及奇數頁的右邊
\fancyfoot[LO,CE]{奇數頁左及偶數頁中}
\fancyfoot[CO,RE]{奇數頁中及偶數頁右}
\renewcommand{\headrulewidth}{0.4pt} % 設定頁首多一條粗細是 0.4 pt 的水平線
\renewcommand{\footrulewidth}{0.4pt} % 設定頁首多一條粗細是 0.4 pt 的水平線
參考資料: http://www.ctan.org/tex-archive/macros/latex/contrib/fancyhdr/fancyhdr.pdf
作者: wushing    時間: 2010-10-22 12:01

謝謝…整理的真好
作者: zidanesquall    時間: 2015-12-9 10:42

想請教一下,我是用exam 環境下製作考卷

我使用fancyhdr製作頁首頁尾,會出現問題...

會出現
「Command \lhead already defined. Or name \end... illegal, see p.192 of the manual.
    See the LaTeX manual of LaTeX Companion for explanation. Type H <return> for immediate help.
    l.266 ... \lhead}{\@ifnextchar}{\@xlhead}{\@ylhead}」

這是我的設定碼

\documentclass[12pt,b4paper]{exam}

\usepackage{fontspec} % 允許設定字體
\usepackage{amsmath,amsthm,amssymb}
\usepackage{xeCJK} % 分開設置中英文字型
\setCJKmainfont{Kaiti TC} % 設定中文字型
%\setmainfont{Georgia} % 設定英文字型
%\setromanfont{Georgia} % 字型
%\setmonofont{Courier New}
\usepackage{Rvector}
\usepackage{stmaryrd}
\usepackage[left=1cm, right=1cm, bottom=1.9cm]{geometry}
\renewcommand\choicelabel{(\thechoice)} %將選擇題選項改成(A)....
\XeTeXlinebreaklocale "zh" % 針對中文自動換行
\XeTeXlinebreakskip = 0pt plus 1pt % 字與字之間加入0pt至1pt的間距,確保左右對整齊
%\parindent 0em % 段落縮進
%\setlength{\parskip}{20pt} % 段落之間的距離

\extrawidth{+0.6in}
\pointsinmargin
\marginpointname{\%}


\usepackage{fancyhdr}
%\usepackage{lastpage}
\pagestyle{fancyplain}
\lhead{\fancyplain{}{FoolEgg.com}} % 左頁首
\chead{} % 中頁首
\rhead{\fancyplain{}{在OSX平台上的XeLaTeX中文測試}} % 右頁首
\lfoot{} % 左頁尾
\cfoot{\fancyplain{}{\thepage\ of \pageref{LastPage}}} % 中頁尾
\rfoot{} % 右頁尾
\begin{document}
...
\end{document}


反而使用
\pagestyle{headandfoot}
\firstpageheader{\large\bf 1.答案卡\\\LARGE{104學年度第1學期第2次期中考高三數學科題目卷}\\班級:$\qquad\qquad$姓名:$\qquad\qquad\qquad$座號:$\quad$}{}{}

這樣子就沒有問題@@




歡迎光臨 Math Pro 數學補給站 (https://math.pro/db/) 論壇程式使用 Discuz! 6.1.0