Re: [NTG-context] Stretching width in natural TABLEs

2012-09-04 Thread Procházka Lukáš Ing . - Pontex s . r . o .

Hello,

On Tue, 04 Sep 2012 05:02:01 +0200, Rogers, Michael K mrog...@emory.edu wrote:


That's what I was afraid.  It's just I had the same problem last week, and a 
deadline made me settle for the ad hoc approach.


I was trying to solve the same situation several week ago.

Finally, I measured what the fit option of the first column mean in real 
units (cm) and I altered widths of remaining columns to get \textwidth in total, which is 
ugly and non-systematic solution.

So it seems that there is a task for natural TABLEs:


Suppose one or more columns have fit width, so the width is computed at 
run-time.
Suppose the total width of the table is defined, too.
How to specify width of other columns to have a specified ratio?


E.g.:

col1.width=fit - will be a concrete value at run-time, 'col1.width.real'
col2.width=fit - will be a concrete value at run-time, 'col2.width.real'
TABLE.tot.width=\textwidth
col3.width.weight=1
col4.width.weight=2

should give

col3.width =
  (TABLE.tot.width - col1.width.real - col2.width.real) / (col3.width.weight + 
col4.width.weight) * col3.width.weight

col4.width =
  (TABLE.tot.width - col1.width.real - col2.width.real) / (col3.width.weight + 
col4.width.weight) * col4.width.weight

Best regards,

Lukas


--
Ing. Lukáš Procházka [mailto:l...@pontex.cz]
Pontex s. r. o.  [mailto:pon...@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Stretching width in natural TABLEs

2012-09-03 Thread Michael Rogers
If you know the width of the first column and total width, then you can use 
arithmetic, as in the example below.  But perhaps this already occurred to you, 
and you were wondering if the widths and stretching can be handled 
automatically -- the short answer is I don't know.

\starttext
\setupTABLE[c][1][width={2cm}]
\setupTABLE[c][2][width={\dimexpr(\textwidth-2cm)/3\relax}]
\setupTABLE[c][3][width={\dimexpr(\textwidth-2cm)* 2 / 3\relax}]
\startTABLE
\NC One \NC Two \NC Three \NC\NR
\NC A \NC B \NC C \NC\NR
\stopTABLE
\stoptext


On Sep 2, 2012, at 12:24 PM, Aditya Mahajan wrote:

 Hi,
 
 Is it possible to stretch the widths of each column in natural TABLEs, so 
 that the widths are in a certain propotion? For example, suppose I have a 
 table with three columns and I want to set the width of the first column to a 
 fixed amount, and split the remaining space between columns two and three in 
 a 1:2 ratio.
 
 Extreme tables implement something similar using option={stretch, width}, but 
 AFAIU, it is not possible to fix the width of a particular column.
 
 Aditya
 ___
 If your question is of interest to others as well, please add an entry to the 
 Wiki!
 
 maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
 webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
 archive  : http://foundry.supelec.fr/projects/contextrev/
 wiki : http://contextgarden.net
 ___

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Stretching width in natural TABLEs

2012-09-03 Thread Aditya Mahajan

On Mon, 3 Sep 2012, Michael Rogers wrote:


On Sep 2, 2012, at 12:24 PM, Aditya Mahajan wrote:

Is it possible to stretch the widths of each column in natural TABLEs, 
so that the widths are in a certain propotion? For example, suppose I 
have a table with three columns and I want to set the width of the 
first column to a fixed amount, and split the remaining space between 
columns two and three in a 1:2 ratio.





If you know the width of the first column and total width, then you can use 
arithmetic, as in the example below.  But perhaps this already occurred to you, 
and you were wondering if the widths and stretching can be handled 
automatically -- the short answer is I don't know.

\starttext
\setupTABLE[c][1][width={2cm}]
\setupTABLE[c][2][width={\dimexpr(\textwidth-2cm)/3\relax}]
\setupTABLE[c][3][width={\dimexpr(\textwidth-2cm)* 2 / 3\relax}]
\startTABLE
\NC One \NC Two \NC Three \NC\NR
\NC A \NC B \NC C \NC\NR
\stopTABLE
\stoptext


Apart from being hard to maintain, this works well if I know the width of 
a cell in advance. But most of the time I want something the width of the 
fixed column to be determined using width=fit option, so I cannot 
precompute the width of other columns.


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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Stretching width in natural TABLEs

2012-09-03 Thread Aditya Mahajan

On Sun, 2 Sep 2012, Aditya Mahajan wrote:


Hi,

Is it possible to stretch the widths of each column in natural TABLEs, so 
that the widths are in a certain propotion? For example, suppose I have a 
table with three columns and I want to set the width of the first column to a 
fixed amount, and split the remaining space between columns two and three in 
a 1:2 ratio.


Extreme tables implement something similar using option={stretch, width}, but 
AFAIU, it is not possible to fix the width of a particular column.


I notice that

\setupTABLE[c][1][width=fit]
\setupTABLE[c][2][width=broad]
\setupTABLE[c][3][width=broad]

splits the remaining space equally between columns 2 and 3.

So, after starting at the code of pack-rul for a while, I realized that

\setupTABLE[c][1][width=fit]
\setupTABLE[c][2][width=0.33\hsize]
\setupTABLE[c][3][width=0.66\hsize]

should work and it does!

Now if someone could explain WHY it works, I'll be enlightened.

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Stretching width in natural TABLEs

2012-09-03 Thread Rogers, Michael K

On Sep 3, 2012, at 9:39 PM, Aditya Mahajan wrote:

 On Mon, 3 Sep 2012, Michael Rogers wrote:

 On Sep 2, 2012, at 12:24 PM, Aditya Mahajan wrote:

 Is it possible to stretch the widths of each column in natural TABLEs, so 
 that the widths are in a certain propotion? For example, suppose I have a 
 table with three columns and I want to set the width of the first column to 
 a fixed amount, and split the remaining space between columns two and three 
 in a 1:2 ratio.


 If you know the width of the first column and total width, then you can use 
 arithmetic, as in the example below.  But perhaps this already occurred to 
 you, and you were wondering if the widths and stretching can be handled 
 automatically -- the short answer is I don't know.

 \starttext
 \setupTABLE[c][1][width={2cm}]
 \setupTABLE[c][2][width={\dimexpr(\textwidth-2cm)/3\relax}]
 \setupTABLE[c][3][width={\dimexpr(\textwidth-2cm)* 2 / 3\relax}]
 \startTABLE
 \NC One \NC Two \NC Three \NC\NR
 \NC A \NC B \NC C \NC\NR
 \stopTABLE
 \stoptext

 Apart from being hard to maintain, this works well if I know the width of a 
 cell in advance. But most of the time I want something the width of the fixed 
 column to be determined using width=fit option, so I cannot precompute the 
 width of other columns.

 Aditya

That's what I was afraid.  It's just I had the same problem last week, and a 
deadline made me settle for the ad hoc approach.  You made me curious enough to 
go look at the source, and one can hack it to work.  See below, if interested.  
Not optimal, and might break in future.

By the way, what you posted in your other message,

 \setupTABLE[c][1][width=fit]
 \setupTABLE[c][2][width=0.33\hsize]
 \setupTABLE[c][3][width=0.66\hsize]

extends into the right margin by the width of the first column or thereabouts, 
for me.

Michael

The hack:

\unprotect
% adapted from \tabl_ntb_stretch_widths, tabl-ntb.mkiv, ll. 1296f
\def\tabl_ntb_mystretch_widths % more variants, e.g. a max to \dimend
  {\ifcase\c_tabl_ntb_maximum_col\else % else division by zero
 \!!dimend\zeropoint
 \!!dimene\hsize
 \dorecurse\c_tabl_ntb_maximum_col
   
{\advance\!!dimend\dimexpr\tabl_ntb_get_wid\recurselevel+\naturaltablelocalparameter\c!columndistance\relax
\advance\!!dimene-\tabl_ntb_get_dis\recurselevel}%
 
\advance\!!dimend\dimexpr-\naturaltablelocalparameter\c!columndistance+\naturaltablelocalparameter\c!leftmargindistance+\naturaltablelocalparameter\c!rightmargindistance\relax
 % distribute width (stretch)
 \ifdim\!!dimend\!!dimene
   \advance\!!dimend-\!!dimene
   \!!dimend-\!!dimend
%  \divide\!!dimend\c_tabl_ntb_maximum_col
%   \dorecurse\c_tabl_ntb_maximum_col
% 
{\tabl_ntb_set_wid\recurselevel{\the\dimexpr\tabl_ntb_get_wid\recurselevel+\!!dimend\relax}}%
   \divide\!!dimend3  %%% divide remainder into three equal parts
   {\tabl_ntb_set_wid2{\the\dimexpr\tabl_ntb_get_wid2+\!!dimend\relax}}%%% 
add one part to 2nd column
   {\tabl_ntb_set_wid3{\the\dimexpr\tabl_ntb_get_wid3+\!!dimend * 
2\relax}}%%% add two parts to 3rd column
 \fi
   \fi}
\def\usemystretch{\let\tabl_ntb_stretch_widths\tabl_ntb_mystretch_widths}
\protect

\starttext
\startsetups mystretch
   \usemystretch
   \setupTABLE[option=stretch]
\stopsetups
\startTABLE[setups=mystretch]
\NC One \NC Two \NC Three \NC\NR
\NC A \NC B \NC C \NC\NR
\stopTABLE
\stoptext

BTW, the above could be adapted to a key of the form stretch={n1,n2,...} (e.g. 
stretch={0,1,2}) which would divide the remaining proportionally.  Maybe not 
worth doing, though...maybe harder than I think -- the table stuff is 
complicated, and I'm assuming that since it worked once, I haven't messed 
anything up.



This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Stretching width in natural TABLEs

2012-09-03 Thread Aditya Mahajan

On Tue, 4 Sep 2012, Rogers, Michael K wrote:



On Sep 3, 2012, at 9:39 PM, Aditya Mahajan wrote:


On Mon, 3 Sep 2012, Michael Rogers wrote:


On Sep 2, 2012, at 12:24 PM, Aditya Mahajan wrote:


Is it possible to stretch the widths of each column in natural TABLEs, so that 
the widths are in a certain propotion? For example, suppose I have a table with 
three columns and I want to set the width of the first column to a fixed 
amount, and split the remaining space between columns two and three in a 1:2 
ratio.




If you know the width of the first column and total width, then you can use 
arithmetic, as in the example below.  But perhaps this already occurred to you, 
and you were wondering if the widths and stretching can be handled 
automatically -- the short answer is I don't know.

\starttext
\setupTABLE[c][1][width={2cm}]
\setupTABLE[c][2][width={\dimexpr(\textwidth-2cm)/3\relax}]
\setupTABLE[c][3][width={\dimexpr(\textwidth-2cm)* 2 / 3\relax}]
\startTABLE
\NC One \NC Two \NC Three \NC\NR
\NC A \NC B \NC C \NC\NR
\stopTABLE
\stoptext


Apart from being hard to maintain, this works well if I know the width of a 
cell in advance. But most of the time I want something the width of the fixed 
column to be determined using width=fit option, so I cannot precompute the 
width of other columns.

Aditya


That's what I was afraid.  It's just I had the same problem last week, and a 
deadline made me settle for the ad hoc approach.  You made me curious enough to 
go look at the source, and one can hack it to work.  See below, if interested.  
Not optimal, and might break in future.

By the way, what you posted in your other message,


\setupTABLE[c][1][width=fit]
\setupTABLE[c][2][width=0.33\hsize]
\setupTABLE[c][3][width=0.66\hsize]


extends into the right margin by the width of the first column or thereabouts, 
for me.


Ah, thats makes more sense. I was so happy to see the right ratio of the 
widths, that I did not notice that.



The hack:


Thanks. I'll play around with it tomorrow.

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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] Stretching width in natural TABLEs

2012-09-02 Thread Aditya Mahajan

Hi,

Is it possible to stretch the widths of each column in natural TABLEs, so 
that the widths are in a certain propotion? For example, suppose I have a 
table with three columns and I want to set the width of the first column 
to a fixed amount, and split the remaining space between columns two and 
three in a 1:2 ratio.


Extreme tables implement something similar using option={stretch, width}, 
but AFAIU, it is not possible to fix the width of a particular column.


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

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___