Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Console Table: how to center columns content?

Using Table of Symfony Console Component one can draw tables with rows and columns.

How to align to the center the content of the columns?

like image 779
Francesco Borzi Avatar asked Sep 03 '25 16:09

Francesco Borzi


1 Answers

In order to change the style of a Table, one should use the TableStyle class and its setPadType method passing STR_PAD_BOTH to it.

Example:

$table = new Table($output);

// set table contents
// ...

$tableStyle = new TableStyle();
$tableStyle->setPadType(STR_PAD_BOTH);

$table->setStyle($tableStyle)->render();
like image 187
Francesco Borzi Avatar answered Sep 05 '25 07:09

Francesco Borzi