Skip to content

Commit 50a74fb

Browse files
committed
Add columns width setter documentation
Documentation for symfony/symfony#17761
1 parent 1f4113f commit 50a74fb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

components/console/helpers/table.rst

+21
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ You can add a table separator anywhere in the output by passing an instance of
6666
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
6767
+---------------+--------------------------+------------------+
6868
69+
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`::
70+
71+
// Sets the left column to 10 characters, the middle to auto and the right to 30 characters.
72+
// The left column will effectively be 13 characters, as the columns content don't fit 10.
73+
$table->setColumnWidths(array(10, 'auto', 30));
74+
$table->render();
75+
76+
This code results in:
77+
78+
.. code-block:: text
79+
80+
+---------------+--------------------------+--------------------------------+
81+
| ISBN | Title | Author |
82+
+---------------+--------------------------+--------------------------------+
83+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
84+
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
85+
+---------------+--------------------------+--------------------------------+
86+
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
87+
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
88+
+---------------+--------------------------+--------------------------------+
89+
6990
The table style can be changed to any built-in styles via
7091
:method:`Symfony\\Component\\Console\\Helper\\Table::setStyle`::
7192

0 commit comments

Comments
 (0)