Difference between revisions of "Framed"

From Wiki
Jump to navigation Jump to search
(new section: offsets)
Line 254: Line 254:
 
\stoptext
 
\stoptext
 
</context>
 
</context>
 +
 +
=Spacing between frame and text=
 +
 +
<tt>\framed</tt> comes with two different types of offsets:
 +
one for the frame itself and  another for the its content.
 +
The parameters <tt>frameoffset</tt> and <tt>backgroundoffset</tt>
 +
were already explained above in the section [[#Coloring frame background and framed text]].
 +
 +
==Content offsets==
 +
Beyond those there is another four dimensions that enable you to control
 +
the safety distance of a <tt>\framed</tt>’s content by orientation.
 +
Horizontally, <tt>loffset</tt> governs the left, <tt>roffset</tt> the right
 +
offset;
 +
the same goes for <tt>boffset</tt> for the bottom and <tt>roffset</tt> for
 +
the top distance.
 +
Their effects are explored in the following example (MkIV only).
 +
 +
==Example==
 +
<texcode>
 +
\def\offsetframe[#1]{%
 +
{\framed[
 +
      #1=1em,
 +
  align=normal,
 +
  width=5.3cm,
 +
  height=5.3cm,
 +
  ]{\tfx\input ward }
 +
}{\it#1}
 +
}
 +
 +
\starttext
 +
\startcombination[2*2]
 +
\offsetframe[loffset]
 +
\offsetframe[roffset]
 +
\offsetframe[toffset]
 +
\offsetframe[boffset]
 +
\stopcombination
 +
\stoptext
 +
</texcode>
  
 
= Similar topics =
 
= Similar topics =

Revision as of 10:00, 23 October 2010

< 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*2]
{\framed
   [width=5cm,
    align={flushleft}]
   {\input ward \endgraf}}
{flushleft}
{\framed
   [width=5cm,
    align={flushleft,nothyphenated,verytolerant}] % maybe also stretch
   {\input ward \endgraf}}
{flushleft,\crlf nothyphenated, \crlf verytolerant}
{\framed
   [width=5cm,
    align={flushright,nothyphenated,verytolerant}] % maybe also stretch
   {\input ward \endgraf}}
{flushright,\crlf nothyphenated, \crlf verytolerant}
{\framed
   [width=5cm,
    align={width,nothyphenated,verytolerant}] % maybe also stretch
   {\input ward \endgraf}}
{width,\crlf nothyphenated, \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}

Ruled Frames

\framed allows you to specify specific edges to be ruled. As an alternative to frame=on (the default), one can specify topframe=on, etc. Note that, as the default is to draw a complete frame, it is necessary to either specify the state (on/off) for all four edges or include the keyword frame=off.

\framed[frame=off,topframe=on,leftframe=on]{A fancy title}

The thickness of the frame rule can be specified using rulethickness=

\framed[frame=off,leftframe=on,rulethickness=2pt]{\tfa\bf A fancy title}

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.

\setupcolors[state=start]
\framed
  [background=color,backgroundcolor=darkblue,
   foreground=color,foregroundcolor=white]
  {\ssx \bf Bold white on dark blue}
\framed
  [background=color,backgroundcolor=yellow,
  frame=off]
  {\tfx Who needs highlighter pens, anyway?}
For filling frames with offset you have to add options frameoffset=..., backgroundoffset=...
\framed
  [frame=on, corner=0, frameoffset=10pt,
   framecolor=black,background=color,
   backgroundcolor=darkgreen, backgroundoffset=10pt, 
   foreground=color,foregroundcolor=white]
  {\tfxx \bf Rounded corners with offset}

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 \mframed:

\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.

Inline Frames

The command \inframed, similar to \framed, differs in the definition of the baseline:

\framed[frame=off,width=10em,align=flushleft]{%
Notice the difference between
\framed{framed} and \inframed{inframed},
especially considering its effect on linespacing...
}

Width broad and local

Sometimes width must be adapted to a "local" \hsize (the actual text area used by TeX to determine line breaks). For example:

\setuppapersize[A7,landscape][A7,landscape]
\setupbodyfont[8pt,ss]
\starttext
\framed[width=broad]{}
\startnarrower[left]
\framed[width=broad]{}
\dontleavehmode\framed[width=broad]{}
\dontleavehmode\framed[width=local]{}
\stopnarrower
\blank
\hsize.5\hsize
\framed[width=broad]{}
\startnarrower[left]
\framed[width=broad]{}
\dontleavehmode\framed[width=broad]{}
\dontleavehmode\framed[width=local]{}
\stopnarrower
\stoptext

Here we use \setlocalhsize after \startitemize to setup the localhsize:

\setuppapersize[A7,landscape][A7,landscape]
\setupbodyfont[8pt,ss]
\setupcolors[state=start]
\setupframed[framecolor=blue]
\showframe
\starttext
\framed[width=\hsize,align=middle]{width=hsize}
\startitemize
\setlocalhsize
\item \framed[width=\hsize,align=middle]     {width=hsize}
\item \framed[width=broad,align=middle]     {width=broad}
\item \framed[width=local,align=middle]     {width=local}
\stopitemize
\stoptext

Spacing between frame and text

\framed comes with two different types of offsets: one for the frame itself and another for the its content. The parameters frameoffset and backgroundoffset were already explained above in the section #Coloring frame background and framed text.

Content offsets

Beyond those there is another four dimensions that enable you to control the safety distance of a \framed’s content by orientation. Horizontally, loffset governs the left, roffset the right offset; the same goes for boffset for the bottom and roffset for the top distance. Their effects are explored in the following example (MkIV only).

Example

\def\offsetframe[#1]{%
{\framed[
      #1=1em,
   align=normal,
   width=5.3cm,
  height=5.3cm,
  ]{\tfx\input ward }
}{\it#1}
}

\starttext
\startcombination[2*2]
\offsetframe[loffset]
\offsetframe[roffset]
\offsetframe[toffset]
\offsetframe[boffset]
\stopcombination
\stoptext

Similar topics