Following my question about the customisation of the section heading, I would like to have the box with the section number always in the outside of the page ( I am using the twoside option). That is, for odd pages, the box with the section number should be at the right, while for even pages, the box with the section number should be left.
For even pages:
and for odd pages:
Here comes the issues:
- I changed the code manually to get the section number at the desired place for the snippets. But, of course, this is not acceptable for big documents. Any help in doing this automatically?
- For odd pages, I could not manage to get the box outside the text area, as in even pages.
Once again, any guidance is welcome.
Here is my MWE:
\documentclass[openright]{scrbook}
\usepackage{geometry}
\geometry{a4paper,twoside, margin=3cm}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{xhfill}
\renewcommand{\sectionformat}{%
\usekomafont{section}%
\makebox[0pt][r]{%
\fboxrule=1.5pt\fcolorbox{blue}{white!0}{\color{black}\thesection}\color{blue}\rule[.6ex]{10pt}{1.5pt}
}%
}
\makeatletter
\renewcommand{\sectionlinesformat}[4]{%
@hangfrom{\hskip #2#3}{\color{blue}#4}$;$%
\xrfill[.6ex]{1.5pt}[blue]%
}
\makeatother
\begin{document}
\chapter{Introduction}
\section{Section 1}
\Blindtext[2]
\section{Section 2}
\Blindtext[2]
\section{Section 3}
\Blindtext[2]
\section{Section 4}
\Blindtext[2]
\end{document}
Thanks!


