Setting column width in RTF

Polecat Harris picture Polecat Harris · Mar 9, 2011 · Viewed 16.1k times · Source

I have what I hope is a simple question !

I am generating a simple RTF table that is subsequently opened in MS Word. The table is generating fine but the column widths are a little small and causing some word wrapping (not what I want).

The RTF code I generate is for a two line, three column table and is of the form:

\trowd \trautofit1 
\intbl
\cellx1 
\cellx2 
\cellx3 
{a\cell b\cell c\cell }{\trowd \trautofit1 
\intbl
\cellx1 
\cellx2 
\cellx3 
\row} 
\trowd \trautofit1 
\intbl
\cellx1 
\cellx2 
\cellx3 
{d\cell e\cell f\cell }{\trowd \trautofit1 
\intbl
\cellx1 
\cellx2 
\cellx3 
\row} 

What do I need to add to set a column width ? I have tried altering the column width in word and then examining the output but it is a little obscure to say the least !

Answer

saperduper picture saperduper · Apr 3, 2011

The control words you are looking for are \clwWidthN and \clftsWidthN

Microsoft RTF Specification v1.9.1:

- \clwWidthN
Preferred cell width. Overrides \trautofitN.
- \clftsWidthN 
Units for \clwWidthN:    
  - 0 : Null. Ignore \clwWidthN in favor of \cellxN (Word 97 style of determining cell and row width).
  - 1 : Auto, no preferred cell width, ignores \clwWidthN if present; \clwWidthN will generally not be written, giving precedence to row defaults.
  - 2 : Percentage (in 50ths of a percent).
  - 3 : Twips.

So, in your case, you could just use \clftsWidth1 (automatically set width) or set the preferred percentages yourself e.g. \clwWidth2\clwWidth2500 (2500 = 50%)

Auto width

\trowd \trautofit1  
\intbl  
\clftsWidth1\cellx1  
\clftsWidth1\cellx2  
\clftsWidth1\cellx3  
{a\cell b\cell c\cell }

40% - 30% - 30%

\trowd \trautofit1  
\intbl  
\clftsWidth2\clwWidth2000\cellx1  
\clftsWidth2\clwWidth1500\cellx2  
\clftsWidth2\clwWidth1500\cellx3  
{a\cell b\cell c\cell }