Skip to content

Commit 89bdbc6

Browse files
committed
feature #6296 [Console] Add columns width setter documentation (akeeman)
This PR was merged into the master branch. Discussion ---------- [Console] Add columns width setter documentation Documentation for symfony/symfony#17761 Commits ------- 097fb65 remove support for "auto" 50a74fb Add columns width setter documentation
2 parents ceeab1a + 097fb65 commit 89bdbc6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

components/console/helpers/table.rst

Lines changed: 21 additions & 0 deletions
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 0, and the right to 30 characters.
72+
// The left two columns will effectively be 13 and 24 characters, as the columns' content don't fit within the set values.
73+
$table->setColumnWidths(array(10, 0, 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)