5

I am trying to improve overview in working sheets and right now I am trying to frame a whole section, preferably with rounded corners but couldn't find any solutions. Is there something like \framedsection in context?

11

You can use the textbackground environment to put a frame around the content of a section. With the beforesection and aftersection keys you can start and stop the frame at the begin and end of a section but you have to use start/stop-version of a section command to get this working.

Unlike other mechanism like the background environment textbackground doesn’t change the position of the section content and works also with floats and split tables.

\definetextbackground
  [SectionFrame]
  [background=,
   framecolor=red,
   corner=round,
   location=paragraph,
   before={\blank[2*big]}]

\definehead[framedsection][section]

\setuphead
  [framedsection]
  [before=,
   beforesection={\starttextbackground[SectionFrame]},
   aftersection=\stoptextbackground]

\starttext

\startsection[title=Knuth]
\input knuth
\stopsection

\startframedsection[title=Tufte]
\input tufte
\stopframedsection

\stoptext

Adding a frame around the content of a section

To improve the layout of the frame you can create your own MetaPost graphic which add a distance between the frame and the content.

\startuseMPgraphic{sectionframe}
    begingroup;
        for i=1 upto nofmultipars :
            draw ( llcorner multipars[i]
                -- lrcorner multipars[i]
                -- urcorner multipars[i]
                -- ulcorner multipars[i]
                -- cycle )
            enlarged (EmWidth,EmWidth)
            cornered (2*EmWidth)
            withcolor "red" ;
        endfor ;
    endgroup;
\stopuseMPgraphic

\definetextbackground
  [SectionFrame]
  [mp=sectionframe,
   location=paragraph,
   before={\blank[2*big]}]

Custom design for the section frame

7

Use the background mechanism. It can break across pages.

\unprotect

\definebackground
  [_background_framed_section]
  [
    corner=round,
    frame=on,
    background=,
  ]

\define\startframedsection{\dodoubleempty\start_framed_section}
\define\stopframedsection{\stop_framed_section}

\starttexdefinition unexpanded start_framed_section [#1][#2]
  \start_background_framed_section
  \doifsomethingelse{#2}{
    \message{first branch}
    \getvalue{start#1}[#2]
    \setvalue{stop_framed_section_level}{#1}
  }{
    \message{second branch}
    \startsection[#1]
    \setvalue{stop_framed_section_level}{section}
  }
\stoptexdefinition

\starttexdefinition unexpanded stop_framed_section
  \getvalue{stop\getvalue{stop_framed_section_level}}
  \stop_background_framed_section
\stoptexdefinition

\protect

\starttext

\startframedsection[title=Knuth]
  \dorecurse{10}{
    \input knuth
  }
\stopframedsection

\stoptext

enter image description here

  • The background environment has limitations when the section contains floats or split tables with repeated headers/footers. – Wolfgang Schuster Jan 19 '17 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.