Difference between revisions of "Framed"

From ConTeXt wiki
(Coloring frame background and framed text: adding rounded corners)
(added subsection on gray math background)
Line 127: Line 127:
  
 
See the [[Colors]] section for more information on available colors and color usage.
 
See the [[Colors]] section for more information on available colors and color usage.
 +
 +
== Shaded background for part of a displayed equation ==
 +
 +
To highlight part of a formula, you can give it a gray background using <cmd>framed</cmd>:
 +
 +
<texcode>
 +
\setupcolors[state=start]
 +
\def\graymath{\mframed[frame=off,
 +
    background=color,
 +
    backgroundcolor=gray,
 +
    backgroundoffset=3pt]}
 +
 +
\startformula
 +
  \ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.
 +
\stopformula
 +
</texcode>
 +
 +
<context>
 +
\setupcolors[state=start]
 +
\def\graymath{\mframed[frame=off,
 +
    background=color,
 +
    backgroundcolor=gray,
 +
    backgroundoffset=3pt]}
 +
 +
\startformula
 +
  \ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.
 +
\stopformula
 +
</context>
 +
 +
The <cmd>,</cmd> add a tiny bit of space to prevent the gray background from crowding the equals and plus sign.
  
 
= Similar topics =
 
= Similar topics =

Revision as of 18:54, 13 April 2009

< Visuals |



TODO: the page devoted to all kinds of framed stuff (See: To-Do List)


How to achieve specific results

Preventing hyphenation

One can prevent hyphenation inside a frame by passing nothypenated option to align. It is also a good idea to add verytolerant and strectch options.

\startcombination[2*1]
{\framed
   [width=5cm,
    align={flushleft}]
   {\input ward \endgraf}}
{flushleft}
{\framed
   [width=5cm,
    align={flushleft,nothyphenated,verytolerant}] % maybe also stretch
   {\input ward \endgraf}}
{flushleft,\crlf nothypenated, \crlf verytolerant}
\stopcombination

Specify the width no longer than needed

I want to specify the maximum width of a frame. If the size of the box is smaller than the maximum width, I want a tight box. This can be done using the autowidth=force option to framed.

\defineframed
   [tightframed][width=5cm,autowidth=force,align=middle]

\tightframed{Small}

\tightframed{A really really long line that is split at 5cm}

Rounded Corners

\framed allows you to have round corners with corner=round. There are also other possibilities if you want round corners but not at all places by giving an appropriate number to corner=.... This example is taken from core-rul.tex and each frame is typeset using

 \framed[corner=....,frame=on]{...}

  • You can only fill the frame with a background color if the corner shape is closed. Otherwise, the backgroundcolor option will be silently ignored.


Coloring frame background and framed text

First you have to turn on colors with \setupcolors[state=start]. Then you can define the background and foreground (=text) colors:

\framed[background=color,backgroundcolor=....,foreground=color,foregroundcolor=...]{...}

If you want to make the frame itself disappear, add a frame=off to the setups.


For filling frames with offset you have to add options frameoffset=..., backgroundoffset=...

See the Colors section for more information on available colors and color usage.

Shaded background for part of a displayed equation

To highlight part of a formula, you can give it a gray background using \framed:

\setupcolors[state=start]
\def\graymath{\mframed[frame=off,
    background=color,
    backgroundcolor=gray,
    backgroundoffset=3pt]}

\startformula
  \ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.
\stopformula

The \, add a tiny bit of space to prevent the gray background from crowding the equals and plus sign.

Similar topics