4

I want to define a new float to enclose my document examples in a frame with grey bakcground. Here is my preamble code so far:

\setupcolumns[n=2]

\definefloat[example][examples]
\definemeasure[atdmexampleoffset][10pt]
\definemeasure[atdmexamplewidth][\dimexpr\textwidth-2\measure{atdmexampleoffset}]
\setupfloat[example][
    location=middle,
    frame=on,
    width=\measure{atdmexamplewidth}, % <------
    offset=\measure{atdmexampleoffset},
    background=color,
    backgroundcolor=atdm-lightgrey%
]

I use the float with this code:

\starttext
\startcolumns

\placeexample[here][ex:foo]{Foo}{%
    For instance: foo. Or bar. Or both. etc.
}

\stopcolumns
\stoptext

The issue I have is that the example text spans over exactly \textwidth, thus making the frame stick out of 2*offset on the right of standard text body (see the gap between the red and green rules).

enter image description here

The width parameter unfortunately seems to have no effect.

Note that the same issue arise with single-column text, only the float stays centered and sticks out by offset both on the left and the right.

How could I make the float occupy the same width as the text below and above it?

  • 1
    It is perhaps better if you give a complete but minimal (non)working example. That way, the people who will help you need not to work so much. – mickep Dec 7 '17 at 12:12
  • Post edited. Concatenating the two code snippets now gives a mwe. – Silverspur Dec 7 '17 at 18:02
9

You should put your texts in a framedtext environment where you can the offset for the margins.

\starttext

\startcolumns

\input knuth

\startplacefloat[title=Zapf]
    \startframedtext[width=max,background=color,backgroundcolor=gray]
    \input zapf
    \stopframedtext
\stopplacefloat

\input tufte

\startplacefloat[title=Ward]
    \startframedtext[width=max,background=color,backgroundcolor=gray]
    \input ward
    \stopframedtext
\stopplacefloat

\input weisman

\stopcolumns

\stoptext

enter image description here

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.