Markdown Backend Examples

This page contains examples of markdown tables generated by PrettyTables.jl.

The A object, when referenced, is defined as:

julia> A = Any[
    1    false      1.0     0x01
    2     true      2.0     0x02
    3    false      3.0     0x03
    4     true      4.0     0x04
    5    false      5.0     0x05
    6     true      6.0     0x06
]

Basic Table

First, we create a basic markdown table using the pretty_table function with the backend keyword set to :markdown.

table = pretty_table(String, A; backend = :markdown)
Col. 1Col. 2Col. 3Col. 4
1false1.01
2true2.02
3false3.03
4true4.04
5false5.05
6true6.06

We can add custom column labels by passing a vector of strings to the column_labels keyword.

table = pretty_table(
    String,
    A;
    backend = :markdown,
    column_labels = ["ID", "Flag", "Value", "Hex"]
)
IDFlagValueHex
1false1.01
2true2.02
3false3.03
4true4.04
5false5.05
6true6.06

Column Label Style

The style of the column labels can be customized by passing a MarkdownTableStyle to the style keyword. In the first example, we set the first_line_column_label field of the style to a MarkdownStyle with the bold field set to true to obtain bold column labels.

**bold** Column Labels
table = pretty_table(
    String,
    A;
    backend = :markdown,
    style = MarkdownTableStyle(first_line_column_label = MarkdownStyle(bold = true))
)
| **Col. 1** | **Col. 2** | **Col. 3** | **Col. 4** |
|-----------:|-----------:|-----------:|-----------:|
|          1 |      false |        1.0 |          1 |
|          2 |       true |        2.0 |          2 |
|          3 |      false |        3.0 |          3 |
|          4 |       true |        4.0 |          4 |
|          5 |      false |        5.0 |          5 |
|          6 |       true |        6.0 |          6 |
Col. 1Col. 2Col. 3Col. 4
1false1.01
2true2.02
3false3.03
4true4.04
5false5.05
6true6.06

In the second example we use italic column labels:

*italic* Column Labels
table = pretty_table(
    String,
    A;
    backend = :markdown,
    style = MarkdownTableStyle(first_line_column_label = MarkdownStyle(italic = true))
)
| *Col. 1* | *Col. 2* | *Col. 3* | *Col. 4* |
|---------:|---------:|---------:|---------:|
|        1 |    false |      1.0 |        1 |
|        2 |     true |      2.0 |        2 |
|        3 |    false |      3.0 |        3 |
|        4 |     true |      4.0 |        4 |
|        5 |    false |      5.0 |        5 |
|        6 |     true |      6.0 |        6 |
Col. 1Col. 2Col. 3Col. 4
1false1.01
2true2.02
3false3.03
4true4.04
5false5.05
6true6.06

Custom Alignment

The alignment of each column can be specified by passing a vector of symbols to the alignment keyword. The supported alignment values are:

  • :l: Left alignment
  • :c: Center alignment
  • :r: Right alignment

The default alignment is left alignment (:l).

Example code
table = pretty_table(
    String,
    A;
    backend = :markdown,
    column_labels = ["Left", "Center", "Right", "Default"],
    alignment = [:l, :c, :r, :l]
)
| **Left** | **Center** | **Right** | **Default** |
|:---------|:----------:|----------:|:------------|
| 1        |   false    |       1.0 | 1           |
| 2        |    true    |       2.0 | 2           |
| 3        |   false    |       3.0 | 3           |
| 4        |    true    |       4.0 | 4           |
| 5        |   false    |       5.0 | 5           |
| 6        |    true    |       6.0 | 6           |
LeftCenterRightDefault
1false1.01
2true2.02
3false3.03
4true4.04
5false5.05
6true6.06

Row and Column Labels

Additional row and column labels can be added to the table by passing the row_labels and column_labels keywords to the pretty_table function. The stubhead_label keyword can be used to specify the label of the stubhead (corner cell).

Example code
data = [
    10.0 6.5
    3.0 3.0
    0.1 1.0
]

row_labels = [
    "Atmospheric drag"
    "Gravity gradient"
    "Solar radiation pressure"
]

column_labels = [
    "Torque [10⁻⁶ Nm]",
    "Angular Momentum [10⁻³ Nms]"
]

table = pretty_table(
    String,
    data;
    backend = :markdown,
    column_labels,
    row_labels,
    stubhead_label = "Effect",
    summary_row_labels = ["Total"],
    summary_rows = [(data, i) -> sum(data[:, i])],
)
|                   **Effect** | **Torque \[10⁻⁶ Nm\]** | **Angular Momentum \[10⁻³ Nms\]** |
|-----------------------------:|-----------------------:|----------------------------------:|
|         **Atmospheric drag** |                   10.0 |                               6.5 |
|         **Gravity gradient** |                    3.0 |                               3.0 |
| **Solar radiation pressure** |                    0.1 |                               1.0 |
| ──────────────────────────── | ────────────────────── | ───────────────────────────────── |
|                    **Total** |                   13.1 |                              10.5 |
EffectTorque [10⁻⁶ Nm]Angular Momentum [10⁻³ Nms]
Atmospheric drag10.06.5
Gravity gradient3.03.0
Solar radiation pressure0.11.0
───────────────────────────────────────────────────────────────────────────────────
Total13.110.5

Markdown Highlighters

A markdown highlighter is defined using an object of type MarkdownHighlighter. Two types of highlighters are supported: italic and bold.

Example code
t = 0:1:20

data = hcat(t, ones(length(t)), t, 0.5.*t.^2)

column_labels = [
    ["Time", "Acceleration", "Velocity", "Distance"],
    ["[s]", "[m / s²]", "[m / s]", "[m]"]
]

hl_p = MarkdownHighlighter(
    (data, i, j) -> (j == 4) && (data[i, j] > 9),
    MarkdownStyle(italic = true)
)

hl_v = MarkdownHighlighter(
    (data, i, j) -> (j == 3) && (data[i, j] > 9),
    MarkdownStyle(bold = true)
)

table = pretty_table(
    String,
    data;
    backend = :markdown,
    column_labels = column_labels,
    highlighters = [hl_p, hl_v],
)
| **Time**<br>`\[s\]` | **Acceleration**<br>`\[m / s²\]` | **Velocity**<br>`\[m / s\]` | **Distance**<br>`\[m\]` |
|--------------------:|---------------------------------:|----------------------------:|------------------------:|
|                 0.0 |                              1.0 |                         0.0 |                     0.0 |
|                 1.0 |                              1.0 |                         1.0 |                     0.5 |
|                 2.0 |                              1.0 |                         2.0 |                     2.0 |
|                 3.0 |                              1.0 |                         3.0 |                     4.5 |
|                 4.0 |                              1.0 |                         4.0 |                     8.0 |
|                 5.0 |                              1.0 |                         5.0 |                  *12.5* |
|                 6.0 |                              1.0 |                         6.0 |                  *18.0* |
|                 7.0 |                              1.0 |                         7.0 |                  *24.5* |
|                 8.0 |                              1.0 |                         8.0 |                  *32.0* |
|                 9.0 |                              1.0 |                         9.0 |                  *40.5* |
|                10.0 |                              1.0 |                    **10.0** |                  *50.0* |
|                11.0 |                              1.0 |                    **11.0** |                  *60.5* |
|                12.0 |                              1.0 |                    **12.0** |                  *72.0* |
|                13.0 |                              1.0 |                    **13.0** |                  *84.5* |
|                14.0 |                              1.0 |                    **14.0** |                  *98.0* |
|                15.0 |                              1.0 |                    **15.0** |                 *112.5* |
|                16.0 |                              1.0 |                    **16.0** |                 *128.0* |
|                17.0 |                              1.0 |                    **17.0** |                 *144.5* |
|                18.0 |                              1.0 |                    **18.0** |                 *162.0* |
|                19.0 |                              1.0 |                    **19.0** |                 *180.5* |
|                20.0 |                              1.0 |                    **20.0** |                 *200.0* |
Time<br>\[s\]Acceleration<br>\[m / s²\]Velocity<br>\[m / s\]Distance<br>\[m\]
0.01.00.00.0
1.01.01.00.5
2.01.02.02.0
3.01.03.04.5
4.01.04.08.0
5.01.05.012.5
6.01.06.018.0
7.01.07.024.5
8.01.08.032.0
9.01.09.040.5
10.01.010.050.0
11.01.011.060.5
12.01.012.072.0
13.01.013.084.5
14.01.014.098.0
15.01.015.0112.5
16.01.016.0128.0
17.01.017.0144.5
18.01.018.0162.0
19.01.019.0180.5
20.01.020.0200.0