In another blog entry, we demonstrated how to create an extension method to add an auto-size functionality to Text Control Table TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
Table Class
An instance of the Table class represents a table in a Text Control document.
objects by looping through all cells of the given table, checking the length of all lines and resizing each column based on the longest detected lines.

This article shows how to auto-size a table by resizing all columns proportionally to fit into the current page width:

AutoSize

The Maths

To calculate the required gap (negative or positive), the total available width is required (maxWidth). This is the page size minus the left and right margin of the current section. currentWidth is calculated by totalizing all column widths in each row. The missing gap is then the maximum width minus the current width of the table row (destinationWidth).

Tables

Windows Forms, WPF, ASP.NET

This missing gap must be distributed proportionally to each cell width in the current row. The following C# code shows how to solve this using the Windows Forms, WPF or ASP.NET Text Control:

Loading...

This extension method can be called on any table in Text Control:

Loading...

JavaScript

The following JavaScript function shows how to realize this using the JavaScript API of the TX Text Control online document editor:

Loading...

This function can be simply called and will auto-size the table at the current input position:

Loading...