答案1
我建议按照内置命令的思路定义一个命令\hrulefill
。它用固定厚度的线填充可用空间0.4pt
。我们定义\hrulefillx
与内置命令相同的命令,但使用厚度的可选参数。如果没有参数,它的行为与相同\hrulefill
。
\newcommand\hrulefillx[1][0.4pt]{%
\leavevmode\leaders\hrule height #1\hfill\kern0pt%
}
然后可以通过以下方式生成带有插入章节号的标题行:
\hrulefillx[4pt]\quad\textsc{\chaptertitlename~\thechapter}\quad\hrulefillx[4pt]%
\documentclass{book}
\usepackage[utf8]{vietnam}
\usepackage{lmodern}
\newcommand\hrulefillx[1][0.4pt]{%
\leavevmode\leaders\hrule height #1\hfill\kern0pt%
}
\usepackage{titlesec}
\titleformat{\chapter}[display]{%
\normalfont\bfseries\centering
}{}{10pt}{%
\hrulefillx[4pt]\quad\textsc{\chaptertitlename~\thechapter}\quad\hrulefillx[4pt]%
\vskip3pt%
\titlerule
\vskip4pt%
\LARGE\sffamily
}[%
\titlerule
]
% For starred chapters without number, like table of contents
\titleformat{name=\chapter,numberless}[display]{%
\normalfont\bfseries\centering
}{}{10pt}{%
\hrulefillx[4pt]%
\vskip3pt%
\titlerule
\vskip4pt%
\LARGE\sffamily
}[%
\titlerule
]
\begin{document}
\tableofcontents
\chapter{Các bài toán hệ phương trình nhiều ẩn không mẫu mực}
\section{Hệ hoán vị vòng quanh.}
\end{document}