1

I am trying customise section heading. Here is a 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}

Here is a screen shot of the output, when compiled with lualatex:

enter image description here

The first two titles are OK. But the third title is all wrong. The L in the second line should be aligned with A in the first line. But this is not happening. Somehow \settowidth is not working. What can be the problem?

2
  • you have \protect{ but } you are applying \protect to { but not to } mostly that does nothing at all (when \protect is \relax or \noexpand but when \protect is \string this will lead to mis-matched brace errors. – David Carlisle Mar 15 at 8:32
  • @David. Can you expand on it? I don't get what you are trying to say. The MWE compile without any errors. I have been using this command in (pdf)latex for quite a few years now and it works perfectly. I have run into this problem only in lualatex. – S. Venkataraman Mar 15 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.