Open nathanrboyer opened 11 months ago
Hi @nathanrboyer
AFAIK there is no way to set a title in a markdown table natively.
Can it just be text above the table?
<u>**This is the Table Title**</u>
| **Variable** | **Region 1** |
| ------------:| --------------:|
| Coeff. x⁰ | A₀₁ = 40.712 |
| Coeff. x¹ | A₁₁ = -227.349 |
| Coeff. x² | A₂₁ = 586.517 |
| Coeff. x³ | A₃₁ = -660.275 |
| Coeff. x⁴ | A₄₁ = 283.234 |
| Thickness | t₁ = 14.625 |
I am not sure because it will not behave like a table title in LaTeX and HTML when rendered.
Okay, I have table metadata that I need to include and am trying to figure out a good way to do that with markdown. Right now I am just using the title and text backend:
function print_polyfit_table(io::IO, table::DataFrame, title::String)
subtitle = "t₀ = " * metadata(table, "t₀") *
"\n" *
"RMSE = " * metadata(table, "RMSE") *
"\n" *
"knots = " * metadata(table, "knots")
pretty_table(io,
table,
show_subheader = false,
title = title * "\n" * subtitle,
backend = Val(:text),
)
println(io, "")
end
Primary Stress
t₀ = 14.625 in
RMSE = 0.240 ksi
knots = [1, 4, 12, 147, 202]
┌───────────┬───────────────────┬────────────────┬──────────────┬───────────────┐
│ Variable │ Region 1 │ Region 2 │ Region 3 │ Region 4 │
├───────────┼───────────────────┼────────────────┼──────────────┼───────────────┤
│ Coeff. x⁰ │ A₀₁ = 87.471 │ A₀₂ = 47.026 │ A₀₃ = 31.403 │ A₀₄ = 301.952 │
│ Coeff. x¹ │ A₁₁ = -853.201 │ A₁₂ = -103.200 │ A₁₃ = -7.569 │ A₁₄ = -69.854 │
│ Coeff. x² │ A₂₁ = 5,335.199 │ A₂₂ = 166.363 │ A₂₃ = 0.744 │ A₂₄ = 5.424 │
│ Coeff. x³ │ A₃₁ = -11,912.133 │ A₃₂ = -89.308 │ A₃₃ = -0.020 │ A₃₄ = -0.134 │
│ Thickness │ t₁ = 0.218 │ t₂ = 0.582 │ t₃ = 9.823 │ t₄ = 4.002 │
└───────────┴───────────────────┴────────────────┴──────────────┴───────────────┘
Residual Stress
t₀ = 14.625 in
RMSE = 0.132 ksi
knots = [1, 4, 12, 147, 202]
┌───────────┬──────────────────┬────────────────┬──────────────┬───────────────┐
│ Variable │ Region 1 │ Region 2 │ Region 3 │ Region 4 │
├───────────┼──────────────────┼────────────────┼──────────────┼───────────────┤
│ Coeff. x⁰ │ A₀₁ = -28.501 │ A₀₂ = -42.186 │ A₀₃ = 1.296 │ A₀₄ = -57.375 │
│ Coeff. x¹ │ A₁₁ = 393.535 │ A₁₂ = 254.269 │ A₁₃ = -0.212 │ A₁₄ = 13.936 │
│ Coeff. x² │ A₂₁ = -3,015.405 │ A₂₂ = -452.254 │ A₂₃ = 0.025 │ A₂₄ = -1.104 │
│ Coeff. x³ │ A₃₁ = 7,754.286 │ A₃₂ = 254.282 │ A₃₃ = -0.002 │ A₃₄ = 0.028 │
│ Thickness │ t₁ = 0.218 │ t₂ = 0.582 │ t₃ = 9.823 │ t₄ = 4.002 │
└───────────┴──────────────────┴────────────────┴──────────────┴───────────────┘
The pretty_table
docstring does have title
listed in the top section of keyword arguments, which I thought meant it would work for all backends.
Okay, I have table metadata that I need to include and am trying to figure out a good way to do that with markdown. Right now I am just using the title and text backend:
In Markdown, the best way would be rendering the table to a string: pretty_table(String, ...)
and concatenating the information as you like.
The pretty_table docstring does have title listed in the top section of keyword arguments, which I thought meant it would work for all backends.
Yes, this is something we have to change if we decide that a title is not suitable for Markdown.
It looks like Quarto and Pandoc have syntax for markdown table captions, which is simply a colon underneath the table. It might be worth supporting that with title
.
Refs: https://quarto.org/docs/authoring/tables.html https://forum.obsidian.md/t/captions-for-tables-in-markdown/17240/4
The problem of supporting features that are not in the standard is that people will not get the desired effect if they past the tables, for example, here in Github or in https://markdownlivepreview.com
Hi @nathanrboyer !
I propose to let this open! I am not sure yet the best approach, let's see if anyone can bring more information for us. I really want to support titles in Markdown, I am not sure what is the optimal way to do so.
Sounds good. Well, the nice thing about markdown is that it still looks pretty good even if some elements aren't completely transformed, so I don't think people will get too upset. The example from the Quarto documentation looks like this here on Github:
Default | Left | Right | Center |
---|---|---|---|
12 | 12 | 12 | 12 |
123 | 123 | 123 | 123 |
1 | 1 | 1 | 1 |
: Demonstration of pipe table syntax
If you want to support multiple standards, then that may just need to be a new markdown-specific keyword argument:
title_style = :above # over the table with no extra formatting
title_style = :below # under the table with no extra formatting
title_style = :pandoc # under the table with a colon at the beginning
title_style = :multimarkdown # under the table surrounded by brackets
Yes! Probably we can add a keyword to change the style (not only for the title, but maybe for other features as well).
Switching from the
:text
to:markdown
backend yielded mostly the same table, except my title was removed.