1

I am using Koma-script for chapter formatting as it is shown on figure below and in MNWE.

I found out that there is an interesting library currfile that can retrieve the name of the file from which the source text is compiled. I'm trying to implement to put the file name with small font in left upper corner in a gray square. My code is very clunky.

I also try to different approach to put the file name into the heading with following code:

\pagestyle{scrheadings}  
\chead{\currfilename}

but in case, that chapter name is too long the text is overlapped.

Chapter formatting with \currfilename

MNWE:

\documentclass[chapterprefix=on]{scrbook}

\usepackage{blindtext}
\usepackage{graphicx}                  % command \scalebox{}{}
\usepackage{xcolor} 
\usepackage[headsepline]{scrlayer-scrpage}


\addtokomafont{chapterprefix}{\currfilename\color{red}\raggedleft}
\setkomafont{chapter}{\color{black}\fontsize{18}{22}\selectfont}

% how to insert the actual or current filename: 
% https://stackoverflow.com/questions/5549803/
\usepackage{currfile}

\renewcommand*{\chapterformat}{%
  \mbox{\chapappifchapterprefix{\nobreakspace}%
  \scalebox{2}{\thechapter\autodot}\enskip}
}

\makeatletter
  \renewcommand{\chapterlineswithprefixformat}[3]{%
    \colorbox{gray}{%
      \parbox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{%
        \raggedchapter
        #2#3%
      }%
    }%
  }
\makeatother


\pagestyle{scrheadings}  
\chead{\currfilename}

\begin{document}
  \blinddocument
\end{document}

1 Answer 1

2

Use only font commands in the second argument of \addtokomafont and \setkomafont.

\documentclass[chapterprefix=on]{scrbook}
\usepackage{lmodern}% <- scalable font
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[headsepline]{scrlayer-scrpage}% -> sets page style scrheadings automatically

\addtokomafont{chapterprefix}{\color{red}}% <- changed: use only font commands!
\setkomafont{chapter}{\color{black}\fontsize{18}{22}\selectfont}

% how to insert the actual or current filename: \currfilename
% https://stackoverflow.com/questions/5549803/
\usepackage{currfile}

\renewcommand*{\chapterformat}{%
  \mbox{\chapappifchapterprefix{\nobreakspace}%
  \scalebox{2}{\thechapter\autodot}\enskip}
}

\makeatletter
  \renewcommand{\chapterlineswithprefixformat}[3]{%
    \colorbox{gray}{%
      \parbox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{%
        \raggedchapter
        \smash{\small\raisebox{-\ht\strutbox}{\currfilename}}\\% <- added
        {\raggedleft#2}#3% <- changed
      }%
    }%
  }
\makeatother

\chead{\currfilename}

\begin{document}
  \blinddocument
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .