I would like to have text in two colored boxes next to each other. I found \tcbox
, but it automatically adds a linebreak.
Please note: I can use anything that works with pdflatex
. No need for \tcbox
, it was only the closest thing to what I'm looking for.
Minimal Example
\documentclass[a4paper]{scrartcl}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{sectsty}
\usepackage{tcolorbox}
\definecolor{darkblue}{HTML}{00008A}
\definecolor{lightblue}{HTML}{C8C8FA}
\sectionfont{\color{darkblue}}
\subsectionfont{\color{darkblue}}
\tcbset{colback=darkblue,arc=0mm,auto outer arc,boxrule=0mm,width=1.5cm, height=1cm,center title,box align=base}
\pagestyle{fancy}
\fancyhf{}
\rhead{\textcolor{darkblue}{2017}}
\lhead{\tcbox{\textcolor{white}1 \textcolor{white}\textbar}\tcbox[colback=lightblue]{Chapter Name}}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\section{And so it begins}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
\end{document}
Best Answer
You're missing the
on line
option, but also to set a strut in the two boxes, so the text baselines will be aligned too.I'd use
\newtcbox
rather than a global\tcbset
. Don't forget to set the\headheight
(fancyhdr
suggests 28.45274pt, I rounded to 30pt).Beware that KOMA classes claim that using
fancyhdr
with them is not recommended; you should consult the guide in order to usescrlayer-scrpage
for the job.