2

Starting from the accepted answer of

Customizing chapter and section style (scrbook)

I did the following to get customized section titles in a scrbook (Minimal (not) Working Example):

\documentclass[]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[german]{babel}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage{xcolor}


\newlength{\sectsquaresize}
\setlength\sectsquaresize{70pt}

\addtokomafont{section}{\fontsize{14pt}{14pt}\selectfont}

\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\color{black}}


\renewcommand\sectionformat{%
    \parbox{\sectsquaresize}{%
    \setlength\fboxsep{0pt}%
    \setlength\fboxrule{1pt}%
  \fbox{\colorbox{yellow}{%
      \parbox[m][\dimexpr \sectsquaresize -  2 \fboxrule][c]{\dimexpr \sectsquaresize - 2 \fboxrule}%
                {\centering{\usekomafont{sectionnumber}{\thesection\autodot}}}}}}%
    \quad%  
    }



\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \@hangfrom{\hspace*{#2}#3}{#4}%
  \ifstr{#1}{section}{%
    \par\nobreak%
    \ifstr{#3}{}{%
      \rule[\dp\strutbox]{\textwidth}{1pt}}{%
      \hspace*{\sectsquaresize}\rule[\dp\strutbox]{\dimexpr\textwidth-\sectsquaresize}{1pt}}%
  }{}%
}
\makeatother


\newcommand{\sectionproc}[1]{\parbox[m][\sectsquaresize][c]{\dimexpr\textwidth - \sectsquaresize - 17pt}{\raggedright #1}}
\newcommand{\ltdis}[1]{#1}

\setlength{\parindent}{0pt}

\begin{document}

\chapter{Erkrankungen des Bewegungsapparats}

\section[Rheumatoide Arthritis]{\sectionproc{Rheumatoide Arthritis\newline\ltdis{Arthritis rheumatoides}}}

\blindtext


\section[Rheumatismus]{\sectionproc{Rheumatismus\newline\ltdis{Rheumatismus}}}

\blindtext


\section[Arthrose mit besonderer Deformation der Gelenke]{\sectionproc{Arthrose mit besonderer Deformation der Gelenke\newline\ltdis{Arthrosis deformans, spondylosis deformans}}}

\blindtext


\section[Händezittern]{\sectionproc{Händezittern\newline\ltdis{Tendovaginitis}}}

\blindtext

\end{document}

In the output, the horizontal \rule, which starts horizontally after the framed yellow square and ends at the textline end, is vertically not aligned to the lower black frame line of the yellow square (as I wished it should be).

first page of text

I tried to introduce \vspace*{[a negative value]} after \par\nobreak to remedy this, but could not find a suitable expression which works in all cases.

\renewcommand\sectionlinesformat[4]{%
  \@hangfrom{\hspace*{#2}#3}{#4}%
  \ifstr{#1}{section}{%
    \par\nobreak%
    \ifstr{#3}{}{%
      \rule[\dp\strutbox]{\textwidth}{1pt}}{%
      \hspace*{\sectsquaresize}\rule[\dp\strutbox]{\dimexpr\textwidth-\sectsquaresize}{1pt}}%
  }{}%
}

What could I do to get the \rule aligned with the lower black frame line of the yellow square?

Sebastiano
  • 54,118

1 Answers1

2

Maybe the following does what you want:

\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[german]{babel}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{lmodern}% scalable font

\newlength{\sectsquaresize}
\setlength\sectsquaresize{70pt}

\addtokomafont{section}{\fontsize{14pt}{17pt}\selectfont}%<- changed
\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\color{black}}%<- changed

\renewcommand\sectionformat{%
  \setlength\fboxsep{0pt}%
  \setlength\fboxrule{1pt}%
  \fcolorbox{black}{yellow}{%
    \parbox[m][\dimexpr \sectsquaresize - 2 \fboxrule][c]{\dimexpr \sectsquaresize - 2 \fboxrule}%
       {\centering{\usekomafont{sectionnumber}{\thesection\autodot}}}}%
  \quad%
}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}{%
    \raisebox{\dimexpr\depth+\dp\strutbox\relax}{%
      \makebox[0pt][l]{\@hangfrom{\hspace*{#2}#3}{%
        \parbox[m][\sectsquaresize][c]{\dimexpr\textwidth - \sectsquaresize - 17pt}{\raggedsection #4}%
      }}%
    }%
    \ifstr{#3}{}{%
      \rule[\dp\strutbox]{\textwidth}{1pt}%
    }{%
      \hspace*{\sectsquaresize}\rule[\dp\strutbox]{\dimexpr\textwidth-\sectsquaresize}{1pt}%
    }%
  }{%
    \@hangfrom{\hspace*{#2}#3}{#4}% original definition for other section levels
  }
}
\makeatother

\newcommand{\ltdis}[1]{#1}

\setlength{\parindent}{0pt}
\begin{document}
\chapter{Erkrankungen des Bewegungsapparats}
\section[Rheumatoide Arthritis]{Rheumatoide Arthritis\newline\ltdis{Arthritis rheumatoides}}
\blindtext
\section[Rheumatismus]{Rheumatismus\newline\ltdis{Rheumatismus}}
\blindtext
\section[Arthrose mit besonderer Deformation der Gelenke]{Arthrose mit besonderer Deformation der Gelenke\newline\ltdis{Arthrosis deformans, spondylosis deformans}}
\blindtext
\section[Händezittern]{Händezittern\newline\ltdis{Tendovaginitis}}
\blindtext
\end{document}

Result:

enter image description here

esdd
  • 85,675
  • Thank you very much, your code worked very well! If I see it right, the essence of your idea was to put the @hangfrom{..#2..#3}{..#4..} stuff alltogether in a \makebox of width zero, raise this box and place a ruler under the raised box where necessary. So the solution also solves the general problem how to put a ruler under the content of a \makebox. – Jürgen Böhm Apr 15 '18 at 12:11