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.
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.
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
\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 ?
\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.
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
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
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.
\|
for every chapter, making it hard to keep things consistent.
Commented
Dec 15, 2022 at 6:34