ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Vit Zyka <vit.zyka@seznam.cz>
Subject: Re: Problems with Natural Tables
Date: Sun, 06 Nov 2005 11:55:18 +0100	[thread overview]
Message-ID: <436DE116.6090806@seznam.cz> (raw)
In-Reply-To: <435DFD5F.3040607@seznam.cz>

Vit Zyka wrote:
 > ...
> so please, is the file 'core-ntb-new.tex' somewhere available?

Solution of my own question, for who is interesting.

Description:
The next patch enables to define intercolumn gaps in Natural Table 
(bTABLE...eTABLE) environment.

Features:
- one can distinguish the amounts of first (colsepfirst), inner 
(colsepbetween), and last (colseplast) gaps.
- patch operates for both 'fit' or 'stretch' table options.
- gaps has no 'background' you have to use external one.

Example:
http://typokvitek.com/tmp/nattab-colskip.pdf

Usage:
\bTABLE[colsepbetween=2cm,colsepfirst=.3cm,colseplast=.5cm]
   \bTR
     \bTD A\eTD    \bTD B\eTD    \bTD C\eTD
   \eTR
\eTABLE

Enjoy it,
vit

Patch:
-----------------------------------------------
% suppressing spurious space from setupTABLE
\let\DosetupTABLE=\setupTABLE
\def\setupTABLE[#1][#2][#3]{\DosetupTABLE[#1][#2][#3]\ignorespaces}

% new bTABLE options <dimen>: colsepbetween, colsepfirst, colseplast
\def\nexttblcol
   {\doglobal\increment\colTBL\hskip\tbltblcolsepbetween\hbox{}&} % VZ

\def\begintblrow
   {\noalign
      {\doglobal\increment\rowTBL
       \doglobal\newcounter\colTBL}%
    \nexttblcol
    \hskip\tbltblcolsepfirst\hskip-\tbltblcolsepbetween} % VZ

\unprotected\def\endtblrow
   {\hskip-\tbltblcolsepbetween\hskip\tbltblcolseplast\hbox{}% VZ
    \crcr
    \noalign
      {\nointerlineskip
       \allowbreak
       \bgroup % protect local vars
         \@@tblsplitafter
       \egroup
       \bgroup % protect local vars
         \increment\rowTBL\relax
         \ifnum\rowTBL>\noftblhdnxlines\relax
           \ifnum\rowTBL<\maximumrow\relax
 
\doifsomething\tbltblspaceinbetween{\blank[\tbltblspaceinbetween]}%
           \fi
         \fi
       \egroup}}

\unprotected\def\endTBL
   {\appendtoks
      \endtbl
    \to\tbltoks
    \setbox\scratchbox\hbox
      {\localframed
         [\@@tbl\@@tbl]
         [\c!frame=\v!off,\c!background=,\c!align=\v!no]
         {\strut}}%
    \edef\minimalcellheight{\the\ht\scratchbox}%
    \dorecurse\maximumcol
      {\settblaut\recurselevel\!!zeropoint % \zeropoint etc
       % new
       \let\xcol\recurselevel
       \dorecurse\maximumrow
         {\settblwd \recurselevel\xcol\!!zeropoint
          \settblht \recurselevel\xcol\!!zeropoint}%
       % till here
       \settblwid\recurselevel\!!zeropoint}%
    \dorecurse\maximumrow
      {\settblhei\recurselevel\maxdimen}%
    \chardef\TBLpass\plusone
    \let\handleTBLcell\dohandleTBLcellA
    \def\makeTBL##1##2%
      {\gettbltxt{##1}{##2}}%
    \def\inTBLcell##1##2%
      {\ExpandBothAfter\doifinsetelse\localwidth{\v!fit,\v!broad} % user set
         {}
         {\scratchdimen\gettblaut\colTBL\relax
          \ifdim\localwidth>\scratchdimen
            \settblaut\colTBL\localwidth
          \fi}}%
    \setbox0\vbox{\trialtypesettingtrue \the\tbltoks}%
    \ifautoTBLspread
      % experimental, stretch non fixed cells to \hsize
      \checktblwidthsone   % trial run
      \checktblwidthstwo   % real run
      \stretchtblwidths
      \let\handleTBLcell\dohandleTBLcellB
      \setbox\scratchbox\vbox{\trialtypesettingtrue \the\tbltoks}%
    \else\ifdim\wd0>\hsize
      \ifautoTBLhsize
        \checktblwidthsone % trial run
        \checktblwidthstwo % real run
        \let\handleTBLcell\dohandleTBLcellB
        \setbox\scratchbox\vbox{\trialtypesettingtrue \the\tbltoks}%
      \fi
    \else\ifautoTBLrowspan\ifnum\maximumrowspan>1 % max ?
      % added jan 2002 because nx=* did no longer work
      \checktblwidthsone % trial run
      \checktblwidthstwo % real run
      %
      \let\handleTBLcell\dohandleTBLcellC
      \setbox\scratchbox\vbox{\trialtypesettingtrue \the\tbltoks}%
    \fi\fi\fi\fi
    \let\handleTBLcell\dohandleTBLcellD
    \chardef\TBLpass\plustwo
    \def\makeTBL##1##2% meer in cellD
      {\dimen2\zeropoint
       \globalpushmacro\colTBL
       \dorecurse{\gettblcol{##1}{##2}}
         {\advance\dimen2 \gettblwid\colTBL
          \advance\dimen2 \tbltblcolsepbetween % VZ
          \increment\colTBL}%
       \advance\dimen2 -\tbltblcolsepbetween % VZ
       \edef\widthTBL{\the\dimen2}%
       \globalpopmacro\colTBL
       \setbox\scratchbox\hbox{\gettbltxt{##1}{##2}}%
       \settblht{##1}{##2}{\the\ht\scratchbox}%
       \settblwd{##1}{##2}{\the\wd\scratchbox}%
       \ifdim\ht\scratchbox>\gettblhei{##1}\relax
         \settblhei{##1}{\the\ht\scratchbox}%
       \fi}%
    \setbox\scratchbox\vbox{\trialtypesettingtrue \the\tbltoks}%
    \checktblheightsone
    \checktblheightstwo
    \let\handleTBLcell\dohandleTBLcellE
    \chardef\TBLpass\plusthree
    \def\makeTBL##1##2%
      {% height
       \globalpushmacro\rowTBL
       \scratchdimen\zeropoint
       \def\rowTBL{##1}%
       \ifnum\gettblcol{##1}{##2}=\maximumcol\relax
         % case: nc=maxcolumns
       \else
         \dorecurse{\gettblrow{##1}{##2}}
           {\advance\scratchdimen \gettblhei\rowTBL
            \increment\rowTBL}%
         \ifdim\scratchdimen<\gettblht{##1}{##2}\relax
           \scratchdimen\gettblht{##1}{##2}\relax
         \fi
       \fi
       \edef\heightTBL{\the\scratchdimen}%
       \globalpopmacro\rowTBL
       % width
       \globalpushmacro\colTBL
       \scratchdimen\zeropoint
       \dorecurse{\gettblcol{##1}{##2}}
         {\advance\scratchdimen \gettblwid\colTBL
          \advance\scratchdimen \tbltblcolsepbetween % VZ
          \increment\colTBL}%
       \advance\scratchdimen -\tbltblcolsepbetween % VZ
       \edef\widthTBL{\the\scratchdimen}%
       \globalpopmacro\colTBL
       % cell
       \setbox\scratchbox\hbox{\gettbltxt{##1}{##2}}%
       \ifnum\gettblcol{##1}{##2}=\maximumcol\relax
         % case: nc=maxcolumns
       \else
         \scratchdimen\gettblhei{##1}%
         \setbox\scratchbox\hbox
           {\lower\ht\scratchbox\hbox{\raise\scratchdimen\box\scratchbox}}%
         \ht\scratchbox\scratchdimen
       \fi
       \dp\scratchbox\zeropoint
       \box\scratchbox}%
     \iftraceTABLE\showtbltoks\fi
     \ifnum\TBLlevel>\plusone
       \@EA\notsplittblbox
     \else\ifenableTBLbreak
       \@EAEAEA\splittblbox
     \else
       \@EAEAEA\notsplittblbox
     \fi\fi{\the\tbltoks}}

\unprotected\def\stretchtblwidths
   {\!!dimend\zeropoint
    \dorecurse\maximumcol
      {\advance\!!dimend\gettblwid\recurselevel
       \advance\!!dimend\tbltblcolsepbetween}% VZ
    \advance\!!dimend-\tbltblcolsepbetween   % VZ
    \advance\!!dimend\tbltblcolsepfirst      % VZ
    \advance\!!dimend\tbltblcolseplast       % VZ
    % distribute width (stretch)
    \ifdim\!!dimend<\hsize
      \advance\!!dimend-\hsize
      \!!dimend-\!!dimend
      \divide\!!dimend\maximumcol
      \dorecurse\maximumcol
        {\scratchdimen\gettblwid\recurselevel
         \advance\scratchdimen\!!dimend
         \settblwid\recurselevel{\the\scratchdimen}}%
    \fi}

\let\tbltblcolsepbetween\zeropoint
\let\tbltblcolsepfirst\zeropoint
\let\tbltblcolseplast\zeropoint
-----------------------------------------------------------

Old emails:
> Actually what I want. I have plenty of natural tables. If I want to make 
> closer interline space between table lines the only way I know is to 
> make smaller value of offset param. But after that, columns are too 
> close together (framed object as a core of natural table does not 
> distinguish between vertical and horizontal offsets). So bellow mentioned
>   \setupTABLE[c][1][distance=2em]
> would be nice solution.
> 
> So ones more, is the new code available?
> 
> Thank you in advance for the answer.
> Vit
> 
> Hans Hagen wrote:
> 
>> Adam Duck wrote:
>>
>>> Eckhart Guthöhrlein <eckhart.guthoehrlein@uni-bielefeld.de> writes:
>>>
>>>  
>>>
>>>> Am Sonntag, den 14.08.2005, 17:17 +0200 schrieb Adam Duck:
>>>>
>>>>  
>>>>
>>>>> - how do I set the spacing between a vertical line (between two
>>>>>  columns) and the text inside that columns?  I already used
>>>>>  "framedoffest=-3pt", but the output is unacceptable.
>>>>>     
>>>>
>>>>
>>>> Spacing is a weak point of natural tables. Afaik, there is no good way
>>>> to tune spacing. I would try using dummy colums like
>>>> \bTD[width=1em]\eTD.
>>>>   
>>>
>>>
>>> OK, That sounds reasonable.  I'll try that.  On the other hand this
>>> means many \bTD<something>\eTD ... but one can write a macro for that,
>>> I think.
>>>  
>>>
>> a next release will support:
>> \input core-ntb-new.tex
>>
>> \starttext
>>
>> \showframe
>>
>> \setupTABLE[c][1][distance=2em]
>> \setupTABLE[c][2][distance=3em]
> 
> 
> I was looking for core-ntb-new.tex or 'distance' in current beta
> core-ntb.tex but have not been successful. Please, where I can find it?
> 
> Thanks
> Vit
> 
>> \bTABLE
>> \bTR \bTD test \eTD  \bTD test \eTD  \bTD test \eTD \eTR
>> \bTR \bTD[nx=2] test \eTD  \bTD test \eTD \eTR
>> \bTR \bTD test \eTD  \bTD[nx=2] test \eTD \eTR
>> \eTABLE
>>
>>
>> \bTABLE[option=stretch]
>> \bTR \bTD test \eTD  \bTD test \eTD  \bTD test \eTD \eTR
>> \bTR \bTD[nx=2] test \eTD  \bTD test \eTD \eTR
>> \bTR \bTD test \eTD  \bTD[nx=2] test \eTD \eTR
>> \eTABLE
>>
>> \stoptext

  reply	other threads:[~2005-11-06 10:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-25  9:39 [Fwd: Re: Problems with Natural Tables] Vit Zyka
2005-11-06 10:55 ` Vit Zyka [this message]
2005-11-09 12:18   ` Problems with Natural Tables Hans Hagen
2005-11-09 14:38     ` Vit Zyka
  -- strict thread matches above, loose matches on Subject: below --
2005-08-14 15:17 Adam Duck
2005-08-14 19:13 ` Eckhart Guthöhrlein
2005-08-14 21:37   ` Vit Zyka
2005-08-14 22:03     ` Hans Hagen
2005-08-14 22:31   ` Adam Duck
2005-08-15  8:55     ` Hans Hagen
2005-08-15 15:19       ` Adam Duck
2005-08-15 15:35         ` Hans Hagen
2005-08-15 21:35           ` Vit Zyka
2005-08-15 15:36         ` Adam Duck
2005-10-22 13:20       ` Vit Zyka
2005-08-14 19:24 ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=436DE116.6090806@seznam.cz \
    --to=vit.zyka@seznam.cz \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).