2

I would like to display on the first page of every chapter, the chapter's name, followed by some spacing and then the chapter's number in big numerals. It should look something like the following, except in black or dark grey. My problem is, that I found a few solutions, but they are all with titlesec, but I'm using fancyhdr and it doesn't seem to be compatible. And I'm using scrreprt and can't switch to memoir. And it's also important that only the chapters are affected and not table of contents or list of figures.

I really like this example, but I don't understand how to make the number look different (more like the one in the picture) and how tho align the number with the paragraph. enter image description here

esdd
  • 85,675
  • Titlesec is compatible with fancyhdr. What's not compatible is its titleps, which does the same job as fancyhdr (in a simpler way, i.m.o.), which is loaded if you use the [pagestyle] option of titlesec. – Bernard Jan 21 '21 at 12:44
  • titlesec is not really compatible with scrreprt. – egreg Jan 25 '21 at 15:14

2 Answers2

2

Here is a suggestion based on the code linked in the question:

\documentclass
  %[parskip=half]
  {scrreprt}
\usepackage{lipsum}% only for dummy text
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{etoolbox}

\colorlet{feline}{darkgray}% change the color of chapter numbers here

\makeatletter \newsavebox{\feline@chapter} \newcommand\feline@chapter@marker[1][4cm]{% \sbox\feline@chapter{% \resizebox{!}{#1}{\setlength{\fboxsep}{0pt}% \colorbox{white}{\color{feline}\usefont{U}{eur}{m}{n}\thechapter}}}% change the font of chapter numbers here \raisebox{\depth}{\usebox{\feline@chapter}}% } \renewcommand*{\chapterformat}{% \sbox\feline@chapter{\feline@chapter@marker[1.61cm]}% adjust the height of chapter numbers here \makebox[0pt][l]{% \makebox[\textwidth][r]{% \usebox\feline@chapter}}% } \renewcommand\chapterlinesformat[3]{% \Ifstr{#1}{chapter} {#2\parbox[b]{\dimexpr\textwidth-\wd\feline@chapter-1em\relax}{\raggedchapter #3}} {@hangfrom{#2}{#3}}% } \makeatother

\preto\chapterheadendvskip{% \vspace*{-\parskip}% {\noindent\setlength\parfillskip{0pt plus 1fil}\rule{\textwidth}{.4pt}\par}% }

\begin{document} \tableofcontents \chapter{Ten} \lipsum \chapter{Lorem ipsum dolor sit amet, consectetuer adipiscing elit} \lipsum \end{document}

enter image description here

enter image description here

It works even if you set an option like parskip=half or parskip=full.


Update regarding a comment below

If you want to color the line below the chapter title, define a color and use it for the rule:

...
\colorlet{felinerule}{red}
...
... \textcolor{felinerule}{\rule{\textwidth}{.4pt}} ...
...

And if only numbered chapters should use the changed layout:

\documentclass
  %[parskip=half]
  {scrreprt}
\usepackage{lipsum}% only for dummy text
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{etoolbox}

\colorlet{feline}{darkgray}% change the color of chapter numbers here \colorlet{felinerule}{red}

\makeatletter \newsavebox{\feline@chapter} \newcommand\feline@chapter@marker[1][4cm]{% \sbox\feline@chapter{% \resizebox{!}{#1}{\setlength{\fboxsep}{0pt}% \colorbox{white}{\color{feline}\usefont{U}{eur}{m}{n}\thechapter}}}% change the font of chapter numbers here \raisebox{\depth}{\usebox{\feline@chapter}}% } \renewcommand*{\chapterformat}{% \sbox\feline@chapter{\feline@chapter@marker[1.61cm]}% adjust the height of chapter numbers here \makebox[0pt][l]{% \makebox[\textwidth][r]{% \usebox\feline@chapter}}% } \newif\ifchapterrule \renewcommand\chapterlinesformat[3]{% \global\chapterrulefalse \Ifstr{#1}{chapter} {\IfArgIsEmpty{#2} {@hangfrom{#2}{#3}}% unnumbered chapters: original definition {#2\parbox[b]{\dimexpr\textwidth-\wd\feline@chapter-1em\relax}{\raggedchapter #3}% \IfArgIsEmpty{#2}{}{\global\chapterruletrue}% }% } {@hangfrom{#2}{#3}}% other sectioning levels with style=chapter: original definition } \makeatother

\preto\chapterheadendvskip{% \ifchapterrule \vspace*{-\parskip}% {\noindent\setlength\parfillskip{0pt plus 1fil}\textcolor{felinerule}{\rule{\textwidth}{.4pt}}\par}% \fi }

\begin{document} \tableofcontents \chapter{Ten} \lipsum \chapter{Lorem ipsum dolor sit amet, consectetuer adipiscing elit} \lipsum \end{document}

enter image description here

esdd
  • 85,675
  • 1
    +1 but I'd just use \usefont{U}{eur}{m}{n}\thechapter instead of $\eurom\thechapter$. I'd rather not allocate a math alphabet just for a chapter number (disclaimer: sometimes I need lots of them, but indeed for most normal humans that's not really an issue :-)). – campa Jan 22 '21 at 09:34
  • @campa Thanks for the hint. I have changed it. – esdd Jan 22 '21 at 09:39
  • @esdd thanks a lot, this is great! especially your comments are very useful. Is there any way to change the color of the line? And is it possible to only apply this style to chapters with content, I would like the table of contents, list of figures and table directory to remain the way they used to look like. – janimango Jan 23 '21 at 13:41
  • @janimango See my updated answer. – esdd Jan 25 '21 at 14:45
1

Improved answer

\documentclass[chapterprefix=off]{scrreprt}

\usepackage{lipsum} \usepackage{anyfontsize} \newcommand{\HUGE}{\fontsize{40}{44pt}\selectfont}

\renewcommand{\chapterlinesformat}[3] {\mbox{#3}\hfill\HUGE{\mbox{\thechapter}}\[10pt] \hrulefill }

\begin{document} \chapter{First}

\lipsum

\end{document}

enter image description here

Below is the original answer that did not address the question. I just leave it in for reference.

You can setup the plain pagestyle to generate this header on the first page of each chapter:

\documentclass{scrreprt}

\usepackage{lipsum} \usepackage{fancyhdr}

\pagestyle{fancy} \fancypagestyle{plain}{% \fancyhead[L]{\LARGE\textbf{\leftmark}} \fancyhead[R]{\Huge\textbf{\arabic{chapter}}} } \setlength{\headheight}{30pt} \renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\begin{document} \chapter{First}

\lipsum

\end{document}

Please note that the \headheight has to be increased to avoid nasty LaTeX warnings, and that this causes the header also to be bigger on all other pages.

  • Thank you! But thats actually not exactly what I wanted. I'm currently using fancyhdr to show the chaptername on left (odd) pages and section on right (even) pages. But on a new page with a new chapter there is no heading and I would like to keep it that way. I just want to change the chapter style (without titlesec). I want the chapter to look wht you achieved with fancyhdr, but not inside the header. – janimango Jan 21 '21 at 14:09