4

The following MWE shows that the second section is black instead of red. Even if this happens only if there is no text between these two sections: Is this a bug?

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{scrlayer-scrpage}

\addtokomafont{section}{\color{red}}
\addtokomafont{pageheadfoot}{\color{blue}}

\begin{document}
...
\\[0.84\textheight]
\section{Test}
\section{Test}
\end{document}

enter image description here

Stefan Braun
  • 1,244
  • Just found out that the page break between sections will never happen if I use \textcolor instead of \color. Looks like \textcolor is more stable: http://tex.stackexchange.com/questions/86039/what-is-the-difference-between-textcolor-and-color – Stefan Braun Jun 11 '16 at 13:55
  • \RedeclareSectionCommand[font=\large\bfseries\sffamily\color{red}]{section} – Johannes_B Jun 11 '16 at 14:00
  • @Johannes_B Do you want to say that \addtokomafont should not be used for the text color? – Stefan Braun Jun 11 '16 at 14:03
  • 1
    I am saying that the above abviously works but has some downsides. You should report the behaviour to komascript.de – Johannes_B Jun 11 '16 at 14:05
  • I would consider that a duplicate. – Johannes_B Jun 11 '16 at 14:18
  • @Johannes_B \RedeclareSectionCommand[font=\large\color{red}]{section} does the same as \setkomafont{section}{ \large\color{red}}. Note that the default size for section in scrartcl is \Large and not \large. – esdd Jun 12 '16 at 18:54
  • 1
    @StefanBraun \color{red} is allowed in \addtokomafont, \setkomafont and as value for the font option in \RedeclareSectionCommand. AFAIK the problem will be solved in the next KOMA-Script version (3.21). – esdd Jun 12 '16 at 18:59
  • @esdd But with \Redeclare... i didn't get the odd behaviour (2016/05/10 v.3.20). – Johannes_B Jun 12 '16 at 19:15
  • 1
    @Johannes_B In your suggestion \large is used. Change it to \Large (default for sections in scrartcl) and you get the page break and the black color. – esdd Jun 12 '16 at 20:05
  • @esdd Ok, now i now what is going on. Thanks. – Johannes_B Jun 12 '16 at 20:09
  • @StefanBraun You can use/test the prerelease of version 3.21 from http://www.komascript.de/node/1801 – esdd Jun 14 '16 at 06:58

2 Answers2

4

You should use \leavevmode before the color command. This will avoid that a page break can occur between the color and the title of the section.

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{scrlayer-scrpage}

\addtokomafont{section}{\leavevmode\color{red}}
\addtokomafont{pageheadfoot}{\color{blue}}

\begin{document}
...
\\[0.84\textheight]
\section{Test}
\section{Test}
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
2

The bug is fixed in KOMA-Script Version 3.21 which is the current version on CTAN, in TeX Live 2016 and in MiKTeX.

\documentclass{scrartcl}[2016/06/14]
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{scrlayer-scrpage}

\addtokomafont{section}{\color{red}}
\addtokomafont{pageheadfoot}{\color{blue}}

\begin{document}
...
\\[0.84\textheight]
\section{Test}
\section{Test}
\KOMAScriptVersion
\end{document}

results in

enter image description here

esdd
  • 85,675