4

I would like to increase the space between the left and right edges of a framed chapter title. I am very new to LaTeX, and am struggling with the package documentation. How can I set text margins within the frame, or increase the size of the frame beyond existing text margins? Perhaps a solution with the mdframed package?

Example code:

\documentclass{book}
\usepackage{titlesec}
\usepackage{xcoffins}
\usepackage{framed}

\newcommand\headerdisplay[1]{%
\Large
\vskip-.5\baselineskip 
\filcenter{#1}%
\vskip-.5\baselineskip
}

\NewCoffin\mytmpa
\NewCoffin\mytmpb
\newcommand\placeabove[3][0pt]{%
\SetHorizontalCoffin\mytmpa{#2}%
\SetHorizontalCoffin\mytmpb{#3}%
\JoinCoffins*\mytmpb[hc,t]\mytmpa[hc,b](0pt,#1)%
\TypesetCoffin\mytmpb
}

\titleformat{\chapter}[frame]
{\setlength\fboxrule{1pt}\normalfont\Large\sffamily\bfseries}
{\filcenter\placeabove[1\baselineskip]{\Large Chapter}{\Large\enspace\thechapter\enspace}}
{0pt}
{\headerdisplay}

\begin{document}

\chapter{A chapter title that goes too close to the horizontal edges of the frame}

\end{document}    

enter image description here

  • Welcome to TeX.SX! – gusbrs Dec 30 '18 at 0:51
1

Apologies, turns out it was quite straightforward (see commented code):

\documentclass{book}
\usepackage{titlesec}
\usepackage{xcoffins}

\newcommand\headerdisplay[1]{%
\Large
\vskip-.5\baselineskip 
\filcenter{#1}%
\vskip-.5\baselineskip
}

\NewCoffin\mytmpa
\NewCoffin\mytmpb
\newcommand\placeabove[3][0pt]{%
\SetHorizontalCoffin\mytmpa{#2}%
\SetHorizontalCoffin\mytmpb{#3}%
\JoinCoffins*\mytmpb[hc,t]\mytmpa[hc,b](0pt,#1)%
\TypesetCoffin\mytmpb
}

\titleformat{\chapter}[frame]
{\setlength\fboxrule{1pt}\normalfont\Large\sffamily\bfseries}
{\filcenter\placeabove[1\baselineskip]{\Large Chapter}{\Large\enspace\thechapter\enspace}}
{10pt} % previously had 0pt
{\headerdisplay}

\begin{document}

\chapter{A chapter title that goes too close to the horizontal edges of the frame}

\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.