1

How to center chapter titles to have chapter I: First chapter and not

Chapter I: First chapter

 \mainlanguage[fr]

  \setuphead[chapter]
      [commandbefore={:\,},
       header=empty,
       alternative=middle]

  \setuphead[subsection][style=bold]

  \setuphead[section]
      [distance=\zeropoint,
       style=bold,
       commandbefore={\space\endash\space}]

  \setuphead[title][commandbefore={},alternative=middle,header=empty]

  \setuplayout
     [height=middle,
     width=middle,
     backspace=2cm,
     topspace=10mm,       
     bottomspace=10mm,
     header=10mm,
     footer=10mm,
     footerdistance=10mm,
     headerdistance=10mm]

   \definelayout
     [firstpage]
     [header=empty]


  \setupheader[text][after=\hrule]

   \setupheadertexts[{\getmarking[section]}]
             [pagenumber]
             [{\getmarking[chapter]}]
             [pagenumber]


   \setuppagenumbering[alternative=,location=]


  \setuplabeltext[fr][chapter=Chapitre ]

  \definestructureconversionset
     [structure]
     [n, R, n, n, n]

  \definestructureconversionset
     [digits]
     [n, n, n, n, n]

  \setupheads[sectionconversionset=structure]

  \setuplist[chapter][style=bold,width=5mm]

  \starttext

  \starttitle[title={\bf Sommaire}] 
  \placelist
    [chapter,section,subsection]
    [criterium=all,
     alternative=c]

  \stoptitle

 \startchapter[title=First chapter]
 \dorecurse{10}{\input ward}
 \startsection[title=Fist section]
 \dorecurse{10}{\input ward} 
 \startsubsection[title=First subsection]
 \dorecurse{10}{\input ward}
 \stopsubsection
 \stopsection
 \stopchapter
 \startchapter[title=Second chapter]
 \dorecurse{10}{\input ward}
 \startsection[title=Second section]
 \dorecurse{10}{\input ward}
 \startsubsection[title=Second subsection]
 \dorecurse{10}{\input ward}
 \stopsubsection
 \stopsection
 \stopchapter
 \stoptext
1

You have to define your own alternative for that but that's fairly straightforward. Go to strc-ren.mkiv and look for \??headrenderings:\v!middle. Copy the definition to your file and make the necessary adjustments.

\mainlanguage[fr]

\defineheadalternative
  [centered]
  [alternative=vertical,
   renderingsetup=headrenderings:centered]

\startsetups[headrenderings:centered]
    \vbox {
        \headsetupspacing
        \veryraggedcenter
        \let\\\endgraf
        \let\crlf\endgraf
        \ifconditional\headshownumber
            \strut
            \headnumbercontent
            %\par % <-- commented out
        \else
            \fakeheadnumbercontent
        \fi
        \begstrut
        \headtextcontent
        \endstrut
    }
\stopsetups

\setuphead
  [chapter]
  [commandbefore={:\,},
   header=empty,
   alternative=centered]

\setuplabeltext[fr][chapter=Chapitre ]

\starttext

\startchapter[title=First chapter]
  \input ward
\stopchapter

\stoptext

enter image description here

  • Thanks a lot for your answer. This has nothing to do with the subject but as you are a specialist of ConteXt, is the code clean ? Can we optimize it ? – Fabrice Jul 23 '18 at 9:06
  • @Fabrice It looks pretty clean already. I'd harmonize the indentation and remove the unused structure conversion sets. I have come to adapt Hans' indentation scheme, as demonstrated in, e.g. the LuaTeX manual. Also I'm not really a specialist of ConTeXt. – Henri Menke Jul 23 '18 at 9:34
  • I have come to adapt Hans indentation scheme That is to say ? – Fabrice Jul 23 '18 at 10:20
  • @Fabrice Oh, that's hard to explain :) Just take a look at the file I linked above. – Henri Menke Jul 23 '18 at 10:25
  • I wanted to test by compiling the file luatex.tex using the simple command context luatex.tex but it does not work because I do not understand why \ startdocument ... \ endocument while we use ConteXt. – Fabrice Jul 23 '18 at 13:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.