Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting column width in RTF

Tags:

width

rtf

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 !

like image 620
Polecat Harris Avatar asked Mar 09 '11 12:03

Polecat Harris


3 Answers

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 }
like image 184
saperduper Avatar answered Jan 01 '23 10:01

saperduper


The problem is in that you have set very small width for column:

\cellx1 
\cellx2 
\cellx3

To set width for column in RTF there is a keyword '\cellxN', where N - is column width in twips. 15 twips is 1px.

So if you want to create a simple RTF table with 1 row and 3 columns, 100px each, use this syntax:

\trowd\cellx1500\cellx3000\cellx4500
\intbl A\cell B\cell C\cell\row

You will get a simple table by 300px, 3 columns - 100px each, with invisible borders.

Cheers, Max

like image 22
Maxim Sautin Avatar answered Jan 01 '23 09:01

Maxim Sautin


You need to either use cellx0, so that autofit tag applies, or explicity set the number to the number of twips from the left border. In your example, you use 1 2 and 3 which is explicity setting the column widths to be very skinny. For example, something like:

\cellx5125 \Cellx6000 \Cellx8000

Note that these numbers are offsets from the left margin.

If you are going to do any RTF, I highly recomend the RTF Pocket Guide from O'Rielly

like image 38
PAUL Mansour Avatar answered Jan 01 '23 08:01

PAUL Mansour