TransWikia.com

Problem with alignment in list environment

TeX - LaTeX Asked on April 8, 2021

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][{sectionfontbfseries 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[{sectionfontarabic{chapter}.arabic{section}hfill}]%
            {sectionfontbfseriesmraggedrightprotect{ #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?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP