Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Improve your question: Make a complete example. Also the title of your question says "scrartcl", but your question mentions \chapter. –  Ulrike Fischer Jun 24 '12 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 '12 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. –  Ulrike Fischer Jun 24 '12 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 '12 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"? –  Ulrike Fischer Jun 24 '12 at 13:35

1 Answer 1

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}
share|improve this answer
    
Works perfectly, thank you for your help. –  Stephan Jun 24 '12 at 14:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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