5

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 !

user229044
  • 232,980
  • 40
  • 330
  • 338
Polecat Harris
  • 177
  • 2
  • 3
  • 11

4 Answers4

10

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 }
saperduper
  • 121
  • 2
9

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

Maxim Sautin
  • 133
  • 5
3

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

PAUL Mansour
  • 131
  • 3
0

Check this link

http://joseluisbz.wordpress.com/2014/04/26/working-rtf-html-css-and-script-files-with-my-own-packages-java-and-php/

you can to make your own file.

      TblData = new RTFTable(4,4);  //4 Columns, 4 Rows

      TblData.setWideCols(1000);  //Width of 2000 to put all columns
      TblData.setWideCol(0,3000);  //Width of 3000 to Column 0
joseluisbz
  • 1,491
  • 1
  • 36
  • 58