4

A few days ago I asked a question about customizing chapter titles in context (here). My question was not so appropriate although @mickep gave an answer.

My intention is to get something like this enter image description here

Which is based on the cover of the Typograph journal Vol 01 (2014) and also on a design by an instagram user nicknamed @nochedeespectros.

To achieve it, this time I was playing with the code from this answer this

The result is

\mainlanguage[es] % Idioma = Español

\setuppapersize[A4] % Tamaño del papel

\setupbodyfont
[modern,12pt] % Fuente = Latin Modern, 12 puntos


%\setuphead % Formato de los capítulos
%[chapter]
%[style=\bfc]

\startsetups[titles_table]
    \setupTABLE[r][each][align=lohi,frame=off]
\setupTABLE[2][ leftframe=on,loffset=5mm,rulethickness=2pt,framecolor=darkred,background=color,backgroundcolor=red 
]
\stopsetups

\define[2]\titlesT{%
\bTABLE[setups=titles_table]
    \bTR
         \bTD[nr=2] #1 \hspace[oneem] \eTD  \bTD  #2\eTD    
                                                         \eTR
    \bTR
                                  \bTD \setupinterlinespace[small]\placecontent\eTD
                                                                                   \eTR    
\eTABLE
}

\definehspace[oneem][-.50 em]
\starttexdefinition MyNumberChapterCommand #1
    \tfe #1
    % {\tfe #1}% Test this instead of the one above
    % #1% Test this if the numberstyle is enabled
    \hspace[oneem]
    %\blackrule[
    %    height=\strutheight,% I changed \lineheight to \strutheight
    %    depth=\strutdepth,
    %    width=2pt,
    %    color=darkred,
    %]
\stoptexdefinition


% \definebodyfont[12pt][rm][tfe=Serif at 36pt]
\definefontsize[e]
\definebodyfontenvironment[default][e=8]% 8*12=108

\setuphead[chapter][
    numbercommand=\MyNumberChapterCommand,
    command=\titlesT,
    style=\bfc,
    page=no,%Just to have them on the same page here   
    % numberstyle={\definedfont[Serif*default at 36pt]},
]


\setuphead[section] [textstyle=\bf, numberstyle=\bf]

\definehead[paragraph][subsubsubsection]
\setuphead [paragraph]
           [
             number=no, % To imitate LaTeX
             textdistance=0pt,
             commandafter={\quad\bullet\quad\null},
             alternative=text,
             style=\tf,
          ]

\definehead[contenttitle][title]
\setuphead[contenttitle][page=no]

\starttext

 \startfrontmatter
\contenttitle{\headtext{content}}
\placecontent
\stopfrontmatter

\startbodymatter

\chapter{Here start}
\section{The first section}
\subsection{The first subsection}
\input khatt-en

\subsection{The second subsection}
\input khatt-en

\section{The second section}
\subsection{Another subsection}
\input khatt-en

\chapter{Another chapter}
\section{More sections}
\subsection{More subsections}
\input khatt-en

\stopbodymatter
\stoptext

enter image description here

The are few issues:

  • I can't get the left vertical line to go further to the left so that it is above (as in the first image) the chapter number

  • I have not been able to reduce the font size of the mini-tables of contents. (If the body font size is 12pt, you might consider 10pt or 9pt for mini-tables of contents.) Although I would like to have the ability to apply some criteria, in case the body font size changes to 11pt.

  • I haven't been able to set a line spacing like the one suggested in the documentation:

    \start

    \setupinterlinespace[small]

    \placecontent

    \stop

  • With this code the title of the table of contents, at the beginning, is also affected and for now it would be nice to see the default style for the title of the table of contents. For the table of contents I have another customization in mind but I will attend to that case another time.

  • I have not been able to get a mini table of contents to be generated that includes only sections (even with the option criterium=section).

  • I couldn't get the the label for the chapter title (\setuplabeltext[chapter=Chapter~]) to appear above the chapter title like in the first image.

  • I'm not sure how to make the chapter number base and the mini table of contents base match. And the top of the chapter number matches the top of the label for the chapter title.

  • I just noticed that the size of this customization will, in general, depend on the number of sections in each chapter. This being the case, I wonder if it would be convenient to create a command that allows customizing, in each chapter, the different font sizes that may be involved.

PD: The red color is only shown to be used as a guide. The idea is to use the white color to achieve the effect of the first image. I hope I have given all the necessary information and have expressed myself adequately since English is not my native language.

3
  • Using a table is probably a bad idea here. I'd recommend using a \clip for the number and an \inframed for the TOC. Commented Mar 9, 2023 at 8:13
  • I was thinking about \inframed but couldn't find documentation. I only found information about \setupframed and \framed but couldn't adapt it to use \inframed.
    – juanuni
    Commented Mar 12, 2023 at 5:27
  • \inframed is the same as \framed (or \startframed/\stopframed) except it is inline with the text. Commented Mar 12, 2023 at 6:35

1 Answer 1

6

Updated with simpler solution

We use MetaFun since we want the number to grow with the content. This time without layers, and the good thing is that we then do not have to compensate for the vertical distance.

\setupbodyfont[bonum]

% We do not set the chapterlabel but use our own
\mainlanguage[es]
\setuplabeltext[es][mychapter=Capítulo]

% The table of contents
\definecombinedlist[MyContent]

\setupcombinedlist
  [MyContent]
  [list={section},
   criterium=chapter]

\setuplist[section][
  alternative=c,
  width=2em,
  style={\switchtobodyfont[7pt]\setupinterlinespace[line=9pt]},
]

\startuseMPgraphic{MyChapterGraphic}
  picture toc, num ;
  % You can play with the width, offset, fontsizes and so on.
  toc := textext("\unframed[width=8cm,align=normal,offset=5mm,leftframe=on,rulethickness=1pt]
                  {%
                  {\switchtobodyfont[18pt]\labeltext{mychapter}}\blank[small]
                  {\switchtobodyfont[28pt] \MPtext{2}}\blank[big]
                  \placecombinedlist[MyContent]
                  }") ;
  toc := toc shifted (-llcorner toc) ;
  num := textext("\MPtext{1}") ;
  num := num ysized 0.8(ypart ulcorner toc) ;
  num := num shifted (-llcorner num) ;
  % The 0.55 decides how much to shift the number left, we shift 55%
  % The 0.1 here satisfies 2*0.1+0.8=1, where 0.8 is the number above
  num := num shifted (-0.55(xpart lrcorner num), 0.1(ypart ulcorner toc) ) ;
  % The 10cm is just to make sure that we are off so that we do not cut to the left of the number
  clip num to ((-10cm,0) -- (0,0) -- ulcorner toc -- (-10cm, ypart ulcorner toc) -- cycle) ;
  draw toc ;
  draw num ;
  % This midaligns the content
  currentpicture := currentpicture xshifted 0.5(TextWidth - xpart lrcorner toc - xpart llcorner num) ;
  setbounds currentpicture to unitsquare xyscaled (TextWidth, ypart urcorner toc) ;
\stopuseMPgraphic

\define[2]\MyChapterCommand{%
  \setnostrut% Try without (and add \showstruts to see)
  \setMPtext{1}{#1}%
  \setMPtext{2}{#2}%
  \useMPgraphic{MyChapterGraphic}
}

\setuphead
  [chapter]
  [header=high,
   command=\MyChapterCommand,
   numberstyle=\bf,
   textstyle=\bf]

\starttext

\dorecurse{10}{
  \chapter[title={Level #1}]
  \dorecurse{#1}{
    \section[title={Sublevel ##1}]
    \subsection[title={A subsection}]
    \samplefile{ward}
  }
}

\stoptext

An overview:

overview

A closer look at one chapter:

one chapter

6
  • that was a very nice job. I made some changes to your answer, but I couldn't recognize the command that places the chapter number (and the whole chapter title style layout) more to the left, i.e. left-aligned.
    – juanuni
    Commented Mar 12, 2023 at 5:15
  • There is a issue with the font size of section in table of contents, I think is due style={\switchtobodyfont[7pt]\setupinterlinespace[line=9pt]}
    – juanuni
    Commented Mar 12, 2023 at 5:23
  • 1
    At the end of the startuseMPgraphic things are moved around to get mid-alignment. You have to play with that. Regarding your second comment, I don't know what issue you have, so I don't know what to say.
    – mickep
    Commented Mar 12, 2023 at 7:14
  • When using \completecontent the sections appear in very small letters unlike the subsections and chapters
    – juanuni
    Commented Mar 12, 2023 at 12:08
  • Ah, so you have another table of contents that should be set in some other style. What if you do the \setuplist just before the \placecombinedlist inside the figure (I cannot test right now)? It might then be adapted locally.
    – mickep
    Commented Mar 12, 2023 at 12:17

You must log in to answer this question.

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