1

I am trying to customize chapter title putting the text inside a frame with only the leftframe on.

I am thinking at something like that: "1 | chapter".

Any suggest will be very appreciate.

voyager
  • 51
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 14 '22 at 17:45

4 Answers4

3

One typically wants to keep the stuff in title={} clean from formatting. It is in general better to define your own numbercommand, textcommand (one argument each) or command (two arguments, the first is the number the second the title).

Here are some alternatives where we use the numbercommand:

\starttexdefinition MyNumberChapterCommand #1
    \inframed{#1\enspace}
\stoptexdefinition

\setuphead[chapter][ numbercommand=\MyNumberChapterCommand, page=no,%Just to have them on the same page here ]

\starttext

\startchapter[title={Foo}] Bla bla bla \stopchapter

\starttexdefinition MyNumberChapterCommand #1 \inframed[frame=off,rightframe=on]{#1\enspace} \stoptexdefinition

\startchapter[title={Bar}] Bla bla bla \stopchapter

\starttexdefinition MyNumberChapterCommand #1 #1 \enspace \blackrule[ height=\lineheight, depth=\strutdepth, width=2pt, color=darkred, ] \stoptexdefinition

\startchapter[title={With a rule}] Bla bla bla \stopchapter

\startchapter[title={With a rule, and with a long title that eventually breaks over two lines}] Bla bla bla \stopchapter

\stoptext

some more or less framed head numbers

mickep
  • 8,685
  • Lots of options there. Why does \chapter [title= \inframed[frame=off,leftframe=on]{Chapter~1}] not work, whereas the similar command in the macro \inframed[frame=off,leftframe=on]{ … } does work ? Is it to ensure we keep titles clean ? – Stanley Dec 15 '22 at 06:56
  • What you suggest work if you add curly braces \title={...}. The keys given are separated by commas, and you have a comma inside that is making your input invalid. But I really suggest you to use setups instead. – mickep Dec 15 '22 at 07:01
  • Ta. I try not to do complicated things. I have enough trouble with simple as it is. – Stanley Dec 15 '22 at 07:52
2

You can define a command that uses a \framed to draw the rule, then use textcommand key of \setuphead to apply this to all chapters.

\define[1]\leftframed{%
    \inframed[frame=off, leftframe=on]{#1}%
}

\setuphead[chapter][ textcommand=\leftframed, ]

\starttext \chapter{Section} Hello world! \stoptext

output sample

Max Chernoff
  • 4,667
2

Thank you very much to all for the interestings tips.

I didn't know about "textcommand and numbercommand" option.

I make a solution using a table to keep aligned and centered the title number in case of multiline text.

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

\define[2]\titlesT{% \bTABLE[setups=titles_table] \bTR \bTD #1 \enspace \eTD \bTD #2\eTD
\eTR
\eTABLE }

\setuphead[chapter][ command=\titlesT, page=no ]

\starttext

\startchapter[title={Long title ... ith a rule, and with a long title t eer dfgfdg dfg gfdd fgfdg dfg fdg fdg fdg fdg fdg fdg fdg }] Bla bla bla

\stopchapter

\startchapter[title={short title .. }] Bla bla bla

\stopchapter

\stoptext

voyager
  • 51
0

This achieves what you want without using a frame. The | is a reserved character in ConTeXt; it needs a \ in front to use it as a real |. The tilde ~ between Chapter and 1 is a nonbreaking space.

\starttext
\chapter [title=\| Chapter~1]
\stoptext

I could put a frame around the chapter name with \chapter [title= \inframed{Chapter~1}] but I couldn't figure out how to only have the leftframe on.

Stanley
  • 371