@@ -76,7 +76,19 @@ method to set the column widths explicitly::
76
76
77
77
In this example, the first column width will be ``10 ``, the last column width
78
78
will be ``30 `` and the second column width will be calculated automatically
79
- because of the ``0 `` value. The output of this command will be:
79
+ because of the ``0 `` value.
80
+
81
+ You can also set the width individually for each column with the
82
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ Table::setColumnWidth ` method.
83
+ Its first argument is the column index (starting from ``0 ``) and the second
84
+ argument is the column width::
85
+
86
+ // ...
87
+ $table->setColumnWidth(0, 10);
88
+ $table->setColumnWidth(2, 30);
89
+ $table->render();
90
+
91
+ The output of this command will be:
80
92
81
93
.. code-block :: terminal
82
94
@@ -95,16 +107,30 @@ widths. If the contents don't fit, the given column width is increased up to the
95
107
longest content length. That's why in the previous example the first column has
96
108
a ``13 `` character length although the user defined ``10 `` as its width.
97
109
98
- You can also set the width individually for each column with the
99
- :method: `Symfony\\ Component\\ Console\\ Helper\\ Table::setColumnWidth ` method.
100
- Its first argument is the column index (starting from ``0 ``) and the second
101
- argument is the column width::
110
+ If you prefer to wrap long contents in multiple rows, use the
111
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ Table::setColumnMaxWidth ` method::
102
112
103
113
// ...
104
- $table->setColumnWidth (0, 10 );
105
- $table->setColumnWidth(2, 30 );
114
+ $table->setColumnMaxWidth (0, 5 );
115
+ $table->setColumnMaxWidth(1, 10 );
106
116
$table->render();
107
117
118
+ The output of this command will be:
119
+
120
+ .. code-block :: terminal
121
+
122
+ +-------+------------+--------------------------------+
123
+ | ISBN | Title | Author |
124
+ +-------+------------+--------------------------------+
125
+ | 99921 | Divine Com | Dante Alighieri |
126
+ | -58-1 | edy | |
127
+ | 0-7 | | |
128
+ | (the rest of rows...) |
129
+ +-------+------------+--------------------------------+
130
+
131
+ .. versionadded :: 4.2
132
+ The ``setColumnMaxWidth() `` method was introduced in Symfony 4.2.
133
+
108
134
The table style can be changed to any built-in styles via
109
135
:method: `Symfony\\ Component\\ Console\\ Helper\\ Table::setStyle `::
110
136
0 commit comments