4

I'm having troubles setting the header of a two-sided document. I need only the chapter number (not necessarily) and name in the header at left for even pages and at right for odd pages; I don't want a section title not the word "Chapter" in each page. So far I've try this with fancyhdr:

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

which gives the correct output of chapter but in left for odds and viceversa, plus it doesn't remove the section header. Also, I try with

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead[]{\thechapter}
\chead{}[\thechapater]

But this only puts the chapter number and adds a horrible 0 in the pages before contents (declaration, acknowledgements, dedication, etc.). I am using documentclass scrreprt.

Thanks!

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – karlkoeller Feb 19 '14 at 15:33
  • In reaction to your comment below Karl Koeller’s answer: Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Speravir Feb 19 '14 at 17:12
4

It would be better not to use the package fancyhdr with KOMA classes like scrreprt.

One of the dedicated packages scrpage2 or scrpage-scrlayer should be used instead.

In your case, it suffices to load the latter and use the page style scrheadings with the following modifications:

\renewcommand*\chaptermarkformat{\thechapter\autodot\enskip}
\automark[chapter]{chapter}

The first line is to eliminate the word "Chapter" from the header and the latter is to place the chapter mark both in even and odd pages.

If you don't want chapter numbers replace the first line with

\renewcommand*\chaptermarkformat{}

MWE:

\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}

Output:

enter image description here

If you want the header line load scrlayer-scrpage with the option headsepline:

\usepackage[headsepline]{scrlayer-scrpage}

Instead, if you want to swap the sides where headers are printed, you have to define an own style, like this:

\defpagestyle{mystyle}{%
{\hfill\headmark}{\headmark\hfill}{\hfill}
}{%
{\hfill}{\hfill}{\hfill}
}

and use \pagestyle{mystyle} instead of \pagestyle{scrheadings}.

MWE

\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} 

Output:

enter image description here

  • Thank you, it worked perfectly for all the pages in chapters but it puts CONTENTS in capitals in the contents pages. I try with \pagestyle{plain} but it swaps away every headline and \thispagestyle{plain} but it won't work if my contents go beyond one page. Suggestions? – Cecilia Guerra Feb 19 '14 at 17:06
  • @CeciliaGuerra I cannot see this side effect. Do you have any setting that may cause this behavior? – karlkoeller Feb 19 '14 at 17:11
  • @karlkoeller, I don't think so. – Cecilia Guerra Feb 19 '14 at 17:22
  • @CeciliaGuerra Try adding nouppercase to the options of scrpage2. If it doesn't work, please add a minimal (non) working example (MWE) – karlkoeller Feb 19 '14 at 17:33
  • now it just go with "Contents"; looks much better. Thanks! – Cecilia Guerra Feb 19 '14 at 21:14
0

Although titlesecis not fully compatible with komascript (see here and there, I give a solution with titleps (included in 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} 

enter image description here

I had to re-define a style for the first page, as the default page numbering does not match the one I defined for the others. This is just to illustrate what one can do with titleps.

enter image description here

  • @Speravir: I didn't noticed that point when I read the question. Was it added afterwards, or am I that absent-minded? Anyway, I'll add a link in my answer – which I think may help users that don't know very well titlesec. – Bernard Feb 19 '14 at 17:31
  • Ah, yes. Karl Koeller added the tag. – Speravir Feb 19 '14 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.