Language: EN

uso-de-tablas-en-markdown

How to use tables in Markdown

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 recommend some tools).

You simply use dashes (-) to define the headers of the columns and vertical bars (|) to separate the columns.

Let’s look at 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       |

This code renders as:

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

Components of a Table in Markdown

  • Column Headers: The first row of the table, which defines the names of the columns. They are separated by vertical bars (|) and underlined with dashes (-).
  • Column Separators: The dashes (-) 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, like HTML. For example, it is not possible to create a table without a header, or to create merged cells.

Column Alignment

Markdown allows you to align text within the 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 :---:.

Example of alignment:

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

This renders as:

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

Tools for Creating Tables in Markdown

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

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

  • Markdown Table Generator: Online tools like TablesGenerator will help you 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. That’s the only advice I can give you. Don’t make a giant, unreadable table.