On 1/3/2015 11:11 AM, Mojca Miklavec wrote:
Hi,

Is there any way to set the maximum width of a caption? I would like
to make sure that no figure caption exceeds, say, 75% of text width.

Here's an example of "bad behaviour" in the second figure:

\starttext

\reservefigure
[width=5cm,height=2cm,frame=on][force]
{Some very small figure with not too much text: OK}

\input tufte

This can hardly be distinguished from the main text:

\reservefigure
[width=\textwidth,height=.2\textwidth,frame=on][force]
{\input tufte}

\input tufte

Desired behaviour:

\placefigure[force]{\input tufte}
{\hbox to 
.75\textwidth{\hss\framed[width=\textwidth,height=.2\textwidth]{}\hss}}

\input tufte

\stoptext

I've seen an option maxwidth, but only in connection to
\externalfigure[...][maxwidth=...].

I can cheat as on the third figure above, but that seems like an ugly
approach to me.

can you test this a bit:

\unprotect

\setupcaptions
  [\c!maxwidth=.75\hsize]

\def\strc_floats_prepare_stack_caption_auto
  {\ifx\p_strc_floats_caption_align\empty \else

\doifnotinset\v!middle\p_strc_floats_caption_align{\let\captionovershoot\!!zeropoint}%
   \fi
   \edef\captionhsize{\the\wd\b_strc_floats_content}%
\scratchwidth\floatcaptionparameter\c!maxwidth\relax
   \ifdim\captionhsize>.75\hsize
     % float is wider than \hsize
     \setbox\b_strc_floats_caption\vbox
       {\settrialtypesetting
        \strc_floats_caption_set_align
\hsize\scratchwidth
        \notesenabledfalse
        \strc_floats_make_complete_caption}%
     \ifdim\ht\scratchbox>\lineheight % more lines
       \setbox\b_strc_floats_caption\vbox
         {\strc_floats_caption_set_align
          \hsize\dimexpr\captionhsize-\captionovershoot\relax
          \ifdim\hsize<\captionminwidth\relax
\hsize\scratchwidth
          \fi
          \strc_floats_make_complete_caption}%
     \else
       \setbox\b_strc_floats_caption\vbox
         {\strc_floats_caption_set_align
\hsize\scratchwidth
          \strc_floats_make_complete_caption}%
     \fi
   \else
     % float is smaller of equal to \hsize
     \ifdim\captionhsize<\captionminwidth\relax
       \scratchdimen\captionminwidth % float smaller than min width
       \edef\captionhsize{\the\scratchdimen}%
     \fi
     \setbox\scratchbox\vbox     % test with overshoot
       {\settrialtypesetting

\scratchdimen\dimexpr\captionhsize+\captionovershoot+3\emwidth\relax % 3em is an average word length
        \ifdim\scratchdimen<\hsize
          \hsize\scratchdimen
        \fi
        \notesenabledfalse
        \strc_floats_make_complete_caption}%
     \ifdim\ht\scratchbox>\lineheight
       % at least an average word longer than a line
       \setbox\b_strc_floats_caption\vbox
         {\strc_floats_caption_set_align
          \scratchdimen\dimexpr\captionhsize+\captionovershoot\relax
          \ifdim\scratchdimen<\hsize
            \hsize\scratchdimen
          \fi
          \strc_floats_make_complete_caption}%
     \else\ifx\p_strc_floats_caption_align\empty
       \setbox\b_strc_floats_caption\vbox
         {\strc_floats_caption_set_align
          \hsize\captionhsize
          \raggedcenter % overloads
          \strc_floats_make_complete_caption}%
     \else
       \setbox\b_strc_floats_caption\vbox
         {\strc_floats_caption_set_align
          \hsize\captionhsize
          \strc_floats_make_complete_caption}%
     \fi\fi
   \fi}

\protect


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
    tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to