# Centering chapter titles with ConteXt

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

Chapter I: First chapter

 \mainlanguage[fr]

[commandbefore={:\,},
alternative=middle]

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

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

\definelayout
[firstpage]

[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]

\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


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]

[centered]
[alternative=vertical,

\vbox {
\veryraggedcenter
\let\\\endgraf
\let\crlf\endgraf
\strut
%\par % <-- commented out
\else
\fi
\begstrut
\endstrut
}
\stopsetups

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

\setuplabeltext[fr][chapter=Chapitre ]

\starttext

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

\stoptext


• 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