從 LaTeX 中的標題中刪除部分名稱

從 LaTeX 中的標題中刪除部分名稱

我正在嘗試刪除標題中的部分名稱。我正在使用fancyhdr包。當我嘗試在 中指定新文字時\lhead{},文字僅覆蓋在部分名稱上。 PS 3小時的Google搜尋沒有幫助。

這是我想要運行的程式碼部分。

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Student ID: 1123123/1}
\chead{University}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{Page \thepage\ of \pageref{LastPage}}

更新:\fancyhf{}不起作用 - 沒有任何變更。

由 Speravir 編輯 - 範例取自http://pastebin.com/W6V​​9GUCs
(OP給出的鏈接對貢薩洛的回答發表評論):

\documentclass{report}
\usepackage[a4paper]{geometry}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{fullpage, graphicx, wrapfig, subcaption, setspace}
\usepackage[T1]{fontenc}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage{fourier}
\usepackage[protrusion=true, expansion=true]{microtype}
\usepackage[english]{babel}

\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\onehalfspacing

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HEADER & FOOTER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Student ID: 1123123/1}
\fancyhead[C]{University}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TITLE PAGE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\title{ \normalsize \textsc{SUBTITLE}
        \\ [2.0cm]
        \HRule{0.5pt} \\
        \LARGE \textbf{\uppercase{TITLE}}
        \HRule{2pt} \\ [0.5cm]
        \normalsize \today
}

\date{}

\author{\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\
        SID:  \\ 
        University \\
        Department of Life Sciences
}

\maketitle

\pagebreak


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BODY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{\textsc{SECTION}}

\end{document}

答案1

若要清除頁首和頁尾中的所有預定義字段,請\fancyhf{}在指派頁首和頁尾之前使用。另外,最好使用現代語法\fancyhead\fancyfoot

\documentclass{article}
\usepackage[a5paper]{geometry}% just for the example
\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{lipsum}% just to generate text for the example

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{Student ID: 1123123/1}
\fancyhead[C]{University}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage}}

\begin{document}

\section{Test Section}
\lipsum[1-40]

\end{document}

在此輸入影像描述

提供了MWE後,很明顯問題出在fullpage包的使用上沒有選項headings;由於使用了頁首/頁尾並且未傳遞該選項,因此頁首和文字區域重疊。解決方法就是fullpage如下載入

\usepackage[header]{fullpage}

順便說一句,由於geometry也使用了包,所以我認為有一些冗餘;您只能使用這些套件之一,具體取決於所需的頁面佈局。

我還對作為 MWE 提供的文件進行了一些其他更改;特別是,我使用該sectsty套件對部分標題使用小型大寫字母(這是手動製作的),並抑制了多個連續\\命令的錯誤使用(產生未滿的壞框)。

我還建議不要(ab)使用\title\author命令來設計完整的標題頁(例如,這可能會對書籤產生不良影響),而是設計自訂的標題頁。

顯示提到的變更的程式碼:

\documentclass{report}
\usepackage[a4paper]{geometry}
\usepackage[myheadings]{fullpage}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx, wrapfig, subcaption, setspace}
\usepackage[T1]{fontenc}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage{fourier}
\usepackage[protrusion=true, expansion=true]{microtype}
\usepackage[english]{babel}
\usepackage{sectsty}

\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\onehalfspacing

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HEADER & FOOTER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{fancy}
\fancyhf{}
\setlength\headheight{12pt}
\fancyhead[L]{Student ID: 1123123/1}
\fancyhead[C]{University}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TITLE PAGE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title{\normalsize \textsc{SUBTITLE}
                \\[2.0cm]
                \HRule{0.5pt} \\
                \LARGE \textbf{\MakeUppercase{TITLE}}
                \HRule{2pt} \\[0.5cm]
                \normalsize\today\vspace*{10\baselineskip}
}

\date{}

\author{
                SID:  \\
                University \\
                Department of Life Sciences}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Section title formatting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\sectionfont{\scshape}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BODY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\maketitle

\newpage
\section*{Section}

\end{document}

相關內容