1

I have changed the section defination to get section title inside a colorbox. Now, I can't use titlesec to change varticle spacing around the section header, specially on top of it. Also, I want to change the section title font to Roboto.

This is my mwe:

\documentclass[a4paper]{scrartcl}
\usepackage{blindtext,xcolor}
% Colorbox for section title
\colorlet{sectioncolor}{orange}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \colorbox{sectioncolor}{%
    \parbox[t]{\dimexpr\linewidth-2\fboxsep\relax}{%
      \raggedsection\color{white}\@hangfrom{#3}{#4}%
}}}
\makeatother
%%%%%%%%%%%
\usepackage[sfdefault,light]{roboto}   ! Want Roboto for Section Title only
\begin{document}
\section*{Bar}
\blindtext
\section*{Foo}

\end{document}

How I can get that? I use lualatex for compiling.

1

The vertical space before and after section header can be changed by

\RedeclareSectionCommand[
  beforeskip=1.5em,% <- before section header
  afterindent=false,
  afterskip=1em,% <- after section header
  runin=false
]{section}

If only the section titles should use Roboto:

\usepackage{fontspec}
\newfontfamily\Roboto{Roboto}
\addtokomafont{section}{\Roboto}% Roboto only for section titles

Example:

\documentclass{scrartcl}% a4paper is default
\usepackage{blindtext}% only for dummy text
\usepackage{xcolor}
% Colorbox for section title
\colorlet{sectioncolor}{orange}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \colorbox{sectioncolor}{%
    \parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
      \raggedsection\color{white}\@hangfrom{#3}{#4}%
}}}
\makeatother

\usepackage{fontspec}
\newfontfamily\Roboto{Roboto}
\addtokomafont{section}{\Roboto}% Roboto only for section titles

\RedeclareSectionCommand[
  beforeskip=1.5em,% <- before section header
  afterindent=false,
  afterskip=1em,% <- after section header
  runin=false
]{section}

\begin{document}
\section*{Bar}
\blindtext
\section*{Foo}
\Blindtext[2]
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.