Table and rotation: push together 45 degree rotated cells
Hi, I want to typeset a table where some of the column headings are really long, while in the columns itself consists only of numbers. Therefore, my idea was to rotate the column headings but not 90 degrees (I found some solutions for that) but 45 degree. It then would be beneficial to push together the rotated cells, so the text of one cell actually starts above the previous cell. Do you know, how to achieve that? Here is a minimal example: ``` \startsetups[table:rotated] \setupTABLE[frame=off] \setupTABLE[row][first][bottomframe=on, style=bf, align={center, low}] \setupTABLE[row][2][align=flushright] \stopsetups \starttext \define\tablerotate{\dontleavehmode\rotate[rotation=-45, location=high]} \bTABLE[setups=table:rotated] \bTR \bTD \eTD \bTD \tablerotate{Water buffalo} \eTD \bTD \tablerotate{Mexican redknee tarantula} \eTD \bTD \tablerotate{European turtle dove} \eTD \eTR \bTR \bTD Amount of legs \eTD \bTD \digits{4} \eTD \bTD \digits{8} \eTD \bTD \digits{2} \eTD \eTR \eTABLE \stoptext ``` I would like to achieve that the text "Mexican redknee tarantula" is typeset right and above of "Water buffalo" so that the single columns have a width that is similar to the width of the single digit coming in the second row. Another question in this context: Is is possible to specify a \setupTABLE command that works for column 2-4 starting from row 2? Something like \setupTABLE[row][2-][column][2,3,4][background=color, backgroundcolor=red]. In this example this would cover all numbers but nothing else. Best Gerion
Am Dienstag, 17. September 2024, 20:36:23 MESZ schrieb Gerion Entrup:
Hi,
I want to typeset a table where some of the column headings are really long, while in the columns itself consists only of numbers. Therefore, my idea was to rotate the column headings but not 90 degrees (I found some solutions for that) but 45 degree.
It then would be beneficial to push together the rotated cells, so the text of one cell actually starts above the previous cell. Do you know, how to achieve that?
Here is a minimal example: ``` \startsetups[table:rotated] \setupTABLE[frame=off] \setupTABLE[row][first][bottomframe=on, style=bf, align={center, low}] \setupTABLE[row][2][align=flushright] \stopsetups
\starttext \define\tablerotate{\dontleavehmode\rotate[rotation=-45, location=high]} \bTABLE[setups=table:rotated] \bTR \bTD \eTD \bTD \tablerotate{Water buffalo} \eTD \bTD \tablerotate{Mexican redknee tarantula} \eTD \bTD \tablerotate{European turtle dove} \eTD \eTR \bTR \bTD Amount of legs \eTD \bTD \digits{4} \eTD \bTD \digits{8} \eTD \bTD \digits{2} \eTD \eTR \eTABLE \stoptext ``` I would like to achieve that the text "Mexican redknee tarantula" is typeset right and above of "Water buffalo" so that the single columns have a width that is similar to the width of the single digit coming in the second row.
To visualize this, I patched the PDF of the above example to the desired result. See the attachment.
Another question in this context: Is is possible to specify a \setupTABLE command that works for column 2-4 starting from row 2? Something like \setupTABLE[row][2-][column][2,3,4][background=color, backgroundcolor=red]. In this example this would cover all numbers but nothing else.
Best Gerion
Gerion Entrup schrieb am 18.09.2024 um 14:44:
Am Dienstag, 17. September 2024, 20:36:23 MESZ schrieb Gerion Entrup:
Hi,
I want to typeset a table where some of the column headings are really long, while in the columns itself consists only of numbers. Therefore, my idea was to rotate the column headings but not 90 degrees (I found some solutions for that) but 45 degree.
It then would be beneficial to push together the rotated cells, so the text of one cell actually starts above the previous cell. Do you know, how to achieve that?
Here is a minimal example: ``` \startsetups[table:rotated] \setupTABLE[frame=off] \setupTABLE[row][first][bottomframe=on, style=bf, align={center, low}] \setupTABLE[row][2][align=flushright] \stopsetups
\starttext \define\tablerotate{\dontleavehmode\rotate[rotation=-45, location=high]} \bTABLE[setups=table:rotated] \bTR \bTD \eTD \bTD \tablerotate{Water buffalo} \eTD \bTD \tablerotate{Mexican redknee tarantula} \eTD \bTD \tablerotate{European turtle dove} \eTD \eTR \bTR \bTD Amount of legs \eTD \bTD \digits{4} \eTD \bTD \digits{8} \eTD \bTD \digits{2} \eTD \eTR \eTABLE \stoptext ``` I would like to achieve that the text "Mexican redknee tarantula" is typeset right and above of "Water buffalo" so that the single columns have a width that is similar to the width of the single digit coming in the second row.
To visualize this, I patched the PDF of the above example to the desired result. See the attachment.
You can use Metapost. \startuseMPgraphic{tableheader}{text,rotation} label.lft("\strut\bf\MPvar{text}",origin) rotated \MPvar{rotation} shifted (\the\strutht,0); setbounds currentpicture to unitsquare xyscaled(\the\struttotal,sin(\MPvar{rotation})*\the\widthofstring{\MPvar{text}}); \stopuseMPgraphic \starttext \bTABLE[frame=off] \bTR[align={middle,low}] \bTH \eTH \bTH[width=3em] \dontleavehmode\useMPgraphic{tableheader}{text=Water buffalo,rotation=315} \eTH \bTH[width=3em] \dontleavehmode\useMPgraphic{tableheader}{text=Mexican redknee tarantula,rotation=315} \eTH \bTH[width=3em] \dontleavehmode\useMPgraphic{tableheader}{text=European turtle dove,rotation=315} \eTH \eTR \bTR[topframe=on,align=middle] \bTD Amount of legs \eTD \bTD 4 \eTD \bTD 8 \eTD \bTD 2 \eTD \eTR \eTABLE \stoptext Wolfgang
On 9/18/2024 10:53 PM, Wolfgang Schuster wrote:
Gerion Entrup schrieb am 18.09.2024 um 14:44:
Am Dienstag, 17. September 2024, 20:36:23 MESZ schrieb Gerion Entrup:
Hi,
I want to typeset a table where some of the column headings are really long, while in the columns itself consists only of numbers. Therefore, my idea was to rotate the column headings but not 90 degrees (I found some solutions for that) but 45 degree.
It then would be beneficial to push together the rotated cells, so the text of one cell actually starts above the previous cell. Do you know, how to achieve that?
Here is a minimal example: ``` \startsetups[table:rotated] \setupTABLE[frame=off] \setupTABLE[row][first][bottomframe=on, style=bf, align={center, low}] \setupTABLE[row][2][align=flushright] \stopsetups
\starttext \define\tablerotate{\dontleavehmode\rotate[rotation=-45, location=high]} \bTABLE[setups=table:rotated] \bTR \bTD \eTD \bTD \tablerotate{Water buffalo} \eTD \bTD \tablerotate{Mexican redknee tarantula} \eTD \bTD \tablerotate{European turtle dove} \eTD \eTR \bTR \bTD Amount of legs \eTD \bTD \digits{4} \eTD \bTD \digits{8} \eTD \bTD \digits{2} \eTD \eTR \eTABLE \stoptext ``` I would like to achieve that the text "Mexican redknee tarantula" is typeset right and above of "Water buffalo" so that the single columns have a width that is similar to the width of the single digit coming in the second row.
To visualize this, I patched the PDF of the above example to the desired result. See the attachment.
You can use Metapost.
\startuseMPgraphic{tableheader}{text,rotation}
label.lft("\strut\bf\MPvar{text}",origin) rotated \MPvar{rotation} shifted (\the\strutht,0);
setbounds currentpicture to unitsquare
xyscaled(\the\struttotal,sin(\MPvar{rotation})*\the\widthofstring{\MPvar{text}});
\stopuseMPgraphic
\starttext
\bTABLE[frame=off] \bTR[align={middle,low}] \bTH \eTH \bTH[width=3em] \dontleavehmode\useMPgraphic{tableheader} {text=Water buffalo,rotation=315} \eTH \bTH[width=3em] \dontleavehmode\useMPgraphic{tableheader} {text=Mexican redknee tarantula,rotation=315} \eTH \bTH[width=3em] \dontleavehmode\useMPgraphic{tableheader} {text=European turtle dove,rotation=315} \eTH \eTR \bTR[topframe=on,align=middle] \bTD Amount of legs \eTD \bTD 4 \eTD \bTD 8 \eTD \bTD 2 \eTD \eTR \eTABLE
\stoptext
Neat. Added to the test suite. ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Am Mittwoch, 18. September 2024, 22:53:55 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 18.09.2024 um 14:44:
Am Dienstag, 17. September 2024, 20:36:23 MESZ schrieb Gerion Entrup:
Hi,
I want to typeset a table where some of the column headings are really long, while in the columns itself consists only of numbers. Therefore, my idea was to rotate the column headings but not 90 degrees (I found some solutions for that) but 45 degree.
It then would be beneficial to push together the rotated cells, so the text of one cell actually starts above the previous cell. Do you know, how to achieve that?
Here is a minimal example: ``` \startsetups[table:rotated] \setupTABLE[frame=off] \setupTABLE[row][first][bottomframe=on, style=bf, align={center, low}] \setupTABLE[row][2][align=flushright] \stopsetups
\starttext \define\tablerotate{\dontleavehmode\rotate[rotation=-45, location=high]} \bTABLE[setups=table:rotated] \bTR \bTD \eTD \bTD \tablerotate{Water buffalo} \eTD \bTD \tablerotate{Mexican redknee tarantula} \eTD \bTD \tablerotate{European turtle dove} \eTD \eTR \bTR \bTD Amount of legs \eTD \bTD \digits{4} \eTD \bTD \digits{8} \eTD \bTD \digits{2} \eTD \eTR \eTABLE \stoptext ``` I would like to achieve that the text "Mexican redknee tarantula" is typeset right and above of "Water buffalo" so that the single columns have a width that is similar to the width of the single digit coming in the second row.
To visualize this, I patched the PDF of the above example to the desired result. See the attachment.
You can use Metapost.
Thanks for this solution. It, however, seems to fail with any other angle than 315° (I tested 305, 325 and 314).
\startuseMPgraphic{tableheader}{text,rotation}
label.lft("\strut\bf\MPvar{text}",origin) rotated \MPvar{rotation} shifted (\the\strutht,0);
I guess, this one actually draws the text...
setbounds currentpicture to unitsquare
xyscaled(\the\struttotal,sin(\MPvar{rotation})*\the\widthofstring{\MPvar{text}});
and this one calculates the faked width. Doesn't the sinus here calculate the height of the rotated text? Beside from using Metapost (since I currently do not understand it and would only be able to copy paste your code), is there some kind of box construct which artificially reduces the width of the inner content? I would have expected something like \fakewidth[width=1cm, align=flushright]{\rotate[rotation=-45, location=high]{A really long text, much longer than 1cm}}. If I see it right, such a construct would also solve the problem, while less cleaner due to the fixed width. Gerion
Hi,
On Thu, Sep 19, 2024 at 12:23 AM Gerion Entrup
Am Mittwoch, 18. September 2024, 22:53:55 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 18.09.2024 um 14:44:
Am Dienstag, 17. September 2024, 20:36:23 MESZ schrieb Gerion Entrup:
Hi,
I want to typeset a table where some of the column headings are really long, while in the columns itself consists only of numbers. Therefore, my idea was to rotate the column headings but not 90 degrees (I found some solutions for that) but 45 degree.
It then would be beneficial to push together the rotated cells, so the text of one cell actually starts above the previous cell. Do you know, how to achieve that?
Here is a minimal example: ``` \startsetups[table:rotated] \setupTABLE[frame=off] \setupTABLE[row][first][bottomframe=on, style=bf, align={center, low}] \setupTABLE[row][2][align=flushright] \stopsetups
\starttext \define\tablerotate{\dontleavehmode\rotate[rotation=-45, location=high]} \bTABLE[setups=table:rotated] \bTR \bTD \eTD \bTD \tablerotate{Water buffalo} \eTD \bTD \tablerotate{Mexican redknee tarantula} \eTD \bTD \tablerotate{European turtle dove} \eTD \eTR \bTR \bTD Amount of legs \eTD \bTD \digits{4} \eTD \bTD \digits{8} \eTD \bTD \digits{2} \eTD \eTR \eTABLE \stoptext ``` I would like to achieve that the text "Mexican redknee tarantula" is typeset right and above of "Water buffalo" so that the single columns have a width that is similar to the width of the single digit coming in the second row.
To visualize this, I patched the PDF of the above example to the desired result. See the attachment.
You can use Metapost.
Thanks for this solution. It, however, seems to fail with any other angle than 315° (I tested 305, 325 and 314).
Try xyscaled(\the\struttotal,abs(sind(\MPvar{rotation}))*\the\widthofstring{\MPvar{text}}); with sind instead of sin. And maybe with abs around it, but one can think of improvements for smaller angles. It all depends on what one wants. /Mikael
On 9/19/2024 7:54 AM, Mikael Sundqvist wrote:
Hi,
On Thu, Sep 19, 2024 at 12:23 AM Gerion Entrup
wrote: Am Mittwoch, 18. September 2024, 22:53:55 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 18.09.2024 um 14:44:
Am Dienstag, 17. September 2024, 20:36:23 MESZ schrieb Gerion Entrup:
Hi,
I want to typeset a table where some of the column headings are really long, while in the columns itself consists only of numbers. Therefore, my idea was to rotate the column headings but not 90 degrees (I found some solutions for that) but 45 degree.
It then would be beneficial to push together the rotated cells, so the text of one cell actually starts above the previous cell. Do you know, how to achieve that?
Here is a minimal example: ``` \startsetups[table:rotated] \setupTABLE[frame=off] \setupTABLE[row][first][bottomframe=on, style=bf, align={center, low}] \setupTABLE[row][2][align=flushright] \stopsetups
\starttext \define\tablerotate{\dontleavehmode\rotate[rotation=-45, location=high]} \bTABLE[setups=table:rotated] \bTR \bTD \eTD \bTD \tablerotate{Water buffalo} \eTD \bTD \tablerotate{Mexican redknee tarantula} \eTD \bTD \tablerotate{European turtle dove} \eTD \eTR \bTR \bTD Amount of legs \eTD \bTD \digits{4} \eTD \bTD \digits{8} \eTD \bTD \digits{2} \eTD \eTR \eTABLE \stoptext ``` I would like to achieve that the text "Mexican redknee tarantula" is typeset right and above of "Water buffalo" so that the single columns have a width that is similar to the width of the single digit coming in the second row.
To visualize this, I patched the PDF of the above example to the desired result. See the attachment.
You can use Metapost.
Thanks for this solution. It, however, seems to fail with any other angle than 315° (I tested 305, 325 and 314).
Try
xyscaled(\the\struttotal,abs(sind(\MPvar{rotation}))*\the\widthofstring{\MPvar{text}});
with sind instead of sin. And maybe with abs around it, but one can think of improvements for smaller angles. It all depends on what one wants.
here is an alternative \bTABLE[frame=off] \bTR[align={middle,low}] \bTH \eTH \bTH \dontleavehmode\kern1.5em\llap{\rotate[rotation=315,frame=on]{\strut Water buffalo}\hss} \eTH \bTH \dontleavehmode\kern1.5em\llap{\rotate[rotation=315,frame=on]{\strut Mexican redknee tarantula}\hss} \eTH \bTH \dontleavehmode\kern1.5em\llap{\rotate[rotation=315,frame=on]{\strut European turtle dove}\hss} \eTH \eTR \bTR[frame=on,align=middle] \bTD Amount of legs \eTD \bTD[width=3em] 4 \eTD \bTD[width=3em] 8 \eTD \bTD[width=3em] 2 \eTD \eTR \eTABLE and yes, i needed to trial and error a bit, Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Am Donnerstag, 19. September 2024, 09:35:49 MESZ schrieb Hans Hagen via ntg-context:
On 9/19/2024 7:54 AM, Mikael Sundqvist wrote:
Hi,
On Thu, Sep 19, 2024 at 12:23 AM Gerion Entrup
wrote: Am Mittwoch, 18. September 2024, 22:53:55 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 18.09.2024 um 14:44:
Am Dienstag, 17. September 2024, 20:36:23 MESZ schrieb Gerion Entrup:
Hi,
I want to typeset a table where some of the column headings are really long, while in the columns itself consists only of numbers. Therefore, my idea was to rotate the column headings but not 90 degrees (I found some solutions for that) but 45 degree.
It then would be beneficial to push together the rotated cells, so the text of one cell actually starts above the previous cell. Do you know, how to achieve that?
Here is a minimal example: ``` \startsetups[table:rotated] \setupTABLE[frame=off] \setupTABLE[row][first][bottomframe=on, style=bf, align={center, low}] \setupTABLE[row][2][align=flushright] \stopsetups
\starttext \define\tablerotate{\dontleavehmode\rotate[rotation=-45, location=high]} \bTABLE[setups=table:rotated] \bTR \bTD \eTD \bTD \tablerotate{Water buffalo} \eTD \bTD \tablerotate{Mexican redknee tarantula} \eTD \bTD \tablerotate{European turtle dove} \eTD \eTR \bTR \bTD Amount of legs \eTD \bTD \digits{4} \eTD \bTD \digits{8} \eTD \bTD \digits{2} \eTD \eTR \eTABLE \stoptext ``` I would like to achieve that the text "Mexican redknee tarantula" is typeset right and above of "Water buffalo" so that the single columns have a width that is similar to the width of the single digit coming in the second row.
To visualize this, I patched the PDF of the above example to the desired result. See the attachment.
You can use Metapost.
Thanks for this solution. It, however, seems to fail with any other angle than 315° (I tested 305, 325 and 314).
Try
xyscaled(\the\struttotal,abs(sind(\MPvar{rotation}))*\the\widthofstring{\MPvar{text}});
with sind instead of sin. And maybe with abs around it, but one can think of improvements for smaller angles. It all depends on what one wants.
here is an alternative
\bTABLE[frame=off] \bTR[align={middle,low}] \bTH \eTH \bTH \dontleavehmode\kern1.5em\llap{\rotate[rotation=315,frame=on]{\strut Water buffalo}\hss} \eTH \bTH \dontleavehmode\kern1.5em\llap{\rotate[rotation=315,frame=on]{\strut Mexican redknee tarantula}\hss} \eTH \bTH \dontleavehmode\kern1.5em\llap{\rotate[rotation=315,frame=on]{\strut European turtle dove}\hss} \eTH \eTR \bTR[frame=on,align=middle] \bTD Amount of legs \eTD \bTD[width=3em] 4 \eTD \bTD[width=3em] 8 \eTD \bTD[width=3em] 2 \eTD \eTR \eTABLE
What is the meaning of \hss here? It seems to work just fine without it. Gerion
On 9/19/2024 1:03 PM, Gerion Entrup wrote:
What is the meaning of \hss here? It seems to work just fine without it.
a left over from trial and error ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Am Donnerstag, 19. September 2024, 16:44:31 MESZ schrieb Hans Hagen:
On 9/19/2024 1:03 PM, Gerion Entrup wrote:
What is the meaning of \hss here? It seems to work just fine without it.
a left over from trial and error
Thank you all! I have documented both solutions in the Wiki (https://wiki.contextgarden.net/TABLE#Rotated_headline). Gerion
participants (5)
-
Gerion Entrup
-
Hans Hagen
-
Hans Hagen
-
Mikael Sundqvist
-
Wolfgang Schuster