[TxMt] Latex/Tables - Alignment at &

Charilaos Skiadas cskiadas at uchicago.edu
Sun Jul 30 16:21:47 UTC 2006


On Jul 30, 2006, at 4:50 AM, Daniel Käsmayr wrote:

> Hello fellow maters,
>
> A while ago we had a command that would align statements at their =  
> signs…
>
> Would it be possible to incorporate that feature into the table- 
> macros fo LaTeX? So that the tables cells are aligned at the &  
> signs? And possibly make a command out of this that would re-format  
> existing tables?

> just wondering if anyone feels like it ;)
>

Here is a first take at it. It requires that you select the rows you  
want to work on. Let me know if it works consistently in this case.  
Input to selected text, output to replace selection.

#!/usr/bin/env ruby
require 'pp'
lines = STDIN.readlines.map {|line| line.chomp.split(/\s*&\s*/)}
table_lines = lines.reject{|line| line.length == 1}
columns = table_lines.shift.zip(*table_lines)
columns_lengths = columns.map{|column| column.map{|i| i.length}.max}
pattern = columns_lengths.map{|i| "%-#{i}s"}.join(" & ") + "\n"
for line in lines do
   if line.length == 1 then
     puts line
   else
     printf(pattern,*line)
   end
end


> Dan
> …in his final stages of actually beating that thesis writing monster…

Good luck!!

Haris





More information about the textmate mailing list