# How to uppercase heavily customised sections (sectsty+fontspec)?

I am trying to customise the aspect of a scrbook to look like a book I have.

In my case, sections should be formatted as follows: the font face should be Conques Demi, the font size 26 pt, the font colour a particular shade of dark red (CMYK: 0% 87% 87% 50%) with a 1 pt thick line rule of the same colour that is large the width of a column, the label should be in upper case and aligned to right.

Since I have not managed to realise how to draw coloured line rules with KOMA scripts, I tried to abstain that results with other packages. If you know how to get the exact result that I described above, please feel free to show me how in KOMA! Thanks in advance!

Anyway I managed to mimic the font face, size and colour, the rule and the alignment, but I started to experience problems when I tried to make the label uppercase. Note that the problem persists even if I remove any reference to the fontspec package and all its commands. Consider the following minimal working example:

\documentclass[twocolumn]{scrbook}

\usepackage{xcolor}
\usepackage{sectsty}
\usepackage{fontspec}

\setcounter{secnumdepth}{0}
\definecolor{darkred}{cmyk}{0.0,0.87,0.87,0.50}
\newfontfamily\myfont[]{Conques}
\sectionfont{\raggedleft\myfont\Huge\color{darkred}\sectionrule{0pt}{0pt}{-2pt}{1pt}} %

\begin{document}
\mainmatter
\section{A Section} % (fold)
\label{sec:a_section}
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
% section a_section (end)
\end{document}


As other answers (to simpler cases) suggest, in order to uppercase the section's label, I am expected to add \uppercase to the end of the \sectionfont{...} command. If I do so, however, I am warned that a { is missing and that \begin{document} is closed by \end{DOCUMENT}. If I open the resulting .pdf, all the document is uppercase except for an additional A Section the appear just below the first occurrence and the rule is gone.

This is due to the fact, I think, that \uppercase is a parametric command while here it is used as an "absolute" statement. In my opinion, in fact, the second occurrence of A Section is due to \uppercase messing with the definition of the section's headings for the table of content, which in turn becomes empty.

According to my researches, there is no such "absolute" \uppercase equivalent. Some answers suggest to use \MakeUppercase instead as in some cases it is more "respectful" of the surrounding environment. If I do so, however, I get the following result: the string [0pt][r] at the beginning of an empty line with a rule that is finishing out of the vertical column border; the proper section's label appears below, not uppercased, with no rule, but correctly moved to the right. Even if this might suggest to reorder the commands within \sectionfont{...}, no permutation actually works. I have even tried with the textcase package and its \MakeTextUppercase command as well, with no luck at all.

Can someone please tell me where I am wrong and how to fix the issue?

-
– Claudio Fiandrino Jan 18 '13 at 14:15
As far as I know, sectsty doesn't allow to put at the end a command with argument; it's titlesec that has this feature. However, also the KoMa-Script classes should have some facility for this job, without the need of external packages. – egreg Jan 18 '13 at 14:23
It's a pity we're not allowed to use KOMA's own setup commands. It'd be rather easy, then. – clemens Jan 18 '13 at 14:25
My main concern in regards of KOMA commands is that I have found no evidence that they allow to define line rules like \sectionrule{0pt}{0pt}{-2pt}{1pt}. Do you know if they indeed do allow that? I'm editing my question to include this possibility. – Stefano Bragaglia Jan 18 '13 at 14:53

If KOMA's \setkomafont{section}{<decl>} can be used then the task is rather easy since the last command in there may have an argument. KOMA doesn't have a \sectionrule but one can define something similar using LaTeX's \rule[<raise>]{<width>}{<thickness>} command.

So maybe something like the following:

\documentclass[twocolumn]{scrbook}

% choose the font:
\usepackage{fontspec}
% I don't have Conques' installed, so I use another font
% I also added a LetterSpace' greater than zero as all-caps
% words _always_ should be spaced out a little
\newfontfamily\sectionfont[LetterSpace=2]{Linux Libertine O}

% define the color:
\usepackage{xcolor}
\definecolor{darkred}{cmyk}{0.0,0.87,0.87,0.50}
\colorlet{section}{darkred}

% the section layout:
\newcommand\sectionrule{%
\makebox[0pt][l]{\rule[-.25ex]{\linewidth}{1pt}}}
\newcommand\sectionformat[1]{%
\sectionfont\Huge\color{section}%
\sectionrule
\hfill\MakeUppercase{#1}}
\setkomafont{section}{\sectionformat}
\setcounter{secnumdepth}{0}

\begin{document}
\mainmatter
\section{A Section}\label{sec:a_section}

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

\end{document}


-
\makebox[0pt][l]{\rule...} would be better than skipping back by \linewidth. However this would not work for multiline section titles. – egreg Jan 18 '13 at 16:25
@egreg indeed, thanks! – clemens Jan 18 '13 at 16:26
You might instead define a new command such as \newcommand\printsectiontitle[1]{\MakeUppercase{#1}\makebox[0pt][r]{\rule...}} and use \printsectiontitle as the last command in \setkomafont{section} – egreg Jan 18 '13 at 16:31
@egreg Yes, that would be better and if it was my document I'd probably define some \sectionformat{<arg>} command and used it as only argument to \setkomafont. I consider that fine-tuning which I haven't done in my answer. Maybe I should, though... – clemens Jan 18 '13 at 16:38
Dear cgnieder and egreg, thanks for both the solution and insightful suggestions to my problem! Now it works... and also reasonably well! I'm doing more experiments but I consider the problem solved. The above short discussion about best practices is very interesting as well, thanks for sharing! Regards. – Stefano Bragaglia Jan 18 '13 at 16:51