1

Currently I'm using

\newcommand{\newchapter}[1]{\rule{\linewidth}{0.25pt} \vspace*{-0.30cm} \\ \textbf{\textcolor{red}{\Large #1}} \vspace*{-0.15cm}\\\rule{\linewidth}{0.25pt}\par}

to make section like headers. But it feels wrong doing so while latex has the concept of real sections (and by using restyled sections the content is just much more portable (copy paste it to another document)).

See here a MWE:

\documentclass{scrartcl}

\usepackage{fontspec} % LuaLaTeX
\usepackage{multicol} % use \begin{multicols}{num} text \end{multicols} and the text will be automatically distributed
\usepackage{scrlayer-scrpage}                 % header and footer
\usepackage{xcolor}

% ----- Settings -----
\KOMAoptions{
    paper=a4,           % set papersize
    paper=landscape,    % set paperformat
    fontsize=6.6pt,       % set fontsize
    parskip=half,       % half a line will seperate paragraphs
    headings=normal,    % headings in normalsize
    twoside=false,      % onesided document
    twocolumn=false,    % one columned pages
    numbers=autoendperiod, % automatic punctuation in outline
}

% turn off header and footer
\pagestyle{empty}

\areaset{835pt}{585pt}

% indentation
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0.5ex}

% big red titles for chapters
\newcommand{\newchapter}[1]{\rule{\linewidth}{0.25pt} \vspace*{-0.30cm} \\ \textbf{\textcolor{red}{\Large #1}} \vspace*{-0.15cm}\\\rule{\linewidth}{0.25pt}\par}

% blue titles for single topics within a chapter
\newcommand{\topic}[1]{\textbf{\textcolor{blue}{#1}}}

% green and bold text for important concepts
\newcommand{\term}[2][]{%
    \if n#1\else\hangindent=1em\hangafter=1\fi%
    \textbf{\textcolor{green!50!black}{#2}}%
}

\renewcommand{\baselinestretch}{1.3}
\setlength{\columnseprule}{.01pt}

\begin{document}
\begin{multicols}{3}
\newchapter{NewChapter}
\topic{Topic}
\term{Term}

\newpage
force pagebreak

\end{multicols}
\end{document}

and the page output: pdf output

(don't wonder about the maybe weird fontsize/papersize, it is supposed to be this way to fit as much as possible on the page)

So I'd like to use section instead of newchapter, subsection instead of topic and paragraph instead of term.

Is there a way to do this (and if yes how)? Note the missing linebreaks after topic and term (but I'd be ok if these linebreaks couldn't be prevented)

Sorry if this is a pretty obvious question, but I already looked into \RedeclareSectionCommand and \setkomafont (would work for the colors, but I'm not sure about the hangindent (term) and the \rule (newchapter) especially the \rule after the chapter text).

Note: I'm compiling with lualatex, but this shouldn't have a relevant effect.

Note for Bounty: newChapter and topic are solved (see esdds answer), but I'm still struggling with the hangindent for \term. I know I can do \newcommand{\term}[1]{\paragraph{#1}\hangindent=1em\hangafter=1} but still I'd like to use \paragraph in the document-body so that its easy to change the formatting.

1
  • Decided to go without indentation (boldface and color are highlighting enough to find the terms/topics fast enough
    – atticus
    Feb 27, 2022 at 11:14

1 Answer 1

3
+50

Here is a suggestion for the section and subsection headings:

\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage{multicol}
%\usepackage{scrlayer-scrpage}% <- not used in the example
\usepackage{xcolor}
\usepackage{blindtext}% only for dummy text

% ----- Settings -----
\KOMAoptions{
    %paper=a4,% default
    paper=landscape,
    fontsize=6.6pt,
    %parskip=half,% <- overwritten by \setparsizes
    headings=normal,
    %twoside=false,% default with scrartcl
    %twocolumn=false,% default
    %numbers=autoendperiod,% default
}

\pagestyle{empty}
\areaset{835pt}{585pt}
\setparsizes{0pt}{0pt}{1em plus 1fil}% indentation

\setcounter{secnumdepth}{\partnumdepth}% unnumbered sections etc.

% big red titles for sections
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0pt,
  afterindent=false,
  runin=false,
  font=\rmfamily\color{red}\Large
]{section}

\newcommand*{\originalsectionlinesformat}{}
\let\originalsectionlinesformat\sectionlinesformat
\renewcommand*{\sectionlinesformat}[4]{%
  \Ifstr{#1}{section}
    {\setlength\parfillskip{0pt}\textcolor{black}{\rule{\linewidth}{0.25pt}}\nopagebreak\par\vskip-.1cm#4\nopagebreak\par\vskip-.3cm  \textcolor{black}{\rule{\linewidth}{0.25pt}}}
    {\originalsectionlinesformat{#1}{#2}{#3}{#4}}%
}

% blue titles for subsections:
\RedeclareSectionCommand[
  runin=true,
  beforeskip=0pt,
  afterskip=1ex,
  font=\rmfamily\color{blue}
]{subsection}

% green and bold text for important concepts:
\newcommand{\term}[2][]{%
    \if n#1\else\hangindent=1em\hangafter=1\fi%
    \textbf{\textcolor{green!50!black}{#2}}%
}

\renewcommand{\baselinestretch}{1.3}
\setlength{\columnseprule}{.01pt}

\begin{document}
\begin{multicols}{3}
\section{NewSection}
\subsection{Topic}
\term{Term}

\newpage
force pagebreak
\end{multicols}
\end{document}

enter image description here

6
  • \sectionlinesformat, I forgot it existed, this is helpful. I've been using an evil hack for colored section lines in some special reports. Thank you!
    – Keks Dose
    Feb 17, 2022 at 17:30
  • Thanks didn't knew of \sectionlinesformat. Any ideas how to set the hangindent (for the content) for the \term command? Just being curious, does it matter to define \originalsectionlinesformat as a latex command before \let? And is there a difference between setting the font via the font key in RedeclareSectionCommand and setting the font via setkomafont?
    – atticus
    Feb 18, 2022 at 11:03
  • In addition I see it works, but I don't quite understand how it works (the line where the rules etc are created). So as far as I read it, it's: make a rule, then enter vertical mode and insert .1cm space (to avoid a pagebreak here \nopagebreak), insert the section title (why are the \par needed here? as far as I understand we already are in vertical mode), then enter vertical mode, insert -.3cm space (again avoid pagebreak) and the second rule. So basically the two things confusing me are the \par and why set the parfillskiplength? (sorry for so many questions but I'm curious)
    – atticus
    Feb 18, 2022 at 12:38
  • 1
    I have no idea for the \term. Additinally I am not sure, if this is (or should be) a heading, because you use it inline. I use \newcommand*{\originalsectionlinesformat}{} to ensure that \originalsectionlinesformat was undefined. If you want, you can remove the \par after #4, because we should be there already in vertical mode.
    – esdd
    Feb 20, 2022 at 11:46
  • 1
    Your parskip=half and my \setparsizes{0pt}{0pt}{1em plus 1fil} (do not change \parindent and/or \parskip manually!) set \parfillskip to 1em plus 1fil). Therefore 1em` free horizontal space at the end of each paragraph is required. To avoid warnings regarding overfull hboxes, I change \parfillskip in \sectionlinesformat.
    – esdd
    Feb 20, 2022 at 11:53

You must log in to answer this question.

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