Adjusting Table Width Automatically



The feature list for includes the following:

3) Adjusting table width automatically when the child table is too large is supported.

The only way I can get a child table to fit is by using the following code:

tab1.SetColumnWidth(1, tab1.GetMinColumnWidth(1)) ’ Column 1 contains the nested table

If I don’t use that line of code, the nested table will extend outside
the borders of its parent table. How do I make tables do this

Thanks, Natan.


Dear Natan,

Thanks for considering Aspose.Pdf.

Can you post the total coding block, I will test on my computer.

Best regards.


Here’s the code I used (

Dim fsPdfFile As New FileStream(sPdfFile, FileMode.Create)

pdfDocument = New Pdf(fsPdfFile)

pdfSection = New Section(pdfDocument)


’ Debug nested table test

Dim tab1 As Table = New Table()

tab1.FixedWidth = 400

tab1.ColumnWidths = “200 200”

tab1.DefaultCellBorder = New BorderInfo(BorderSide.All)

Dim row1 As Row = tab1.Rows.Add()

row1.Cells.Add(“left cell”)

Dim cell2 As Cell = row1.Cells.Add()

cell2.Padding.Bottom = 3

cell2.Padding.Top = 3

cell2.Padding.Left = 3

cell2.Padding.Right = 3

Dim tab2 As Table = New Table(cell2)


tab2.FixedWidth = 300

tab2.ColumnWidths = “150 150”

Dim row21 As Row = tab2.Rows.Add()

Dim cell21 As Cell = row21.Cells.Add(“top cell”)

cell21.ColumnsSpan = 2

Dim row22 As Row = tab2.Rows.Add()

row22.Cells.Add(“left bottom cell”)

row22.Cells.Add(“right bottom cell”)

tab1.SetColumnWidth(1, tab1.GetMinColumnWidth(1))




This bug will be fixed in the next hotfix at this weekend.


Thanks. So from this version on, can I assume that nested tables should never extend beyond the boundaries of parent tables?

I had written some code to prevent this from happening and I'd like to remove it for performance reasons.

Thanks, Natan.


Yes but when nested table is larger than parent table's column, we can only extend column of parent table. We can't assure the parent table has appropriate column width then.


hi, i have a similar issue:

when using Table.ColumnWidths = "50% 50%" in a NESTED table, the table does not display; but when using the syntax Table.ColumnWidths = "300 300" in a nested tabel, no problem.

Of course it would be nice to do this (all dynamic sizing of tables and nested tables within) :

For example:

Table masterTable = new Table();

masterTable.ColumnWidths = "100%";


Row row_1 = masterTable.Rows.Add();

Cell cell_1 = row_1.Cells.Add();

Table table_1 = new Table();

table_1.ColumnWidths = "50% 50%";




I have tested the above snippet code embedded in my scenario, it was fine and the bug wasn’t reproduced.

Could you please post the whole code block or send to


ok, here's the code (it does not work if the ColumnWidths are set to percentages, but if you comment that line of code, of course it works!) also works when you add a pixel unit, like "300 300"

Pdf pdf = new Pdf();

Section sec1 = pdf.Sections.Add();

sec1.PageInfo.PageHeight = PageSize.LetterHeight;

sec1.PageInfo.PageWidth = PageSize.LetterWidth;

sec1.PageInfo.Margin.Left = 20;

sec1.PageInfo.Margin.Right = 20;

Table masterTable = new Table();

masterTable.ColumnWidths = "50% 50%";


masterTable.Border = new BorderInfo((int) BorderSide.All, 0.5f, new Color(0,255,0));

Row row_1 = masterTable.Rows.Add();

Row row_2 = masterTable.Rows.Add();

Cell cell2 = row_2.Cells.Add("Testing");


Cell cell_1 = row_1.Cells.Add();

Table t_1 = new Table();

t_1.ColumnWidths = "25% 25%";

t_1.Border = new BorderInfo((int) BorderSide.All, 0.5f, new Color(255,0,0));

Row t_1_r_1 = t_1.Rows.Add();

Cell t_1_r_1_c_1 = t_1_r_1.Cells.Add("1Test_Cell1");



Cell cell_2 = row_1.Cells.Add();

Table t_2 = new Table();

t_2.Border = new BorderInfo((int) BorderSide.All, 0.5f, new Color(0,0,255));

Row t_2_r_1 = t_2.Rows.Add();

Cell t_2_r_1_c_1 = t_2_r_1.Cells.Add("2Test_Cell2");





Which version of Aspose.Pdf was made reference to in your project? It
is not a new bug and has been resolved, Please download the latest
version and try again.