2

I am looking to make a tight black box around my chapter titles, ideally only 1pt of margin on each side. So far, my best results have been with soul:

using "soul" package

However, you'll notice that there is too much margin at the bottom. Also, the highlight gets repeated at the top of each odd page:

using "soul" package

What is the clever way to do this stuff? I don't mind using something else than soul, it just seemed like a good solution.

MWE below. Please note that you'll need the Mikodacs font (or perhaps any TTF font?) in FONTLOCATION.

\documentclass[book,dvipsnames]{memoir}

\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{anyfontsize}
\usepackage{soul}
\sethlcolor{black}

%% Change height of highlight
\makeatletter
 \def\SOUL@hlpreamble{%
 \setul{}{2ex}%
 \let\SOUL@stcolor\SOUL@hlcolor
 \SOUL@stpreamble
 }
\makeatother

\newfontfamily{\archivo}[Path=/FONTLOCATION]{Mikodacs.ttf}

\usepackage{lipsum} %% For dummy text

%% Chapterstyle
\makechapterstyle{lucknerto}{%
\setlength{\beforechapskip}{-2\onelineskip}%
\setlength{\afterchapskip}{2\onelineskip}%
\renewcommand*{\printchaptername}{}%
\renewcommand*{\chapternamenum}{}%
\renewcommand*{\chapnumfont}{\normalfont\large\sffamily\bfseries}%
\renewcommand*{\afterchapternum}{}%
\renewcommand{\printchaptertitle}{\centering\archivo\color{White}\fontsize{23}{27.6}\selectfont\MakeUppercase}
}
\chapterstyle{lucknerto} %% enable

%% Pagestyle 
\makepagestyle{luckner}%
\makeevenhead{luckner}{}{\small{{\MakeUppercase{book title}}}}{} 
\makeoddhead{luckner}{}{\small{{\MakeUppercase{\leftmark}}}}{}
\makeevenfoot{luckner}{\large{\thepage}}{}{}
\makeoddfoot{luckner}{}{}{\large{\thepage}}
\pagestyle{luckner} %% enable

\begin{document}
\chapter{\hl{Foobar}}
\lipsum[1-20]
\end{document}
8
  • 1
    tcolorbox can provide nice (and tight) boxes
    – user31729
    Commented Apr 16, 2017 at 23:04
  • @ChristianHupfer, how would you implement it? I tried \begin{tcolorbox}[colframe=black] \chapter{Foobar} \end{tcolorbox} ... but that ruins the pagestyle. Commented Apr 16, 2017 at 23:10
  • I'll try but your document is not compilable, due to the XeLaTeX stuff ;-) I just don't have the font and must replace it :-(
    – user31729
    Commented Apr 16, 2017 at 23:15
  • It is compilable? I just tested it ... Commented Apr 16, 2017 at 23:16
  • No, it isn't. I don't have your Mikodacs font
    – user31729
    Commented Apr 16, 2017 at 23:17

1 Answer 1

3

The style is pretty easy with tcolorbox and a special \tcbox command for this, which is can be modified to the personal preferences.

The 'difficulty' is to understand what memoir does with the chapter title. I had to change \printchaptertitle to have an argument (which is the usual case), other than to work with moving arguments.

\documentclass[book,dvipsnames]{memoir}

\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{anyfontsize}
\usepackage{soul}
\usepackage{tcolorbox}
\sethlcolor{black}

%% Change height of highlight
\makeatletter
 \def\SOUL@hlpreamble{%
 \setul{}{2ex}%
 \let\SOUL@stcolor\SOUL@hlcolor
 \SOUL@stpreamble
 }
\makeatother

\newfontfamily{\archivo}[Path=/FONTLOCATION]{Micodacs.ttf}

%\newfontfamily{\archivo}{Liberation Sans}

\usepackage{lipsum} %% For dummy text

\tcbset{chapterhead/.style={%
    fontupper=\archivo\fontsize{23}{27.6}\selectfont,
    left skip=1ex, % for example
    nobeforeafter, %no spacing before and after the box etc
    halign=center, % horizontal align within box, can be omitted
    valign=center, % vertical align within box, can be omitted
    colback=black, % black background colour
    size=tight, % tight box
    colupper=white, % white foreground colour
  }
}

\newtcbox{\blackbox}[1][]{%
  chapterhead,
  #1,
}

%% Chapterstyle
\makechapterstyle{lucknerto}{%
\setlength{\beforechapskip}{-2\onelineskip}%
\setlength{\afterchapskip}{2\onelineskip}%
\renewcommand*{\printchaptername}{}%
\renewcommand*{\chapternamenum}{}%
\renewcommand*{\chapnumfont}{\normalfont\large\sffamily\bfseries}%
\renewcommand*{\afterchapternum}{}%
\renewcommand{\printchaptertitle}{\centering\tcbox[nobeforeafter,halign=center,valign=center,colback=black,size=tight,colupper=white,code={\noexpand\MakeUppercase}]}%\centering\archivo\color{blue}\fontsize{23}{27.6}\selectfont\MakeUppercase}
\renewcommand{\printchaptertitle}[1]{\centering\blackbox{\MakeUppercase{##1}}}%\centering\archivo\color{blue}\fontsize{23}{27.6}\selectfont\MakeUppercase}
}
\chapterstyle{lucknerto} %% enable

%% Pagestyle 
\makepagestyle{luckner}%
\makeevenhead{luckner}{}{\small{{\MakeUppercase{book title}}}}{} 
\makeoddhead{luckner}{}{\small{{\MakeUppercase{\leftmark}}}}{}
\makeevenfoot{luckner}{\large{\thepage}}{}{}
\makeoddfoot{luckner}{}{}{\large{\thepage}}
\pagestyle{luckner} %% enable

\begin{document}
\chapter{Foobar}
\lipsum[1-20]
\end{document}

enter image description here

Output with Mikodacs font:

enter image description here

3
  • Thanks! Only small comment is that there seems to be a white border to the box, can this be fixed? Commented Apr 17, 2017 at 14:59
  • @KristianNordestgaard: colframe=black as option to the box or in the chapterhead style for the box (that's the easiest way, I think)
    – user31729
    Commented Apr 17, 2017 at 15:02
  • Splendid! Gracias! Commented Apr 17, 2017 at 15:05

You must log in to answer this question.

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