有人能帮我正确使用\markboth{}{}
重新定义\sectionmark
吗?我正在努力应用第二个参数\markboth
。我正在写的文章需要在所有页面上都有章节和小节标题。我读过由于小节原因,标题在章节页面上显示不正确并理解\chapter
或\section
命令会使\markright
字段为空,因此子部分不会出现在发出\chapter
或的页面上\section
。我仍然不明白如何做到这一点。我将不胜感激任何帮助。
PS. 以下是 LaTeX 代码。我正在使用 XeLaTeX 编写本文。
\documentclass[11pt]{article}
\special{papersize=210mm,297mm}
\title{\bfseries Factor Analysis}
\author{J. Smith}
% Set font
\usepackage{unicode-math}
\setmainfont[Ligatures=TeX]{Cambria}
\setmathfont{Cambria Math}
% if then
\usepackage{ifthen}
\usepackage[a4paper,portrait,hmargin=2.54cm,vmargin=2.54cm,bindingoffset=0cm,includehead,includefoot]{geometry} % Document margins
\geometry{headheight=14pt}
% Multi columns
%\usepackage{paralist} % Used for the "compactitem" environment which makes bullet points with less space between them
\usepackage{multicol} % Used for the two-column layout of the document
\setlength{\columnsep}{20pt}
% Fancy headers
\usepackage{fancyhdr} % Headers and footers
\pagestyle{fancy} % All pages have headers and footers
\fancyhf{} % clear all headers and footers - equivalent to %\fancyhead{} and \fancyfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\newcommand{\mymarks}{
\ifthenelse{\equal{\rightmark}{}} % is \rightmark empty?
{\leftmark} % when empty
{\leftmark\ --\ \itshape\rightmark} % when not empty
}
\renewcommand{\sectionmark}[1]{\markboth{\thesection.\ #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\fancyhead[C]{\mymarks} % Custom header text
\fancyfoot[C]{\thepage} % Custom footer text
\usepackage{graphicx}
\usepackage{url} % allows escaping special characters inside a hyper links in a bibliography such as %20 etc.
\usepackage[round]{natbib}
\usepackage{setspace}
\usepackage[format=hang,font=small,labelfont=bf]{caption} % Custom captions under/above floats in tables or figures
% Links in PDF
%\usepackage[hidelinks]{hyperref}
\usepackage{hyperref}
\hypersetup{
bookmarks=false, % show bookmarks bar?
pdftoolbar=true, % show Acrobat’s toolbar?
pdfmenubar=true, % show Acrobat’s menu?
pdffitwindow=false, % window fit to page when opened
pdfstartview={FitH}, % fits the width of the page to the window
pdftitle={Exposure response relationship to noise in the presence of vibration}, % title
pdfauthor={Zbigniew Koziel}, % author
pdfsubject={Environmental Noise and Vibration}, % subject of the document
pdfcreator={Zbigniew Koziel}, % creator of the document
pdfproducer={Zbigniew Koziel}, % producer of the document
pdfkeywords={noise} {vibration} {exposure response-relationship}, % list of keywords
pdfnewwindow=true, % links in new window
colorlinks=true,
citecolor=blue,
linkcolor=red, % color of internal links (change box color with linkbordercolor)
urlcolor=blue,
filecolor=black % color of file links
}
% Change default commands
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}
% New commands
\newcommand{\defaultvspacing}{\doublespacing}
\newcommand{\compactvspacing}{\onehalfspacing}
\newcommand{\tidyvspacing}{\singlespacing}
\newcommand{\myterm}[2]{$#1_{\mathrm{#2}}$}
\newcommand{\defvspace}{12pt}
\newcommand{\clearthepage}{\clearpage} % depending on one or two side
\newcommand{\mysection}[2]{\clearthepage\markright{#2}\section{#1}}
\begin{document}
\tidyvspacing
\maketitle
\begin{abstract}
The abstract
\end{abstract}
\tableofcontents
\compactvspacing
\include{introduction}
\include{conceptual_view}
\include{fa_and_sm}
\include{the_factor_model}
\include{interpeting_factor_tables}
\bibliography{thesis} % Here from this place, the Bibliography should appear !
% \bibliographystyle{plain} % Standard commands for BiBTeX
\bibliographystyle{plainnat} % Extended commands from package natbib
\end{document}
答案1
是的,短节和小节的标记问题是 LaTeX 标记的一个众所周知的问题。如果您愿意使用其他软件包,这里有一个解决方案,使用titlesec
及其选项pagestyles
和extramarks
(我删除了与讨论的问题无关的原始代码部分):
\documentclass[11pt]{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{lipsum}% just to generate text for the example
\usepackage{ifthen}
\usepackage[pagestyles,extramarks]{titlesec}
\settitlemarks*{section,subsection}
\newpagestyle{mystyle}{
\headrule\footrule
\sethead{}{\thesection.\ \sectiontitle\ifthesubsection{\ --\ \itshape\firstextramarks{subsection}\subsectiontitle}{}}{}
\setfoot{}{\thepage}{}
}
\pagestyle{mystyle}
\begin{document}
\section{Test Section One}
\lipsum[4]
\subsection{Test Subsection One}
\lipsum[1]
\section{Test Section Two}
Some test text here
\end{document}