How to Create a Markdown Table
Markdown is a lightweight markup language that enables the easy creation of structured documents. One of the widely used formatting features of Markdown is creating tables. Markdown tables make it simple to organize data in a tabular form, making it easy to read and understand. Here’s how you can create a Markdown table:
Step 1: Define the table header
The first step involves defining the header row of the table. To do this, start with a pipe character (|) followed by the header title. The pipe represents the separation between each column. Use the same number of pipes as the number of columns in the table. For example, if you want to create a table with three columns, use three pipes as follows:
“`
| Column 1 | Column 2 | Column 3 |
“`
Step 2: Define the table separator
The table separator separates the header row from the data rows. To define it, add a new line with a pipe character followed by three hyphens (—) for each column. For example:
“`
| Column 1 | Column 2 | Column 3 |
| — | — | — |
“`
Step 3: Add data rows
Add the data rows beneath the table separator. Each row should start with a | to create a new cell and be separated by the same number of pipes as the header row. For instance:
“`
| Apple | $1 | Red |
| Orange | $2 | Orange |
“`
Step 4: Align contents
You can align the contents of each column by adding colons (:) to the header separator line. For example, to align the first column to the left, the second column in the center, and the third column to the right, use:
“`
| Column 1 | Column 2 | Column 3 |
| :— | :—: | —: |
“`
The colon positioning tells Markdown how to align the contents in each cell, with “left,” “center,” or “right.”
Step 5: Finalize the table
Lastly, add a new line after the final data row to avoid merging with the text beneath. The final table should look like:
“`
| Column 1 | Column 2 | Column 3 |
| :— | :—: | —: |
| Apple | $1 | Red |
| Orange | $2 | Orange |
“`