Difference between revisions of "Combinations"

From Wiki
Jump to navigation Jump to search
m (just add example in <context> for online rendering)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
< [[Graphics]], [[Using Graphics]] | [[Tables]] >
+
Combinations are ConTeXt's way to align several pictures (preferrably at same size):
  
Combinations are ConTeXt's way to align several pictures (preferrably at same size):
+
== Combinations ==
  
 
<texcode>
 
<texcode>
\startcombination[x*y]
+
\startcombination[x*y] %% x=columns, y=rows
 
{something}{caption} ...
 
{something}{caption} ...
 
...
 
...
 
\stopcombination
 
\stopcombination
 
</texcode>
 
</texcode>
 +
 +
or using the newer interface:
 +
 +
<texcode>
 +
\startcombination [nx=3, ny=2]  %% 3 columns, 2 rows
 +
  \startcontent something \stopcontent
 +
  \startcaption caption  \stopcaption
 +
  \startcontent something \stopcontent
 +
  \startcaption caption  \stopcaption
 +
  \startcontent something \stopcontent
 +
  \startcaption caption  \stopcaption
 +
  \startcontent something \stopcontent
 +
  \startcaption caption  \stopcaption
 +
  \startcontent something \stopcontent
 +
  \startcaption caption  \stopcaption
 +
  \startcontent something \stopcontent
 +
  \startcaption caption  \stopcaption
 +
\stopcombination
 +
 +
</texcode>
 +
 
means:
 
means:
  
 
You define, how much figures in columns * rows you'd like to align.
 
You define, how much figures in columns * rows you'd like to align.
  
You must provide one "figure something" (e.g. an <cmd>externalfigure</cmd>) and a caption for every "cell".
+
You must provide one "figure something" (e.g. an {{cmd|externalfigure}}) and a caption for every "cell".
  
 
The sample, from the manual, shows how to define a caption for the whole group and use it as float (see [[Floating Objects]]):
 
The sample, from the manual, shows how to define a caption for the whole group and use it as float (see [[Floating Objects]]):
  
 
<context source=yes>
 
<context source=yes>
\placefigure
+
\useMPlibrary [dum] %% sample images
[here] % placement option
+
 
[fig:combinations] % reference
+
\startplacefigure [title=An example of a combination]
{An example of combination} % caption for whole group
+
  \startcombination [nx=3, ny=2]
{
+
    \startcontent \externalfigure [dummy] \stopcontent
\startcombination[3*2] % 3 columns, 2 rows
+
    \startcaption a                       \stopcaption
{\externalfigure[lb00220]} {a} {\externalfigure[lb00221]} {b} % picture and caption for two figures in first row
+
    \startcontent \externalfigure [dummy] \stopcontent
{\externalfigure[lb00222]} {c} {\externalfigure[lb00223]} {d}
+
    \startcaption b                       \stopcaption
{\externalfigure[lb00225]} {e} {\externalfigure[lb00226]} {f}
+
    \startcontent \externalfigure [dummy] \stopcontent
 +
    \startcaption c                       \stopcaption
 +
    \startcontent \externalfigure [dummy] \stopcontent
 +
    \startcaption d                      \stopcaption
 +
    \startcontent \externalfigure [dummy] \stopcontent
 +
    \startcaption e                      \stopcaption
 +
    \startcontent \externalfigure [dummy] \stopcontent
 +
    \startcaption f                      \stopcaption
 +
  \stopcombination
 +
\stopplacefigure
 +
</context>
 +
 
 +
=== Image Width ===
 +
 
 +
The image widths aren’t calculated automatically:
 +
 
 +
<context source="yes">
 +
\startcombination[3*1]
 +
  {\externalfigure[cow]}{cow}
 +
  {\externalfigure[mill]}{mill}
 +
  {\externalfigure[hacker]}{hacker}
 
\stopcombination
 
\stopcombination
} % whole combination in braces of placefigure
+
</context>
 +
 
 +
You could define them on your own:
 +
 
 +
<texcode>
 +
\startcombination[3*1]
 +
  {\externalfigure[cow]  [width=.3\textwidth]}{cow}
 +
  {\externalfigure[mill]  [width=.3\textwidth]}{mill}
 +
  {\externalfigure[hacker][width=.3\textwidth]}{hacker}
 +
\stopcombination
 +
</texcode>
 +
 
 +
But that’s ugly and tedious. Hans did it for you in {{src|grph-inc.mkxl}}:
 +
 
 +
<texcode>
 +
\definemeasure[combination][
 +
  (\textwidth
 +
  -\effectiveleftskip
 +
  -\effectiverightskip
 +
  -\numexpr\combinationparameter\nx-\plusone\relax\dimexpr\combinationparameter\distance\relax
 +
  )/\combinationparameter]
 +
</texcode>
 +
 
 +
So you can say:
 +
 
 +
<texcode>
 +
\startcombination[3*1]
 +
  {\externalfigure[cow]  [width=\measure{combination}]}{cow}
 +
  {\externalfigure[mill]  [width=\measure{combination}]}{mill}
 +
  {\externalfigure[hacker][width=\measure{combination}]}{hacker}
 +
\stopcombination
 +
</texcode>
 +
 
 +
But that’s still tedious.
 +
 
 +
With the power of {{cmd|defineexternalfigure}}:
 +
 
 +
<texcode>
 +
\defineexternalfigure[combination][width=\measure{combination}]
 +
</texcode>
 +
(That’s predefined, no need to copy!)
 +
 
 +
<context source="yes">
 +
\startcombination[3*1]
 +
  {\externalfigure[cow]  [combination]}{cow}
 +
  {\externalfigure[mill]  [combination]}{mill}
 +
  {\externalfigure[hacker][combination]}{hacker}
 +
\stopcombination
 +
</context>
 +
 
 +
Beautiful. ;)
 +
 
 +
== Floatcombinations ==
 +
 
 +
When combination contain floats, the command {{cmd|startfloatcombination}} is used. Here an example using float combinations as well as subfloatnumbering that creates subfigures sharing a mutual figure prefix and an individual subfigure designator (e.g. figure 1a), figure 1b, etc.).
 +
 
 +
<context source=yes>
 +
\useMPlibrary [dum]
 +
 
 +
\startplacefigure [location=none]
 +
  \startfloatcombination [nx=2]
 +
    \startplacefigure [title=Left, reference=ref:left, group=one, groupsuffix=a]
 +
      \externalfigure
 +
    \stopplacefigure
 +
    \startplacefigure [title=Right, reference=ref:right, group=one, groupsuffix=b]
 +
      \externalfigure
 +
    \stopplacefigure
 +
  \stopfloatcombination
 +
\stopplacefigure
 +
 
 +
See \in{image}[ref:right] (right) and \in{image}[ref:left] (left).
 
</context>
 
</context>
  
 
== Setup ==
 
== Setup ==
  
There is {{cmd|setupcombinations}} command.
+
There is the {{cmd|setupcombinations}} command.
 
 
[[Category:Graphics]]
 
[[Category:Text elements]]
 
  
 
== Referencing ==
 
== Referencing ==
Line 49: Line 157:
  
 
This would produce something like 'figure 2.4d'. The content of the second parameter simply gets appended to the end of the figure's reference-number, thus the example above would still work even if the caption would be 'd) An awesome subfigure'.
 
This would produce something like 'figure 2.4d'. The content of the second parameter simply gets appended to the end of the figure's reference-number, thus the example above would still work even if the caption would be 'd) An awesome subfigure'.
 +
 +
== See also ==
 +
[[Floating_Objects#Subfloats]], {{cmd|startfloatcombination}}, {{cmd|startsubfloatnumbering}}
 +
 +
[[Category:Graphics]]

Latest revision as of 23:20, 10 April 2023

Combinations are ConTeXt's way to align several pictures (preferrably at same size):

Combinations

\startcombination[x*y] %% x=columns, y=rows
{something}{caption} ...
...
\stopcombination

or using the newer interface:

\startcombination [nx=3, ny=2]  %% 3 columns, 2 rows
  \startcontent something \stopcontent
  \startcaption caption   \stopcaption
  \startcontent something \stopcontent
  \startcaption caption   \stopcaption
  \startcontent something \stopcontent
  \startcaption caption   \stopcaption
  \startcontent something \stopcontent
  \startcaption caption   \stopcaption
  \startcontent something \stopcontent
  \startcaption caption   \stopcaption
  \startcontent something \stopcontent
  \startcaption caption   \stopcaption
\stopcombination

means:

You define, how much figures in columns * rows you'd like to align.

You must provide one "figure something" (e.g. an \externalfigure) and a caption for every "cell".

The sample, from the manual, shows how to define a caption for the whole group and use it as float (see Floating Objects):

\useMPlibrary [dum]  %% sample images

\startplacefigure [title=An example of a combination]
  \startcombination [nx=3, ny=2]
    \startcontent \externalfigure [dummy] \stopcontent
    \startcaption a                       \stopcaption
    \startcontent \externalfigure [dummy] \stopcontent
    \startcaption b                       \stopcaption
    \startcontent \externalfigure [dummy] \stopcontent
    \startcaption c                       \stopcaption
    \startcontent \externalfigure [dummy] \stopcontent
    \startcaption d                       \stopcaption
    \startcontent \externalfigure [dummy] \stopcontent
    \startcaption e                       \stopcaption
    \startcontent \externalfigure [dummy] \stopcontent
    \startcaption f                       \stopcaption
  \stopcombination
\stopplacefigure

Image Width

The image widths aren’t calculated automatically:

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

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 in grph-inc.mkxl:

\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. ;)

Floatcombinations

When combination contain floats, the command \startfloatcombination is used. Here an example using float combinations as well as subfloatnumbering that creates subfigures sharing a mutual figure prefix and an individual subfigure designator (e.g. figure 1a), figure 1b, etc.).

\useMPlibrary [dum]

\startplacefigure [location=none]
  \startfloatcombination [nx=2]
    \startplacefigure [title=Left, reference=ref:left, group=one, groupsuffix=a]
      \externalfigure
    \stopplacefigure
    \startplacefigure [title=Right, reference=ref:right, group=one, groupsuffix=b]
      \externalfigure
    \stopplacefigure
  \stopfloatcombination
\stopplacefigure

See \in{image}[ref:right] (right) and \in{image}[ref:left] (left).

Setup

There is the \setupcombinations command.

Referencing

To reference a subfigure you can provide the subfigure's caption as a second parameter to the \in command.

To reference the subfigure with the caption d you would write:

\in{figure}{d}[fig:combinations]

This would produce something like 'figure 2.4d'. The content of the second parameter simply gets appended to the end of the figure's reference-number, thus the example above would still work even if the caption would be 'd) An awesome subfigure'.

See also

Floating_Objects#Subfloats, \startfloatcombination, \startsubfloatnumbering