4

I want to achieve the following: In a twoside document I want to display the chapter title on even pages and the section (plus subsection if there is one) title on odd pages. So that for odd pages it looks like "section -- subsection" if there is a subsection and "section" otherwise. So far, I do it this way:

    \documentclass[a4paper, 12pt, twoside, openright, appendixprefix, BCOR7.5mm, pointlessnumbers, bibliography=totoc, listof=totoc]{scrreprt}
    \usepackage[utf8]{inputenc}
    \usepackage[american]{babel}
    \usepackage{blindtext}

    \usepackage{scrpage2}

    \begin{document}

    \pagestyle{scrheadings}
    \automark[subsection]{chapter}
    \renewcommand*{\sectionmark}[1]{%
        \markright{\ifnum \value{secnumdepth} >0 \sectionmarkformat\fi
        #1}}%
    \setheadsepline{.2pt}
    \ohead{\headmark}

    \chapter{Chapter 1}
    \section{section}
    \blindtext[15]

    \chapter{Chapter 2}
    \section{section}
    \subsection{subsection}
    \blindtext[15]

    \end{document}

This works so far in that it displays chapter and section OR subsections, respectively. Now I want to display both, section and subsection. How can I do this? Thank you.

Edit: Added example.

7
  • Improve your question: Make a complete example. Also the title of your question says "scrartcl", but your question mentions \chapter. Jun 24, 2012 at 10:49
  • Well, I am not sure what exactly I should write. I am using scrartcl as document class and scrpage2 to format my headers. Now I tried redefining \sectionmark so that it displays "section -- subsection" if a subsection exists and only "section" otherwise.
    – Stephan
    Jun 24, 2012 at 11:37
  • You should make a complete example. One that starts with \documentclass and ends with \end{document} and so enables us to make sensible tests. Jun 24, 2012 at 12:45
  • I see. Well, this would be my example then. It basically does what I want but only displays the section OR subsection title and not both.
    – Stephan
    Jun 24, 2012 at 13:26
  • What would you want in the header if you have on one page "section, subsection, section". What if there is only a section? What if there is "subsection, section, subsection"? Jun 24, 2012 at 13:35

1 Answer 1

4

Try this

 \documentclass[a4paper, 12pt, twoside, openright, appendixprefix, BCOR7.5mm, pointlessnumbers, bibliography=totoc, listof=totoc]{scrreprt}
    \usepackage[utf8]{inputenc}
    \usepackage[american]{babel}
    \usepackage{blindtext}
    \usepackage{extramarks}
    \usepackage{scrpage2}
    \newcommand\currentsectionmark{}
    \pagestyle{scrheadings}
    \automark[subsection]{chapter}

    \renewcommand*{\sectionmark}[1]{%
        \markright{\ifnum \value{secnumdepth} >0 \sectionmarkformat\fi
        #1}\def\currentsectionmark{\ifnum \value{secnumdepth} >0 \sectionmarkformat\fi
        #1}}%

    \renewcommand*\subsectionmark[1]{%
     \markright{\currentsectionmark\ -- \subsectionmarkformat #1}}    
    \setheadsepline{.2pt}
    \lehead{\leftmark}
    \rohead{\lastrightmark}

    \begin{document}


    \chapter{Chapter 1}
        blub
    \newpage
    blub
    \newpage
    \section{section}
    \section{section 2}
    \blindtext[15]

    \chapter{Chapter 2}
        blub
    \newpage
    blub
    \newpage
    \section{section}
    \section{section 2}
    \subsection{subsection}
    \blindtext[15]
    \chapter{Chapter 2}
    blub
    \newpage
    blub
    \newpage
    \section{section}
    \subsection{subsection}
    \section{section 2}
    \blindtext[15]

    \chapter{Chapter 2}
    blub
    \newpage
    blub
    \newpage
    \section{section}
    \newpage
    \subsection{subsection}
    \subsection{subsection 2}
    \blindtext[35]
    \end{document}
0

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.