為什麼 \markboth 不起作用?

為什麼 \markboth 不起作用?

我正在嘗試為我正在寫的一本書製作自己的標題。我想在兩個標題之間交替:「左」和「右」我的問題是:當我使用 時,我沒有列印出左和右\markboth

代碼是

\documentclass{book}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{graphics,color}
\usepackage[superscript]{cite}

\begin{document}
\pagestyle{myheadings}
\markboth{Right}{Left}

First page
\newpage
Second page
\newpage
Third page
\newpage
Fourth page

 \end{document}

這提供了:
在此輸入影像描述

第二頁:
在此輸入影像描述

但我想要這樣(如下):
在此輸入影像描述

第二頁:
在此輸入影像描述

第三:
在此輸入影像描述

第四:
在此輸入影像描述

答案1

您發布的所需輸出的圖片包括標題下的規則和減少的邊距。要設定邊距,最好的選擇是使用套件geometry。對於標頭,該fancyhdr包提供了所需的設施。使用您的語法(確實有Right並且是Left錯誤的方式),您可以編寫:

樣本頁2

\documentclass[a4paper,12pt]{book}

\usepackage[vmargin=0.2cm,hmargin=1cm,head=16pt,includeheadfoot]{geometry}
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\slshape\rightmark}
\fancyhead[RE]{\slshape\leftmark}
\pagestyle{fancy}

\begin{document}

\markboth{Right}{Left}
\thispagestyle{empty}

First page
\newpage
Second page
\newpage
Third page
\newpage
Fourth page

\end{document}

\pagestyle{empty}確保第一頁(或命令所在的頁面)沒有標題。

要使用\markboth標準方法,您應該使用:

\documentclass[a4paper,12pt]{book}

\usepackage[vmargin=0.2cm,hmargin=1cm,head=16pt,includeheadfoot]{geometry}
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\slshape\leftmark}
\fancyhead[RE]{\slshape\rightmark}
\pagestyle{fancy}

\begin{document}

\markboth{Left}{Right}
\thispagestyle{empty}

First page
\newpage
Second page
\newpage
Third page
\newpage
Fourth page

\end{document}

相關內容