0

I am editing a package (which I did not write myself) where the titlesec package was used in combination with the scrbook document class. This produces an error, as explained in this post: Conflict between titlesec package and scrbook class after most recent update of TeXLive2019. I wish to fix this error, and get rid of the error message. I realize one must use the commands in the KOMA-class, but I don't know exactly how. Here is a minimal exaple:

Package:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage} 
\RequirePackage[T1]{fontenc}
\RequirePackage[explicit]{titlesec}
\titleformat{\section}
  {\normalfont}{\thesection}{0pt}{\phantomsection\fontsize{18pt}{20pt} \sffamily\center\MakeUppercase{#1}}
\titleformat{\subsection}
  {\normalfont}{\thesubsection}{0pt}{\fontsize{14pt}{16pt} \sffamily\center\MakeUppercase{#1}}
\titleformat{\subsubsection}
  {\normalfont}{\thesubsubsection}{0pt}{\scshape{\textbf{\normalsize #1}}}
% {left}{top}{below}{right}
\titlespacing*{\section}{0pt}{0pt minus 0.5em}{0pt}
\titlespacing*{\subsection}{0pt}{-2em plus 0.3em minus 0.3em}{-0.4em plus 0.2em minus 0.2em}
\titlespacing*{\subsubsection}{0pt}{-0.5em plus 0.2em}{-0.8em plus 0.5em minus 0em} 
\setcounter{secnumdepth}{0} 

The document:

\documentclass[fontsize=13pt,a4paper,openany,parskip=half,DIV=calc]{scrbook}
\usepackage{mypackage}
\begin{document}
\section{Section}
    Some text.
\subsection{Subsection}
    More text.
\subsubsection{Subsubsection}
    Text.
\end{document}

So the challenge is redefining the commands section, subsection and subsubsection as intended by the author of this class without using the titlesec package.

0

3 Answers 3

2

I see no way to apply \MakeUppercase to section titles with komascript methods. But it can be done.

\RequirePackage{fix-cm}
\documentclass[fontsize=13pt,a4paper,openany,parskip=half,DIV=calc]{scrbook}

\usepackage{lipsum} % for nonsense text

\RedeclareSectionCommand[
  style=section,
  level=1,
  runin=false,
  font=\fontsize{18}{20}\sffamily\centering,
  beforeskip=10pt,
  afterskip=5pt,
]{section}
\RedeclareSectionCommand[
  style=section,
  level=2,
  runin=false,
  font=\fontsize{14}{16}\sffamily\centering,
  beforeskip=6pt,
  afterskip=3pt,
]{subsection}
\RedeclareSectionCommand[
  style=section,
  level=3,
  runin=false,
  font=\normalfont\normalsize\scshape,
  beforeskip=6pt,
  afterskip=3pt,
]{subsubsection}
\setcounter{secnumdepth}{0}

\NewCommandCopy{\scrsection}{\section}
\NewCommandCopy{\scrsubsection}{\subsection}

\NewDocumentCommand{\uppercasesection}{msom}{%
  \IfBooleanTF{#2}{%
    #1*{\MakeUppercase{#4}}
  }{%
    \IfNoValueTF{#3}{%
      #1{\MakeUppercase{#4}}%
    }{%
      #1[#3]{\MakeUppercase{#4}}%
    }%
  }%
}
\RenewDocumentCommand{\section}{}{\uppercasesection\scrsection}
\RenewDocumentCommand{\subsection}{}{\uppercasesection\scrsubsection}

\begin{document}

\lipsum[1][1-3]

\section{Section}

\lipsum[1][1-3]

\subsection{Subsection}

\lipsum[1][1-3]

\subsubsection{Subsubsection}

\lipsum[1][1-3]

\end{document}

Adjust the spacing and font parameters to your taste.

enter image description here

9
  • This solution produced 14 errors, maybe because it is a package and the package does not provide \RedeclareSectionCommand ?
    – Vebjorn
    Commented Apr 22, 2022 at 16:39
  • 1
    @Vebjorn My guess is that you have an older version of LaTeX. Try adding \usepackage{xparse}.
    – egreg
    Commented Apr 22, 2022 at 16:42
  • I don't think I use an older version. I use Overleaf
    – Vebjorn
    Commented Apr 22, 2022 at 16:43
  • 1
    @Vebjorn I get no error.
    – egreg
    Commented Apr 22, 2022 at 16:47
  • 1
    @Vebjorn I guess you have an outdated version of the KoMa-script bundle, then.
    – egreg
    Commented Apr 24, 2022 at 20:32
1

Here is another suggestion redefining \sectionlinesformat to apply \MakeUppercase:

\begin{filecontents}[overwrite]{mypackage.sty}
\ProvidesPackage{mypackage}
\@ifundefined{KOMAClassName}
  {% no KOMA-Script class is used
    \RequirePackage[explicit]{titlesec}
    \titleformat{\section}
      {\normalfont}{\thesection}{0pt}{\fontsize{18pt}{20pt} \sffamily\centering\MakeUppercase{#1}}
    \titleformat{\subsection}
      {\normalfont}{\thesubsection}{0pt}{\fontsize{14pt}{16pt} \sffamily\centering\MakeUppercase{#1}}
    \titleformat{\subsubsection}
      {\normalfont}{\thesubsubsection}{0pt}{\scshape{\normalsize #1}}
    %{indent}{before}{after}
    \titlespacing*{\section}{0pt}{10pt}{5pt}
    \titlespacing*{\subsection}{0pt}{6pt}{3pt}
    \titlespacing*{\subsubsection}{0pt}{6pt}{3pt}
  }
  {% a KOMA-Script class is used
    \RedeclareSectionCommand[
      runin=false,
      font=\fontsize{18}{20}\mdseries,
      beforeskip=10pt,
      afterskip=5pt,
    ]{section}
    \RedeclareSectionCommand[
      runin=false,
      font=\fontsize{14}{16}\mdseries,
      beforeskip=6pt,
      afterskip=3pt,
    ]{subsection}
    \RedeclareSectionCommand[
      runin=false,
      font=\normalfont\normalsize\scshape,
      beforeskip=6pt,
      afterskip=3pt,
    ]{subsubsection}
    \renewcommand*{\sectionlinesformat}[4]{%
      \Ifstr{#1}{section}
        {\centering\MakeUppercase{#3#4}}
        {%
          \Ifstr{#1}{subsection}
            {\centering\MakeUppercase{#3#4}}
            {\@hangfrom{\hskip #2#3}{#4}}% original definition for other section levels
        }%
      }%
  }
\setcounter{secnumdepth}{0}
\end{filecontents}


\RequirePackage{fix-cm}
\documentclass[fontsize=13pt,a4paper,openany,parskip=half,DIV=calc]{scrbook}
\usepackage{mypackage}

\usepackage{lipsum} % for nonsense text

\begin{document}
\lipsum[1][1-3]
\section{Section}
\lipsum[1][1-3]
\subsection{Subsection}
\lipsum[1][1-3]
\subsubsection{Subsubsection}
\lipsum[1][1-3]
\end{document}

I have changed the spacings before and after the headings (like in the answer of @egreg), because the spacings in the question are curious.

enter image description here

0

I tried something like this:

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
             {-3.5ex \@plus -1ex \@minus -.2ex}%
             {2.3ex \@plus.2ex}%
             {\center\phantomsection\fontsize{18pt}{20pt} \sffamily\MakeUppercase}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
             {-3.25ex\@plus -1ex \@minus -.2ex}%
             {1.5ex \@plus .2ex}%
             {\fontsize{14pt}{16pt} \sffamily\center\MakeUppercase}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
             {-3.25ex\@plus -1ex \@minus -.2ex}%
             {1.5ex \@plus .2ex}%
             {\scshape\normalsize\bfseries}}
\makeatother
                                  

which seems to have worked. Now I just need tips on how to (correctly) include the spacings from the \titlespacing commands.

2
  • I just tried using 0.7ex on the afterskip, which seemes to have produced something similar.
    – Vebjorn
    Commented Apr 22, 2022 at 15:30
  • Using a KOMA-Script class do not redefine \section etc. using \@startsection. With an uptodate KOMA-Script version you will get warnings and several features of KOMA-Script will be deactivated.
    – esdd
    Commented Apr 25, 2022 at 11:30

You must log in to answer this question.

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