2

The align=center option of \setupcaptions can align the caption in the middle of figure or table. It's OK with one-line caption text, while not so good for multiple lines of caption texts, for all lines align in the middle.

How to make the effect like the following example, which the first words of caption text from the second line on line up with the first word after caption label?

Figure 1 This is very long caption text as 
         an example.

2 Answers 2

4

Starting with version 2019.12.27 19:26 of ConTeXt you can use \setupcaption[hang=yes] to have a hanging title for float captions.

\setupexternalfigures[location=default]

\setupcaption
  [figure]
  [align=tolerant]

\starttext

\startplacefigure[title={\samplefile{jojomayer}}]
  \externalfigure[hacker][width=.75\textwidth]
\stopplacefigure

\setupcaption
  [figure]
  [hang=yes]

\startplacefigure[title={\samplefile{jojomayer}}]
  \externalfigure[hacker][width=.75\textwidth]
\stopplacefigure

\stoptext

enter image description here

3

Right now that is only achievable by patching the core, but I've emailed the development list about this: https://mailman.ntg.nl/pipermail/dev-context/2019/003636.html

\unprotect

\def\strc_floats_make_complete_caption
  {\doifsomething{\floatcaptionparameter\c!spacebefore}{\blank[\floatcaptionparameter\c!spacebefore]}%
   \strc_floats_make_complete_caption_before
   \synchronizedisplaydirection % temp hack, till we have a proper model
   \noindent
   \gdef\lastcaptiontag{\strut\thecurrentfloatnumber}% was xdef ... needs checking
   \begingroup
     \usefloatcaptionstyleandcolor\c!style\c!color
     \clf_doifelselisthastitle{\currentfloat}\numexpr\currentfloatnumber\relax
       \donothing
       \emptyfloatcaptiontrue
     \ifnofloatnumber
     \else
       \floatcaptionparameter\c!headcommand % <- nieuw
         {\usefloatcaptionstyleandcolor\c!headstyle\c!headcolor\thecurrentfloatnumber}%
       \ifnofloatcaption \else \ifemptyfloatcaption \else
         \doifelsenothing{\floatcaptionparameter\c!spaceinbetween}
           {\floatcaptionparameter\c!headseparator\relax
            \scratchskip\floatcaptionparameter\c!distance\relax
            \dotfskip\scratchskip\emergencystretch.5\scratchskip}
           {\blank[\floatcaptionparameter\c!spaceinbetween]}%
       \fi \fi
     \fi
     \ifnofloatcaption
       \global\d_strc_floats_caption_height\zeropoint
       \global\d_strc_floats_caption_depth \zeropoint
     \else
       \usefloatcaptionstyleandcolor\c!textstyle\c!textcolor
       \global\d_strc_floats_caption_height\strutheight
       \global\d_strc_floats_caption_depth \strutdepth
       \thecurrentfloatcaption\endgraf
     \fi
   \endgroup
   \strc_floats_make_complete_caption_after
   \doifsomething{\floatcaptionparameter\c!spaceafter}{\blank[\floatcaptionparameter\c!spaceafter]}}

\protect

\define[1]\hanginghead{\llap{\hbox to 5em{#1\hss}}}

\setupcaption
  [figure]
  [width=\dimexpr\textwidth-5em\relax,
   headcommand=\hanginghead,
   distance=0pt]

\starttext

\startplacefigure[title={\samplefile{knuth}}]
  \externalfigure[cow]
\stopplacefigure

\stoptext
1
  • Thanks, Menke. It really helps.
    – gannaiju
    Dec 25, 2019 at 5:00

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.