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

2 Answers 2

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

6
  • 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
    Commented Jul 23, 2018 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. Commented Jul 23, 2018 at 9:34
  • I have come to adapt Hans indentation scheme That is to say ?
    – Fabrice
    Commented Jul 23, 2018 at 10:20
  • @Fabrice Oh, that's hard to explain :) Just take a look at the file I linked above. Commented Jul 23, 2018 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
    Commented Jul 23, 2018 at 13:43
1

Much easier: to get what you want, you need align=center.

Thus:

\setuppapersize[A5]
\setuplabeltext[chapter=CHAPTER~]

\setuphead[chapter][
    header=empty,
    align=center,
    style=bold,
  numbercommand=\groupedcommand{}{:},
   %commandbefore={:\,},
   %distance=0em,
    after={\blank[3cm]},
    ]

\starttext

\chapter{Title of chapter}

The first paragraph begins 3 cm below the title. In this chapter, we will discuss...

\stoptext

Adapted from the wiki:

\setuppapersize[A5]
\setuplabeltext[chapter=CHAPTER~]

\setuphead[chapter][
    header=empty,
    alternative=middle,
    style=bold,
    numbercommand=\groupedcommand{}{\blank[2cm]},
    after={\blank[3cm]},
    ]

\starttext

\chapter{Title of chapter}

The first paragraph begins 3 cm below the title. In this chapter, we will discuss...

\stoptext

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .