我想增加带框章节标题左右边缘之间的空间。我对 LaTeX 还很陌生,并且对软件包文档感到困惑。我该如何在框架内设置文本边距,或者将框架的大小增加到现有文本边距之外?也许软件包可以解决这个问题mdframed
?
示例代码:
\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}
答案1
抱歉,事实证明这很简单(参见注释代码):
\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}