请问如何更改像这张照片这样的章节格式?
\documentclass{book}
\usepackage{titlesec}
\usepackage[tracking=true]{microtype}
\usepackage{lipsum}% juts to generate text for the example
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{4ex}
{\titlerule
\vspace{2ex}%
\filright}
[\vspace{2ex}%
\titlerule]
\begin{document}
\chapter{Introduction}
\lipsum[4]
\end{document}
答案1
像这样吗?
显然,您可能希望调整大小等。我假设您的章节数可能是两位数,并且无论如何,右侧的行和标题都应占用相同的宽度。如果您的章节数少于 10 个,您可以考虑在计算相关宽度的代码中更改99
为。9
请注意,尽管和朋友很受欢迎,但我个人还是很反感的,titlesec
我自己也不太可能使用这种方法。所以你提供 MWE 是件好事,否则我可能会给你不兼容的代码,并给你带来各种麻烦!
买者自负 ...
\documentclass{book}
\usepackage{titlesec,calc}
\usepackage[tracking=true]{microtype}
\usepackage{lipsum}% juts to generate text for the example
\AtBeginDocument{%
\newlength\chaptertitlenamewidth
\newlength\chapternumberwidth
\newlength\chapternumberheight
\newlength\chaptertitlenameheight
\newlength\chaptertitlenameraise
\newlength\chaptertitlewidth
\newsavebox{\chaptertitlenamebox}%
\sbox\chaptertitlenamebox{\bfseries\MakeUppercase{\chaptertitlename}}%
\settowidth{\chaptertitlenamewidth}{\usebox{\chaptertitlenamebox}}%
\settototalheight{\chaptertitlenameheight}{\usebox{\chaptertitlenamebox}}%
\settowidth{\chapternumberwidth}{\bfseries\Huge 99}%
\settototalheight{\chapternumberheight}{\bfseries\Huge 99}%
\setlength{\chaptertitlenameraise}{\chapternumberheight-\chaptertitlenameheight}%
\setlength{\chaptertitlewidth}{\textwidth-\chaptertitlenamewidth-\chapternumberwidth-.5em}%
}
\titleformat{\chapter}[block]{\bfseries}{\raisebox{\chaptertitlenameraise}{\usebox{\chaptertitlenamebox}}\hskip .25em\begin{minipage}[b]{\chapternumberwidth}\filcenter\Huge\thechapter\end{minipage}}{0pt}{%
\hskip .25em\begin{minipage}[b]{\chaptertitlewidth}\titlerule[1pt]\vspace{2ex}%
}[\end{minipage}]
\begin{document}
\chapter{Introduction}
\lipsum[4]
\end{document}
答案2
我建议使用这个方案:
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{graphicx} \usepackage[tracking=true]{microtype}
\usepackage{lipsum}% just to generate text for the example
\titleformat{\chapter}[block]
{\SetTracking[no ligatures = {f}]{encoding = *}{40}}%
{\filright\sffamily\parbox[b][1.6cm][t]{3.5cm}{\MakeUppercase{\large\lsstyle\chaptertitlename} \raisebox{-0.75\height}{\resizebox{!}{1.6cm}{\Huge\thechapter}}}}
{0ex}%
{\parbox[b][1.6cm]{\dimexpr\linewidth-3.5cm-1.6pt\relax}{\titlerule[1.5pt] \vspace{2ex}\vfill\endgraf\filright\bfseries\Large#1}}
\begin{document}
\chapter{Une courte \\Introduction}
\lipsum[4]
\end{document}