# How to print “string” of first or last \label{string}, in running headers and margins, dictionary-like, with KOMA class?

I need to typeset a book where sections are identified by a string, like "PLA 1", as dictated by the book's editor (the publisher calls these strings "cite-keys".)

Sometimes there are a few sections on a given book spread, which means a few cite-keys.

• These cite-keys need to be printed on the outer margin, on the same line as the section.
• Also, the first current cite-key of a left page must be printed in even-page running headers.
• The last current cite-key appearing on a right page must be in odd-page running headers.

How can one print those special strings in running headers and in margins?

I thought of using \label{SCA 1}, but then I realized \labels are actually counters.

I tried to use \marks (with the emarks package), but I can't figure it out.

Work-in-progress MWE:

\documentclass{scrbook}

\usepackage{lipsum}

\documentclass{scrbook}

\usepackage{lipsum}

\usepackage{scrpage2}

\begin{document}
\section*{Section title}\label{PLA 1}
\lipsum[1]

Label string should be here \nameref{PLA 1}

\end{document}


I need to use Koma class. I saw somewhere people using fancyhdr or titlesec, but Koma manual advice against either or them (for example, the titlesec package interferes with the option headings=optiontotoc).

I saw a few questions answered on http://tex.stackexchange.com, but none has enough pointers to get me started.

• Welcome to TeX.SX! – user31729 Sep 29 '14 at 17:17
• Your MWE doesn't really show a dictionary, it shows something you suppose is necessary for the solution, but probably it is not (see also XY Problem). Please make your code reflect what your true intention is. And btw, Section 10 of the fancyhdr manual describes a method that is not so much dependent on fancyhdr itself, you just ought to use the KOMA commands for modifying the headers instead of \fancyhead; this could make a good starting point for you. – yo' Sep 29 '14 at 18:11
• Thank you for pointing out that particular fancyhdr section would possibly not disturb KOMA inner commands. The book is actually not a dictionary, perhaps more of a reference book. I will refine the MWE as soon as I can wrap my head around the fancyhdr example. Thank you so much. – gsl Sep 29 '14 at 18:18

Here is a suggestion using the package scrlayer-scrpage

\documentclass{scrbook}

\usepackage{lipsum}% dummy text
\usepackage{needspace}
\usepackage[manualmark]{scrlayer-scrpage}
\clearpairofpagestyles

%%% alternatively:
%\usepackage[manualmark]{scrpage2}

\renewcommand\chaptermark[1]{\markboth{}{}}

\needspace{3\baselineskip}%
}

\begin{document}
\tableofcontents
\chapter{Chapter Title}
\lipsum[1]
\lipsum[1-3]
\lipsum[1]
\lipsum[1-5]

• Thank you, that is perfect. I was struggling with fancyhdr, as suggested by others, but they may not be aware that, if one uses many aspects of koma class, fancyhdr will interfere with it at some point. Your solution is simple and elegant. Very nice, thank you. – gsl Oct 2 '14 at 6:40