|
| 1 | +# Markdown Backend Examples |
| 2 | + |
| 3 | +```@meta |
| 4 | +CurrentModule = PrettyTables |
| 5 | +``` |
| 6 | + |
| 7 | +```@setup markdown_examples |
| 8 | +using PrettyTables |
| 9 | +``` |
| 10 | + |
| 11 | +Here, we can see some examples of text tables generated by PrettyTables.jl. The `A` object, |
| 12 | +when referenced, is defined as: |
| 13 | + |
| 14 | +```julia-repl |
| 15 | +julia> A = Any[ |
| 16 | + 1 false 1.0 0x01 |
| 17 | + 2 true 2.0 0x02 |
| 18 | + 3 false 3.0 0x03 |
| 19 | + 4 true 4.0 0x04 |
| 20 | + 5 false 5.0 0x05 |
| 21 | + 6 true 6.0 0x06 |
| 22 | +] |
| 23 | +``` |
| 24 | + |
| 25 | +```@setup markdown_examples |
| 26 | +A = Any[ |
| 27 | + 1 false 1.0 0x01 |
| 28 | + 2 true 2.0 0x02 |
| 29 | + 3 false 3.0 0x03 |
| 30 | + 4 true 4.0 0x04 |
| 31 | + 5 false 5.0 0x05 |
| 32 | + 6 true 6.0 0x06 |
| 33 | +] |
| 34 | +``` |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +```@example markdown_examples |
| 39 | +pretty_table(A; backend = :markdown) |
| 40 | +``` |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +```@example markdown_examples |
| 45 | +pretty_table( |
| 46 | + A; |
| 47 | + backend = :markdown, |
| 48 | + style = MarkdownTableStyle(first_column_label = MarkdownStyle(italic = true)) |
| 49 | +) |
| 50 | +``` |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +```@example markdown_examples |
| 55 | +data = [ |
| 56 | + 10.0 6.5 |
| 57 | + 3.0 3.0 |
| 58 | + 0.1 1.0 |
| 59 | +] |
| 60 | +
|
| 61 | +row_labels = [ |
| 62 | + "Atmospheric drag" |
| 63 | + "Gravity gradient" |
| 64 | + "Solar radiation pressure" |
| 65 | +] |
| 66 | +
|
| 67 | +column_labels = [ |
| 68 | + [MultiColumn(2, "Value", :c)], |
| 69 | + [ |
| 70 | + "Torque [10⁻⁶ Nm]", |
| 71 | + "Angular Momentum [10⁻³ Nms]" |
| 72 | + ] |
| 73 | +] |
| 74 | +
|
| 75 | +pretty_table( |
| 76 | + data; |
| 77 | + backend = :markdown, |
| 78 | + column_labels, |
| 79 | + merge_column_label_cells = :auto, |
| 80 | + row_labels, |
| 81 | + stubhead_label = "Effect", |
| 82 | + summary_row_labels = ["Total"], |
| 83 | + summary_rows = [(data, i) -> sum(data[:, i])], |
| 84 | +) |
| 85 | +``` |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +```@example markdown_examples |
| 90 | +t = 0:1:20 |
| 91 | +
|
| 92 | +data = hcat(t, ones(length(t) ), t, 0.5.*t.^2); |
| 93 | +
|
| 94 | +column_labels = [ |
| 95 | + ["Time", "Acceleration", "Velocity", "Distance"], |
| 96 | + [ "[s]", "[m / s²]", "[m / s]", "[m]"] |
| 97 | +] |
| 98 | +
|
| 99 | +hl_p = MarkdownHighlighter( |
| 100 | + (data, i, j) -> (j == 4) && (data[i, j] > 9), |
| 101 | + MarkdownStyle(italic = true) |
| 102 | +) |
| 103 | +
|
| 104 | +hl_v = MarkdownHighlighter( |
| 105 | + (data, i, j) -> (j == 3) && (data[i, j] > 9), |
| 106 | + MarkdownStyle(bold = true) |
| 107 | +) |
| 108 | +
|
| 109 | +pretty_table( |
| 110 | + data; |
| 111 | + backend = :markdown, |
| 112 | + column_labels = column_labels, |
| 113 | + highlighters = [hl_p, hl_v], |
| 114 | +) |
| 115 | +``` |
0 commit comments