我在设置双面文档的页眉时遇到了麻烦。我只需要在偶数页左侧的页眉和奇数页右侧的页眉中显示章节编号(不一定)和名称;我不想在每页中都有章节标题而不是单词“章节”。到目前为止,我已经尝试过fancyhdr
:
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
它给出了正确的章节输出,但赔率在左边,反之亦然,而且它不会删除章节标题。此外,我尝试使用
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead[]{\thechapter}
\chead{}[\thechapater]
但这只会添加章节编号,并在内容(声明、致谢、献词等)之前的页面中添加一个可怕的 0。我正在使用 documentclass scrreprt
。
谢谢!
答案1
最好不要将这个包fancyhdr
与类似 KOMA 类一起使用scrreprt
。
应该使用专用包之一scrpage2
或。scrpage-scrlayer
对于您来说,只需加载后者并使用scrheadings
经过以下修改的页面样式即可:
\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}
\automark[chapter]{chapter}
第一行是从页眉中删除“章节”一词,后者是在偶数页和奇数页都放置章节标记。
如果你不想要章节编号,请将第一行替换为
\renewcommand*\chaptermarkformat{}
梅威瑟:
\documentclass[twoside,openright,chapterprefix=true]{scrreprt}
\usepackage{lipsum} % only for the example
\usepackage{scrlayer-scrpage}
\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}
\automark[chapter]{chapter}
\pagestyle{scrheadings}
\begin{document}
\chapter{Test}
\lipsum[1-5]
\section{A section}
\lipsum[1-5]
\end{document}
输出:
如果您希望标题行加载scrlayer-scrpage
以下选项headsepline
:
\usepackage[headsepline]{scrlayer-scrpage}
相反,如果您想交换打印标题的两侧,您必须定义自己的样式,如下所示:
\defpagestyle{mystyle}{%
{\hfill\headmark}{\headmark\hfill}{\hfill}
}{%
{\hfill}{\hfill}{\hfill}
}
并使用\pagestyle{mystyle}
代替\pagestyle{scrheadings}
。
平均能量损失
\documentclass[twoside,openright,chapterprefix=true]{scrreprt}
\usepackage{lipsum} % only for the example
\usepackage{scrlayer-scrpage}
\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}
\automark[chapter]{chapter}
\defpagestyle{mystyle}{%
{\hfill\headmark}{\headmark\hfill}{\hfill}
}{%
{\hfill}{\hfill}{\hfill}
}
\pagestyle{mystyle}
\begin{document}
\chapter{Test}
\lipsum[1-5]
\section{A section}
\lipsum[1-5]
\end{document}
输出:
答案2
虽然titlesec
不完全兼容komascript
(见这里和那里,我给出了一个解决方案titleps
(包含在中titlesec
):
\documentclass[11pt, twoside]{book}% http://ctan.org/pkg/amsproc
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{titlesec}
\usepackage{lettrine}
\newpagestyle{mine}{%
\sethead[\hskip1em\Roman{chapter}. \itshape\chaptertitle][][]{}{}{\Roman{chapter}. \itshape\chaptertitle\hskip1em}
\setfoot{}{\textendash\,\thepage\,\textendash}{}
\widenhead[1em][0pt]{0pt}{1em}
\setheadrule{0.6pt}
\headrule
}
\newpagestyle{first}{%
\sethead{}{}{}
\setfoot{}{\textendash\,\thepage\,\textendash}{}
}
\pagestyle{mine}%
\begin{document}
\setcounter{chapter}{9}
\chapter{A Chapter upon chapters}
\thispagestyle{first}
\lettrine{I}{s it not} a shame to make two chapters of what passed in going down one pair of stairs? for we are got no farther yet than to the first landing, and there are fifteen more steps down to the bottom; and for aught I know, as my father and my uncle \emph{Toby} are in a talking humour, there may be as many chapters as steps;—let that be as it will, Sir, I can no more help it than my destiny:—A sudden impulse comes across me——drop the curtain, \emph{Shandy}—I drop it——Strike a line here across the paper, \emph{Tristram}—I strike it—and hey for a new chapter!
\newpage
The duce of any other rule have I to govern myself by in this affair—and if I had one—as I do all things out of all rule—I would twist it and tear it to pieces, and throw it into the fire when I had done—Am I warm? I am, and the cause demands it—a pretty story! is a man to follow rules—or rules to follow him?
\newpage
Now this, you must know, being my chapter upon chapters, which I promised to write before I went to sleep, I thought it meet to ease my conscience entirely before I lay’d down, by telling the world all I knew about the matter at once: Is not this ten times better than to set out dogmatically with a sententious parade of wisdom, and telling the world a story of a roasted horse—that chapters relieve the mind—that they assist—or impose upon the imagination—and that in a work of this dramatic cast they are as necessary as the shifting of scenes—with fifty other cold conceits, enough to extinguish the fire which roasted him.—O! but to understand this, which is a puff at the fire of \emph{Diana}’s temple—you must read \emph{Longinus}—read away—if you are not a jot the wiser by reading him the first time over—never fear—read him again—\emph{Avicenna} and \emph{Licetus}, read \emph{Aristotle}’s metaphysicks forty times through a piece, and never understood a single word.—But mark the consequence—\emph{Avicenna} turned out a desperate writer at all kinds of writing—for he wrote books \emph{de omni scribili}; and for \emph{Licetus} (\emph{Fortunio}) though all the world knows he was born a fœtus, of no more than five inches and a half in length, yet he grew to that astonishing height in literature, as to write a book with a title as long as himself——the learned know I mean his \emph{Gonopsychanthropologia}, upon the origin of the human soul. So much for my chapter upon chapters, which I hold to be the best chapter in my whole work; and take my word, whoever reads it, is full as well employed, as in picking straws.
\end{document}
我必须重新定义第一页的样式,因为默认页码与我为其他页面定义的页码不匹配。这只是为了说明如何使用titleps
。