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. 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 |
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"]
)| ID | Flag | Value | Hex |
|---|---|---|---|
| 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 |
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. 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 |
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. 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 |
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 || 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 |
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 || 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 |
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.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 |