2

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.

1
  • 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 Bot
    Commented Dec 14, 2022 at 17:45

4 Answers 4

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

3
  • 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
    Commented Dec 15, 2022 at 6: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
    Commented Dec 15, 2022 at 7:01
  • Ta. I try not to do complicated things. I have enough trouble with simple as it is.
    – Stanley
    Commented Dec 15, 2022 at 7: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

3
  • How can I change the gap between number chapter and the | ?
    – juanuni
    Commented Feb 28, 2023 at 6:24
  • @juanuni loffset=XXpt Commented Feb 28, 2023 at 8:27
  • this works on gap between | and text in frame.
    – juanuni
    Commented Feb 28, 2023 at 12:53
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

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.

1
  • This does kind of work, but you'd need to type the \| for every chapter, making it hard to keep things consistent. Commented Dec 15, 2022 at 6:34

You must log in to answer this question.

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