--- layout: default title: Table Extension description: The TableExtension adds the ability to create tables in CommonMark documents --- # Table Extension _(Note: this extension is included by default within [the GFM extension](/2.2/extensions/github-flavored-markdown/))_ The `TableExtension` adds the ability to create tables in CommonMark documents. ## Installation This extension is bundled with `league/commonmark`. This library can be installed via Composer: ```bash composer require league/commonmark ``` See the [installation](/2.2/installation/) section for more details. ## Usage Configure your `Environment` as usual and simply add the `TableExtension` provided by this package: ```php use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\Extension\Table\TableExtension; use League\CommonMark\MarkdownConverter; // Define your configuration, if needed $config = [ 'table' => [ 'wrap' => [ 'enabled' => false, 'tag' => 'div', 'attributes' => [], ], ], ]; // Configure the Environment with all the CommonMark parsers/renderers $environment = new Environment($config); $environment->addExtension(new CommonMarkCoreExtension()); // Add this extension $environment->addExtension(new TableExtension()); // Instantiate the converter engine and start converting some Markdown! $converter = new MarkdownConverter($environment); echo $converter->convert('Some Markdown with a table in it'); ``` ## Syntax This package is fully compatible with [GFM-style tables](https://github.github.com/gfm/#tables-extension-): ### Simple Code: ```markdown th | th(center) | th(right) ---|:----------:|----------: td | td | td ``` Result: ```html
th | th(center) | th(right)/th> |
---|---|---|
td | td | td |