我正在尝试自定义部分标题。以下是 MWE:
\documentclass{book}
\usepackage{fontspec}
\newcommand{\mraggedright}{\rightskip=0pt plus1fil}
%macros to change space before and after section title.
\newlength{\blsectionskip}
\setlength{\blsectionskip}{0.5truecm minus0.3truecm}
\newcommand{\setbsectionskip}[1][0.5truecm minus0.3truecm]{\setlength{\blsectionskip}{#1}}
\newlength{\alsectionskip}
\setlength{\alsectionskip}{0.5truecm minus0.3truecm}
\newcommand{\setasectionskip}[1][0.5truecm minus0.3truecm]{\setlength{\alsectionskip}{#1}}
\newcommand{\resetsectionskip}{\setlength{\blsectionskip}{0.5truecm minus0.3truecm}%
\setlength{\alsectionskip}{0.5truecm minus0.3truecm}}
\newfontface{\sectionfont}{Arial Bold}[Scale=1.8]
\newcommand{\msection}[2][{\sectionfont\bfseries 9.9}]{
\mbox{}\\[\blsectionskip]
%\bigskip
\begin{minipage}[t]{\textwidth}%
\rule{\textwidth}{1truept}\mbox{}\\*[-20truept]\refstepcounter{section}%
\begin{list}{}%
{\setlength{\labelsep}{12truept}\settowidth{\labelwidth}{#1}%
\setlength{\leftmargin}{12truept}\addtolength{\leftmargin}{\labelwidth}}%
\item[{\sectionfont\arabic{chapter}.\arabic{section}\hfill}]%
{\sectionfont\bfseries\mraggedright\protect{ #2}}
\end{list}
\mbox{}\\*[-30truept]\rule{\textwidth}{1pt}\end{minipage}%
\mbox{}\\[\alsectionskip]
%\bigskip
}
\begin{document}
\setcounter{chapter}{1}
\msection{Matrix}
\msection{A VERY LONG LONG LONG LONG LONG SECTION TITLE}
\setcounter{section}{10}
\msection[1.11]{A VERY LONG LONG LONG LONG LONG SECTION TITLE}
\end{document}
以下是使用 lualatex 编译时的输出屏幕截图:
前两个标题没问题。但第三个标题完全错误。第二行中的 L 应该与第一行中的 A 对齐。但事实并非如此。不知为何\settowidth
不起作用。问题可能出在哪里?