From e639cdf0ec95953355dda82b0bd9b443a08142f9 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 6 Apr 2016 11:37:32 +0200 Subject: [PATCH 1/3] Improved the documentation about the explicit column widths --- components/console/helpers/table.rst | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/components/console/helpers/table.rst b/components/console/helpers/table.rst index 73a5d6ce8e2..eea058f9183 100644 --- a/components/console/helpers/table.rst +++ b/components/console/helpers/table.rst @@ -66,15 +66,17 @@ 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 control the minimum widths via :method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidths`:: +By default the width of the columns is calculated automatically based on their +contents. Use the :method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidths` +method to set the columns widths explicitly:: - // the widths will expand to be bigger if necessary - // here, the left two columns will be 13 & 24 characters to fit their content + // ... $table->setColumnWidths(array(10, 0, 30)); $table->render(); - -This code results in: + +In this example, the first column width will be ``10``, the last column width +will be ``30`` and the second column width will be calculated automatically +because of the ``0`` value. The output of this command will be: .. code-block:: text @@ -88,6 +90,21 @@ This code results in: | 80-902734-1-6 | And Then There Were None | Agatha Christie | +---------------+--------------------------+--------------------------------+ +Note that the defined column widths are always considered as the minimum column +widths. If the contents don't fit, the given column width is increased up to the +contents length. That's why in the previous example the first column has a ``13`` +character length although the user defined ``10`` as its width. + +You can also set the width individually for each column with the +:method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidth` method. +Its first argument is the column index (starting from ``0``) and the second +argument is the column width: + + // ... + $table->setColumnWidth(0, 10); + $table->setColumnWidths(2, 30); + $table->render(); + The table style can be changed to any built-in styles via :method:`Symfony\\Component\\Console\\Helper\\Table::setStyle`:: From f3a7a26b89af0b585bdeeab444d63c0d7e955f66 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 6 Apr 2016 11:44:30 +0200 Subject: [PATCH 2/3] Minor reword --- components/console/helpers/table.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/console/helpers/table.rst b/components/console/helpers/table.rst index eea058f9183..35d822ce96d 100644 --- a/components/console/helpers/table.rst +++ b/components/console/helpers/table.rst @@ -92,8 +92,8 @@ because of the ``0`` value. The output of this command will be: Note that the defined column widths are always considered as the minimum column widths. If the contents don't fit, the given column width is increased up to the -contents length. That's why in the previous example the first column has a ``13`` -character length although the user defined ``10`` as its width. +longest content length. That's why in the previous example the first column has +a ``13`` character length although the user defined ``10`` as its width. You can also set the width individually for each column with the :method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidth` method. From 780f68cb8ccb37f6531c5ee10fced0ce4db713c5 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 12 Apr 2016 21:13:49 +0200 Subject: [PATCH 3/3] Fixed errors --- 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 35d822ce96d..65d887bbe71 100644 --- a/components/console/helpers/table.rst +++ b/components/console/helpers/table.rst @@ -68,7 +68,7 @@ You can add a table separator anywhere in the output by passing an instance of By default the width of the columns is calculated automatically based on their contents. Use the :method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidths` -method to set the columns widths explicitly:: +method to set the column widths explicitly:: // ... $table->setColumnWidths(array(10, 0, 30)); @@ -98,11 +98,11 @@ a ``13`` character length although the user defined ``10`` as its width. You can also set the width individually for each column with the :method:`Symfony\\Component\\Console\\Helper\\Table::setColumnWidth` method. Its first argument is the column index (starting from ``0``) and the second -argument is the column width: +argument is the column width:: // ... $table->setColumnWidth(0, 10); - $table->setColumnWidths(2, 30); + $table->setColumnWidth(2, 30); $table->render(); The table style can be changed to any built-in styles via