public void InsertTableWithPreferredWidth()
{
//ExStart
//ExFor:Table.PreferredWidth
//ExFor:PreferredWidth.FromPercent
//ExFor:PreferredWidth
//ExId:TablePreferredWidth
//ExSummary:Shows how to set a table to auto fit to 50% of the page width.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table with a width that takes up half the page width.
Table table = builder.StartTable();
// Insert a few cells
builder.InsertCell();
table.PreferredWidth = PreferredWidth.FromPercent(50);
builder.Writeln("Cell #1");
builder.InsertCell();
builder.Writeln("Cell #2");
builder.InsertCell();
builder.Writeln("Cell #3");
doc.Save(MyDir + @"\Artifacts\Table.PreferredWidth.doc");
//ExEnd
// Verify the correct settings were applied.
Assert.AreEqual(PreferredWidthType.Percent, table.PreferredWidth.Type);
Assert.AreEqual(50, table.PreferredWidth.Value);
}