使用 ConteXt 将章节标题居中

使用 ConteXt 将章节标题居中

如何使章节标题chapter I: First chapter居中

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

您必须为此定义自己的替代方案,但这相当简单。转到strc-ren.mkiv并查找\??headrenderings:\v!middle。将定义复制到您的文件中并进行必要的调整。

\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

在此处输入图片描述

答案2

更简单:要得到你想要的,你需要align=center

因此:

\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

改编自维基百科

\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

相关内容