TableDirectives-Talk

Show or Hide table

Is it possible to have a collapsible table, that you can set by default to be deployed (as with the (:toc:) display) or retracted?

Cell spacing

When using table directives to set up image slices, i get spaces between some of the images, even though cellpadding and cellspacing are both set to 0? How do I eliminate this behavior?

This may need to be taken care of in CSS via
#myTableDiv img { display:block; }

overtones99 April 12, 2011, at 02:53 AM

Making tables easier

Maybe I have missed something but I have found tables extremely tedious. I've ended up writing macros for my text editor to put in the (:cellnr:) commands at the right place. Eventually even this has become boring, and I've made an addition to the markup. The addition to the config file is shown below. These are the instructions:

You can now add a new parameter to the table header, the "cwidth" is the width in columns.

(:table width=95% align=center class=border cwidth=4:)

After that, every cwidth'th (:cell:) (every 4th in the above case) will automatically generate a (:cellnr:). At the end of the table enough (:cell:)'s will be added to pad it out to the correct width.

What this means is that you no longer have to insert (:cellnr:) tags. A table becomes a simple list of (:cell:) tags and data. If you need to insert another name you just add it, no need to reformat all the other entries in the table.

You can still use (:cellnr:) and it works as before, for example for a table title. If there is no cwidth parameter in the table header then everything works as before.

## Extend tables

$FXtableCount;
$FXtableWidth;

function FXtable($t,$args)
{
 global $FXtableCount;
 global $FXtableWidth;
 $extra='';

 if($t=='table')
 {
  $FXtableWidth=0;
  $FXtableCount=0;

  if(preg_match("/\bcwidth\s*=\s*(\d+)\b/",$args,$matches,PREG_OFFSET_CAPTURE)==1)
  {
   $FXtableWidth=$matches[1][0];
   $args=substr($args,0,$matches[0][1]).substr($args,$matches[0][1]+strlen($matches[0][0]));
  }
 }
 else
 if($FXtableWidth>0)
 {
  if($t=='tableend')
  {
   $extra=str_repeat("(:cell:)\n",$FXtableWidth-$FXtableCount);
   $FXtableWidth=0;
  }
  else
  if($t=='cell')
  {
   $FXtableCount++;
   if($FXtableCount>$FXtableWidth)
   {
    $t='cellnr';
    $FXtableCount=1;
   }
  }
		else
		if($t=='cellnr')
		{
   $FXtableCount=1;
		}
 }
 return($extra."(:".$t." ".$args.":)");
}

Markup('Xtable', '_begin',
  '/^\\(:(table|cell|cellnr|tableend)(\\s.*?)?:\\)/ei',
  "FXtable('$1','$2')");


David Pilling (pmwk@pilling.demon.co.uk) December 28, 2011, at 18:01 GMT

hi David, haven't had a chance to try out your possibly wonderful addition yet, but just a heads up that a similar extension exists here: Cookbook:CreateColumns. it's a separate markup that allows the constraining of the number of columns, or the number of items per column. overtones99 December 28, 2011, at 07:55 PM
Thanks. At first sight I thought CreateColumns duplicated my effort. However after trying it I am not sure. I want my data in cells going across the table, not in columns. This is an example of my tables and code in use:
I've added a bug fixed version above. David Pilling. December 29, 2011, at 21:24 GMT


This is a talk page for improving PmWiki.TableDirectives.