From 50a74fb00423d212c90342ac39595a5e7ed40c88 Mon Sep 17 00:00:00 2001 From: Arjan Keeman Date: Mon, 22 Feb 2016 15:55:12 +0100 Subject: [PATCH 1/2] Add columns width setter documentation Documentation for https://github.com/symfony/symfony/pull/17761 --- components/console/helpers/table.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/components/console/helpers/table.rst b/components/console/helpers/table.rst index 5dc4e827bb3..930cd744f4e 100644 --- a/components/console/helpers/table.rst +++ b/components/console/helpers/table.rst @@ -66,6 +66,27 @@ You can add a table separator anywhere in the output by passing an instance of | 80-902734-1-6 | And Then There Were None | Agatha Christie | +---------------+--------------------------+------------------+ +The width of the columns are automatically set using the width of their contents by default. You can change this behavior via :method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidths`:: + + // Sets the left column to 10 characters, the middle to auto and the right to 30 characters. + // The left column will effectively be 13 characters, as the columns content don't fit 10. + $table->setColumnWidths(array(10, 'auto', 30)); + $table->render(); + +This code results in: + +.. code-block:: text + + +---------------+--------------------------+--------------------------------+ + | ISBN | Title | Author | + +---------------+--------------------------+--------------------------------+ + | 99921-58-10-7 | Divine Comedy | Dante Alighieri | + | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | + +---------------+--------------------------+--------------------------------+ + | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien | + | 80-902734-1-6 | And Then There Were None | Agatha Christie | + +---------------+--------------------------+--------------------------------+ + The table style can be changed to any built-in styles via :method:`Symfony\\Component\\Console\\Helper\\Table::setStyle`:: From 097fb656e9b47521b306731e69e1e34be9307219 Mon Sep 17 00:00:00 2001 From: Arjan keeman Date: Tue, 1 Mar 2016 16:03:18 +0100 Subject: [PATCH 2/2] remove support for "auto" --- components/console/helpers/table.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/console/helpers/table.rst b/components/console/helpers/table.rst index 930cd744f4e..c43302b3946 100644 --- a/components/console/helpers/table.rst +++ b/components/console/helpers/table.rst @@ -68,9 +68,9 @@ You can add a table separator anywhere in the output by passing an instance of The width of the columns are automatically set using the width of their contents by default. You can change this behavior via :method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidths`:: - // Sets the left column to 10 characters, the middle to auto and the right to 30 characters. - // The left column will effectively be 13 characters, as the columns content don't fit 10. - $table->setColumnWidths(array(10, 'auto', 30)); + // Sets the left column to 10 characters, the middle to 0, and the right to 30 characters. + // The left two columns will effectively be 13 and 24 characters, as the columns' content don't fit within the set values. + $table->setColumnWidths(array(10, 0, 30)); $table->render(); This code results in: