3

I am trying to generate proportionality tables, like this one:

From this answer I know it is possible to change background of a cell, so I tried to change the background of the last column. The following code shows as far as I could go

\startuseMPgraphic{TableArrow}
  path p ; p := halfcircle scaled OverlayHeight ;
  drawarrow reverse(p) ;
  clip currentpicture to OverlayBox;
\stopuseMPgraphic

\defineoverlay[TableArrow][\useMPgraphic{TableArrow}]

\starttext
  \bTABLE
  \setupTABLE[last][first][background=TableArrow]
  \setupTABLE[c][each][width=0.150\textwidth]
  \bTABLEbody
  \bTR\bTD Number of Bottles \eTD
      \bTD $2$ \eTD
      \bTD $3$ \eTD
      \bTD $4$ \eTD
      \bTD $\cdots$ \eTD
      \bTD $x$ \eTD
      \bTD[nr=2]\eTD\eTR
  \bTR\bTD Price (\$)\eTD
      \bTD $2.40$ \eTD
      \bTD $3.60$ \eTD
      \bTD $4.80$ \eTD
      \bTD $\cdots$ \eTD
      \bTD $y$ \eTD\eTR
  \eTABLEbody
  \eTABLE
\stoptext

but I could not make it.

When I shifted the path it "disappears". How can I start and end the arrow on the edges of previous cells? And, a bit strange, why when I scaled the halfcircle with OverlayHeight/2 it does not work? Anyway I probably should use something else than halfcircle but I do not know what exactly.

Subsidiary question. How can I act on penultimate cells with \setupTABLE? I tried \setupTABLE[row][last-1][] but I does not seem to work.

1 Answer 1

2

Instead of clipping, you can set the width of the last column in the table to zero, and play with the bounding box of the MetaFun graphic. I also changed some parameters in the table to make it look more as in the picture you attached. The 3pt in the x-coordinates in the path p correspond to the offset between the table and the arrow.

\startuseMPgraphic{TableArrow}
  path p ; p := (3pt,0.9OverlayHeight){dir -50} .. {dir -130}(3pt,0.1OverlayHeight) ;
  drawarrow p ;
  label.rt("\im{\times} \$1.20/bottle", point 0.5 along p) ;
  setbounds currentpicture to unitsquare xyscaled (OverlayWidth,OverlayHeight) ;
\stopuseMPgraphic

\defineoverlay[TableArrow][\useMPgraphic{TableArrow}]

\starttext
  \bTABLE
  \setupTABLE[last][first][background=TableArrow]
  \setupTABLE[c][each][width=0.150\textwidth,align={middle,lohi},height=8ex]
  \setupTABLE[c][last][width=0dk]
  \bTABLEbody
  \bTR\bTD Number of Bottles \eTD
      \bTD $2$ \eTD
      \bTD $3$ \eTD
      \bTD $4$ \eTD
      \bTD $\cdots$ \eTD
      \bTD $x$ \eTD
      \bTD[nr=2]\eTD\eTR
  \bTR\bTD Price (\$)\eTD
      \bTD $2.40$ \eTD
      \bTD $3.60$ \eTD
      \bTD $4.80$ \eTD
      \bTD $\cdots$ \eTD
      \bTD $y$ \eTD\eTR
  \eTABLEbody
  \eTABLE
\stoptext

the resulting table

4
  • Perfect ! One last question. I tried to look at the documentation but I could not find a thing. Is there an easy way to change the label or should I create an overlay for each one?
    – user213111
    Commented Sep 18, 2022 at 11:17
  • I guess you can use some \MPvar or something similar. I would look in the MetaFun manual.
    – mickep
    Commented Sep 18, 2022 at 11:26
  • 0dk :-) I didn’t expect to see dk units in the wild
    – Aditya
    Commented Sep 19, 2022 at 16:00
  • 1
    It is in fact a convenient length. For making small examples, \startTEXpage[offset=1dk] has become standard for me. (But OK, the 0dk was perhaps not necessary.)
    – mickep
    Commented Sep 19, 2022 at 17:49

You must log in to answer this question.