ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Maximum width of a caption
@ 2015-01-03 10:11 Mojca Miklavec
  2015-01-04 11:30 ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Mojca Miklavec @ 2015-01-03 10:11 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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.

Thank you,
    Mojca
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Maximum width of a caption
  2015-01-03 10:11 Maximum width of a caption Mojca Miklavec
@ 2015-01-04 11:30 ` Hans Hagen
  2015-01-05 10:22   ` Mojca Miklavec
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2015-01-04 11:30 UTC (permalink / raw)
  To: ntg-context

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Maximum width of a caption
  2015-01-04 11:30 ` Hans Hagen
@ 2015-01-05 10:22   ` Mojca Miklavec
  2015-01-05 10:51     ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Mojca Miklavec @ 2015-01-05 10:22 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sun, Jan 4, 2015 at 12:30 PM, Hans Hagen wrote:
> 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]

Thank you very much. The patch that you sent me for strc-flt.mkvi
seems to work as expected on a long document with many figures.

The only exception are one-liners. The following creates a caption
that extends to almost the whole text width:

    \placefigure
      % Why are there two spaces between "dummy" and "text"?
      {Some \dorecurse{7}{dummy } text}
      {\externalfigure[dummy][width=\textwidth,height=.2\textwidth]}

As soon as slightly more text is added, it shrinks to the desired text width.

(But then again I'm not sure if that is a bug or a feature ;)

Mojca
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Maximum width of a caption
  2015-01-05 10:22   ` Mojca Miklavec
@ 2015-01-05 10:51     ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2015-01-05 10:51 UTC (permalink / raw)
  To: ntg-context

On 1/5/2015 11:22 AM, Mojca Miklavec wrote:
> On Sun, Jan 4, 2015 at 12:30 PM, Hans Hagen wrote:
>> 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]
>
> Thank you very much. The patch that you sent me for strc-flt.mkvi
> seems to work as expected on a long document with many figures.
>
> The only exception are one-liners. The following creates a caption
> that extends to almost the whole text width:
>
>      \placefigure
>        % Why are there two spaces between "dummy" and "text"?
>        {Some \dorecurse{7}{dummy } text}
>        {\externalfigure[dummy][width=\textwidth,height=.2\textwidth]}
>
> As soon as slightly more text is added, it shrinks to the desired text width.

oneliners have a separate branch


> (But then again I'm not sure if that is a bug or a feature ;)
>
> Mojca
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
>


-- 

-----------------------------------------------------------------
                                           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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-01-05 10:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-03 10:11 Maximum width of a caption Mojca Miklavec
2015-01-04 11:30 ` Hans Hagen
2015-01-05 10:22   ` Mojca Miklavec
2015-01-05 10:51     ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).