uso-de-tablas-en-markdown

How to use tables in Markdown

  • 3 min

The syntax for creating tables in Markdown is simple and easy to read. However, writing them can be a bit more cumbersome (at the end of the article I’ll recommend some tools).

It simply uses hyphens (-) to define the column headers and vertical bars (|) to separate the columns.

Let’s see a basic example of a table in Markdown:

| Header 1     | Header 2     | Header 3     |
|--------------|--------------|--------------|
| Data 1       | Data 2       | Data 3       |
| Data 4       | Data 5       | Data 6       |
Copied!

This code renders as:

Header 1Header 2Header 3
Data 1Data 2Data 3
Data 4Data 5Data 6

Components of a Markdown Table

  • Column Headers: The first row of the table, which defines the column names. They are separated by vertical bars (|) and underlined with hyphens (-).
  • Column Separators: The hyphens (-) below the headers indicate the start of the data rows.
  • Data Rows: Each data row follows the same format of separation by vertical bars (|).

Tables in Markdown are much more limited than in other languages, such as HTML. For example, it is not possible to create a table without a header, or to create merged cells.

Column Alignment

Markdown allows aligning text within columns to the left, right, or center. This is achieved by using colons (:) in the column separators.

  • Left alignment: Use :---.
  • Right alignment: Use ---:.
  • Center alignment: Use :---:.

Alignment example:

| Left         | Center       | Right        |
|:------------ |:------------:| ------------:|
| Data 1       | Data 2       | Data 3       |
| Data 4       | Data 5       | Data 6       |
Copied!

This renders as:

LeftCenterRight
Data 1Data 2Data 3
Data 4Data 5Data 6

Tools for Creating Tables in Markdown

Although it’s possible to create tables manually, it’s a bit of a nightmare if your editor doesn’t help you a little (for example, by automatically indenting the table).

Fortunately, there are several tools and editors that facilitate this process:

  • Markdown Table Generator: Online tools like TablesGenerator will help us create and customize tables visually.
  • Text editor plugins: Editors like Visual Studio Code and Obsidian have extensions that help format tables in Markdown, and even copy from or to a spreadsheet.

Best Practices Tips

Simplicity: Keep tables simple and easy to read. It’s the only advice I can give you. Don’t make a huge, unbearable table.