ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Question about matrices with vertical and horizontal lines
@ 2025-02-27  2:16 Matthias Weber
  2025-02-27 11:09 ` [NTG-context] " Mikael Sundqvist
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Weber @ 2025-02-27  2:16 UTC (permalink / raw)
  To: ntg-context

Hi, 

I’d like to typeset a matrix with vertical and horizontal lines like so:

starttext 

\startformula
\startmatrix
   \HL
   \VL 16 \VL 3  \VL  2 \VL  12 \VL\NR
   \HL
   \VL 5 \VL 10 \VL 11 \VL 8  \VL\NR
   \HL
   \VL 9 \VL 6 \VL 7 \VL 12 \VL\NR
   \HL
   \VL 4 \VL 15 \VL 14 \VL 1 \VL\NR
   \HL
\stopmatrix 
\stopformula
  

\starttable[|c|c|c|c|]
\HL
 \VL $16$ \VL $3$ \VL $2$ \VL $12$ \VL \FR
\HL
\VL $5$ \VL $10$ \VL $11$ \VL $8$\VL \SR
\HL
\VL $9$ \VL $6$ \VL $7$\VL $12$ \VL\SR
\HL
\VL $4$ \VL $15$ \VL $14$ \VL  $1$ \VL\SR
\HL
\stoptable

\stoptext

In the matrix version, the horizontal lines extend too far to the left. 

Ideally, I would like the cells to be squares, with the entries centered.

Thanks for any suggestions!

Matthias


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: Question about matrices with vertical and horizontal lines
  2025-02-27  2:16 [NTG-context] Question about matrices with vertical and horizontal lines Matthias Weber
@ 2025-02-27 11:09 ` Mikael Sundqvist
  2025-02-27 20:03   ` [NTG-context] Re: Question about matrices with vertical and horizontal lines (and now adding arrows between cells) Matthias Weber
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Sundqvist @ 2025-02-27 11:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

On Thu, Feb 27, 2025 at 3:18 AM Matthias Weber
<matthiasweber64@gmail.com> wrote:
>
> Hi,
>
> I’d like to typeset a matrix with vertical and horizontal lines like so:
>
> starttext
>
> \startformula
> \startmatrix
>    \HL
>    \VL 16 \VL 3  \VL  2 \VL  12 \VL\NR
>    \HL
>    \VL 5 \VL 10 \VL 11 \VL 8  \VL\NR
>    \HL
>    \VL 9 \VL 6 \VL 7 \VL 12 \VL\NR
>    \HL
>    \VL 4 \VL 15 \VL 14 \VL 1 \VL\NR
>    \HL
> \stopmatrix
> \stopformula
>
>
> \starttable[|c|c|c|c|]
> \HL
>  \VL $16$ \VL $3$ \VL $2$ \VL $12$ \VL \FR
> \HL
> \VL $5$ \VL $10$ \VL $11$ \VL $8$\VL \SR
> \HL
> \VL $9$ \VL $6$ \VL $7$\VL $12$ \VL\SR
> \HL
> \VL $4$ \VL $15$ \VL $14$ \VL  $1$ \VL\SR
> \HL
> \stoptable
>
> \stoptext
>
> In the matrix version, the horizontal lines extend too far to the left.
>
> Ideally, I would like the cells to be squares, with the entries centered.
>
> Thanks for any suggestions!
>
> Matthias

You can try \VC instead of \VL for the first column. Also, square
cells might be easiest(?) to get with natural tables.

\starttext

\startformula
  x +
\startmatrix
   \HL
   \VC 16 \VL  3 \VL  2 \VL 12 \VL\NR
   \HL
   \VC  5 \VL 10 \VL 11 \VL  8 \VL\NR
   \HL
   \VC  9 \VL  6 \VL  7 \VL 12 \VL\NR
   \HL
   \VC  4 \VL 15 \VL 14 \VL  1 \VL\NR
   \HL
\stopmatrix
  + y
\stopformula

\setupTABLE[c][width=1cm,offset=overlay,align={middle,lohi}]
\setupTABLE[r][height=1cm]
\bTABLE
   \bTR \bTD 16 \eTD  \bTD  3 \eTD \bTD  2 \eTD \bTD 12 \eTD \eTR
   \bTR \bTD  5 \eTD  \bTD 10 \eTD \bTD 11 \eTD \bTD  8 \eTD \eTR
   \bTR \bTD  9 \eTD  \bTD  6 \eTD \bTD  7 \eTD \bTD 12 \eTD \eTR
   \bTR \bTD  4 \eTD  \bTD 15 \eTD \bTD 14 \eTD \bTD  1 \eTD \eTR
\eTABLE

\stoptext

/Mikael
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: Question about matrices with vertical and horizontal lines (and now adding arrows between cells)
  2025-02-27 11:09 ` [NTG-context] " Mikael Sundqvist
@ 2025-02-27 20:03   ` Matthias Weber
  2025-02-27 20:52     ` Mikael Sundqvist
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Weber @ 2025-02-27 20:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Thanks!

Now, I would like to have arrows between cells. I have tried using overlays (see below), and I understand that an overlay is centered within the cell. How do I move the arrow so that it points from 6 to 7, for instance?
(Starting a little to the right and above the 6, ending below and to the left of the 7)

Matthias



\starttext
\startuseMPgraphic{DiagonalArrow}
  numeric w, h;
  w := OverlayWidth ;
  h := OverlayHeight ;
	draw lmt_arrow [ path =((.5*w,.5*w) -- (2*w,2*w)), ]
    withpen pencircle
    scaled (h/40)
    withcolor "darkgreen" ;
\stopuseMPgraphic

\defineoverlay
  [DiagonalArrow]
  [\useMPgraphic{DiagonalArrow}]
  
  
\setupTABLE[c][width=1cm,offset=overlay,align={middle,lohi}]
\setupTABLE[r][height=1cm]
\bTABLE
  \bTR \bTD 17 \eTD  \bTD  24 \eTD \bTD   1 \eTD \bTD  8\eTD \bTD  15 \eTD \eTR
   \bTR \bTD 23 \eTD  \bTD  5 \eTD \bTD  7 \eTD \bTD  14\eTD \bTD  16 \eTD \eTR
    \bTR \bTD 4 \eTD  \bTD  [background=DiagonalArrow] 6 \eTD \bTD  13 \eTD \bTD 20\eTD \bTD 22 \eTD \eTR
     \bTR \bTD 10 \eTD  \bTD  12 \eTD \bTD 19 \eTD \bTD 21\eTD \bTD 3 \eTD \eTR
   \bTR \bTD 11 \eTD  \bTD  18 \eTD \bTD 25 \eTD \bTD  2\eTD \bTD 9 \eTD \eTR
\eTABLE
\stopExample

\stoptext

> On Feb 27, 2025, at 6:09 AM, Mikael Sundqvist <mickep@gmail.com> wrote:
> 
> Hi,
> 
> On Thu, Feb 27, 2025 at 3:18 AM Matthias Weber
> <matthiasweber64@gmail.com> wrote:
>> 
>> Hi,
>> 
>> I’d like to typeset a matrix with vertical and horizontal lines like so:
>> 
>> starttext
>> 
>> \startformula
>> \startmatrix
>>   \HL
>>   \VL 16 \VL 3  \VL  2 \VL  12 \VL\NR
>>   \HL
>>   \VL 5 \VL 10 \VL 11 \VL 8  \VL\NR
>>   \HL
>>   \VL 9 \VL 6 \VL 7 \VL 12 \VL\NR
>>   \HL
>>   \VL 4 \VL 15 \VL 14 \VL 1 \VL\NR
>>   \HL
>> \stopmatrix
>> \stopformula
>> 
>> 
>> \starttable[|c|c|c|c|]
>> \HL
>> \VL $16$ \VL $3$ \VL $2$ \VL $12$ \VL \FR
>> \HL
>> \VL $5$ \VL $10$ \VL $11$ \VL $8$\VL \SR
>> \HL
>> \VL $9$ \VL $6$ \VL $7$\VL $12$ \VL\SR
>> \HL
>> \VL $4$ \VL $15$ \VL $14$ \VL  $1$ \VL\SR
>> \HL
>> \stoptable
>> 
>> \stoptext
>> 
>> In the matrix version, the horizontal lines extend too far to the left.
>> 
>> Ideally, I would like the cells to be squares, with the entries centered.
>> 
>> Thanks for any suggestions!
>> 
>> Matthias
> 
> You can try \VC instead of \VL for the first column. Also, square
> cells might be easiest(?) to get with natural tables.
> 
> \starttext
> 
> \startformula
>  x +
> \startmatrix
>   \HL
>   \VC 16 \VL  3 \VL  2 \VL 12 \VL\NR
>   \HL
>   \VC  5 \VL 10 \VL 11 \VL  8 \VL\NR
>   \HL
>   \VC  9 \VL  6 \VL  7 \VL 12 \VL\NR
>   \HL
>   \VC  4 \VL 15 \VL 14 \VL  1 \VL\NR
>   \HL
> \stopmatrix
>  + y
> \stopformula
> 
> \setupTABLE[c][width=1cm,offset=overlay,align={middle,lohi}]
> \setupTABLE[r][height=1cm]
> \bTABLE
>   \bTR \bTD 16 \eTD  \bTD  3 \eTD \bTD  2 \eTD \bTD 12 \eTD \eTR
>   \bTR \bTD  5 \eTD  \bTD 10 \eTD \bTD 11 \eTD \bTD  8 \eTD \eTR
>   \bTR \bTD  9 \eTD  \bTD  6 \eTD \bTD  7 \eTD \bTD 12 \eTD \eTR
>   \bTR \bTD  4 \eTD  \bTD 15 \eTD \bTD 14 \eTD \bTD  1 \eTD \eTR
> \eTABLE
> 
> \stoptext
> 
> /Mikael
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive  : https://github.com/contextgarden/context
> wiki     : https://wiki.contextgarden.net
> ___________________________________________________________________________________

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: Question about matrices with vertical and horizontal lines (and now adding arrows between cells)
  2025-02-27 20:03   ` [NTG-context] Re: Question about matrices with vertical and horizontal lines (and now adding arrows between cells) Matthias Weber
@ 2025-02-27 20:52     ` Mikael Sundqvist
  2025-02-27 21:14       ` Matthias Weber
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Sundqvist @ 2025-02-27 20:52 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

On Thu, Feb 27, 2025 at 9:04 PM Matthias Weber
<matthiasweber64@gmail.com> wrote:
>
> Thanks!
>
> Now, I would like to have arrows between cells. I have tried using overlays (see below), and I understand that an overlay is centered within the cell. How do I move the arrow so that it points from 6 to 7, for instance?
> (Starting a little to the right and above the 6, ending below and to the left of the 7)
>
> Matthias
>
>
>
> \starttext
> \startuseMPgraphic{DiagonalArrow}
>   numeric w, h;
>   w := OverlayWidth ;
>   h := OverlayHeight ;
>         draw lmt_arrow [ path =((.5*w,.5*w) -- (2*w,2*w)), ]
>     withpen pencircle
>     scaled (h/40)
>     withcolor "darkgreen" ;
> \stopuseMPgraphic
>
> \defineoverlay
>   [DiagonalArrow]
>   [\useMPgraphic{DiagonalArrow}]
>
>
> \setupTABLE[c][width=1cm,offset=overlay,align={middle,lohi}]
> \setupTABLE[r][height=1cm]
> \bTABLE
>   \bTR \bTD 17 \eTD  \bTD  24 \eTD \bTD   1 \eTD \bTD  8\eTD \bTD  15 \eTD \eTR
>    \bTR \bTD 23 \eTD  \bTD  5 \eTD \bTD  7 \eTD \bTD  14\eTD \bTD  16 \eTD \eTR
>     \bTR \bTD 4 \eTD  \bTD  [background=DiagonalArrow] 6 \eTD \bTD  13 \eTD \bTD 20\eTD \bTD 22 \eTD \eTR
>      \bTR \bTD 10 \eTD  \bTD  12 \eTD \bTD 19 \eTD \bTD 21\eTD \bTD 3 \eTD \eTR
>    \bTR \bTD 11 \eTD  \bTD  18 \eTD \bTD 25 \eTD \bTD  2\eTD \bTD 9 \eTD \eTR
> \eTABLE
> \stopExample
>
> \stoptext
>

Maybe https://www.pragma-ade.com/general/manuals/metafun-p.pdf,
section 5, Positional graphics, is what you look for?

/Mikael
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [NTG-context] Re: Question about matrices with vertical and horizontal lines (and now adding arrows between cells)
  2025-02-27 20:52     ` Mikael Sundqvist
@ 2025-02-27 21:14       ` Matthias Weber
  0 siblings, 0 replies; 5+ messages in thread
From: Matthias Weber @ 2025-02-27 21:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Thanks again. This is exquisite, truly.

One of the many things I like about using ConTeXt is that whenever I try to do something new, I learn amazing things I didn’t even know were possible.

Matthias


> On Feb 27, 2025, at 3:52 PM, Mikael Sundqvist <mickep@gmail.com> wrote:
> 
> Hi,
> 
> On Thu, Feb 27, 2025 at 9:04 PM Matthias Weber
> <matthiasweber64@gmail.com> wrote:
>> 
>> Thanks!
>> 
>> Now, I would like to have arrows between cells. I have tried using overlays (see below), and I understand that an overlay is centered within the cell. How do I move the arrow so that it points from 6 to 7, for instance?
>> (Starting a little to the right and above the 6, ending below and to the left of the 7)
>> 
>> Matthias
>> 
>> 
>> 
>> \starttext
>> \startuseMPgraphic{DiagonalArrow}
>>  numeric w, h;
>>  w := OverlayWidth ;
>>  h := OverlayHeight ;
>>        draw lmt_arrow [ path =((.5*w,.5*w) -- (2*w,2*w)), ]
>>    withpen pencircle
>>    scaled (h/40)
>>    withcolor "darkgreen" ;
>> \stopuseMPgraphic
>> 
>> \defineoverlay
>>  [DiagonalArrow]
>>  [\useMPgraphic{DiagonalArrow}]
>> 
>> 
>> \setupTABLE[c][width=1cm,offset=overlay,align={middle,lohi}]
>> \setupTABLE[r][height=1cm]
>> \bTABLE
>>  \bTR \bTD 17 \eTD  \bTD  24 \eTD \bTD   1 \eTD \bTD  8\eTD \bTD  15 \eTD \eTR
>>   \bTR \bTD 23 \eTD  \bTD  5 \eTD \bTD  7 \eTD \bTD  14\eTD \bTD  16 \eTD \eTR
>>    \bTR \bTD 4 \eTD  \bTD  [background=DiagonalArrow] 6 \eTD \bTD  13 \eTD \bTD 20\eTD \bTD 22 \eTD \eTR
>>     \bTR \bTD 10 \eTD  \bTD  12 \eTD \bTD 19 \eTD \bTD 21\eTD \bTD 3 \eTD \eTR
>>   \bTR \bTD 11 \eTD  \bTD  18 \eTD \bTD 25 \eTD \bTD  2\eTD \bTD 9 \eTD \eTR
>> \eTABLE
>> \stopExample
>> 
>> \stoptext
>> 
> 
> Maybe https://www.pragma-ade.com/general/manuals/metafun-p.pdf,
> section 5, Positional graphics, is what you look for?
> 
> /Mikael
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive  : https://github.com/contextgarden/context
> wiki     : https://wiki.contextgarden.net
> ___________________________________________________________________________________

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-02-27 21:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-27  2:16 [NTG-context] Question about matrices with vertical and horizontal lines Matthias Weber
2025-02-27 11:09 ` [NTG-context] " Mikael Sundqvist
2025-02-27 20:03   ` [NTG-context] Re: Question about matrices with vertical and horizontal lines (and now adding arrows between cells) Matthias Weber
2025-02-27 20:52     ` Mikael Sundqvist
2025-02-27 21:14       ` Matthias Weber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).