[NTG-context] TIL: figure combinations

Henning Hraban Ramm texml at fiee.net
Thu Aug 11 23:14:46 CEST 2022


You probably know about combinations to place images side by side:

\startcombination[3*1]
   {\externalfigure[cow]}{cow}
   {\externalfigure[mill]}{mill}
   {\externalfigure[hacker]}{hacker}
\stopcombination

Now, the widths aren’t calculated automatically.
You could define them on your own:

\startcombination[3*1]
   {\externalfigure[cow]   [width=.3\textwidth]}{cow}
   {\externalfigure[mill]  [width=.3\textwidth]}{mill}
   {\externalfigure[hacker][width=.3\textwidth]}{hacker}
\stopcombination

But that’s ugly and tedious. Hans did it for you:

\definemeasure[combination][
   (\textwidth
   -\effectiveleftskip
   -\effectiverightskip
 
-\numexpr\combinationparameter\nx-\plusone\relax\dimexpr\combinationparameter\distance\relax
   )/\combinationparameter]

So you can say:

\startcombination[3*1]
   {\externalfigure[cow]   [width=\measure{combination}]}{cow}
   {\externalfigure[mill]  [width=\measure{combination}]}{mill}
   {\externalfigure[hacker][width=\measure{combination}]}{hacker}
\stopcombination

But that’s still tedious.

With the power of \defineexternalfigure:

\defineexternalfigure[combination][width=\measure{combination}]
(That’s predefined, no need to copy!)

\startcombination[3*1]
   {\externalfigure[cow]   [combination]}{cow}
   {\externalfigure[mill]  [combination]}{mill}
   {\externalfigure[hacker][combination]}{hacker}
\stopcombination

Beautiful. ;)


Have fun,
Hraban


More information about the ntg-context mailing list