# Column of Pretty Tables tables and a plot to a png file

**URL:** <https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 31, 2025, 1:36pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577 "2025-10-31T13:36:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arby111](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Arby111](https://discourse.julialang.org/u/Arby111)\
**Post date:** [October 31, 2025, 1:36pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/1 "2025-10-31T13:36:39Z")

</div>

Hello,  
Does anyone know how to write a column of, say, three small Pretty Tables tables followed by a plot to a png file with mankie.jl or with some other tool?  
Thanks

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 31, 2025, 6:45pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/2 "2025-10-31T18:45:20Z")

</div>

You mean you want to put a table inside a Makie plot? I once made this but didn’t merge it [Makie table extension by jkrumbiegel · Pull Request #24 · PumasAI/SummaryTables.jl · GitHub](https://github.com/PumasAI/SummaryTables.jl/pull/24)

But in principle, yeah, you can build a table with GridLayout, Label and Box

---

<div class="post-metadata">

**Author:** ![technocrat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/technocrat/32/220947_2.png) [@technocrat](https://discourse.julialang.org/u/technocrat)\
**Post date:** [October 31, 2025, 9:28pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/3 "2025-10-31T21:28:49Z")

</div>

```julia-auto
using CairoMakie
table_text = DataFrame(
    Category = ["All Counties", "Served Counties", "Served Population"],
    Count = [all_counties, served_counties, served_population],
    Percentage = ["100%", percentage_counties_served, percentage_served_population]
)
io = IOBuffer()
pretty_table(io, table_text; backend=:text, alignment=[:l, :r, :r], show_first_column_label_only = true)
str_table = String(take!(io))

```

Then just place it in a Figure object.

```julia-auto
f = Figure()
ax = Axis()
Label(axis, str_table, font="IBM Plex Mono", fontsize=10, justification=:left, halign=:left, valign=:bottom)
save("output.png", f)

```

Use GridLayout() to arrange multiple tables.

 ![complete_plot](https://global.discourse-cdn.com/julialang/original/3X/7/7/770337848b7ae79263defac6c5b1c3aac027fc99.jpeg)

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [November 1, 2025, 7:32pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/4 "2025-11-01T19:32:46Z")

</div>

This is a cool idea. @Ronis_BR if someone wanted to make a Makie backend for PrettyTables.jl is there a certain list of methods that need to be implemented?

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [November 2, 2025, 5:46pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/5 "2025-11-02T17:46:01Z")

</div>

I have no idea! However, PrettyTables.jl renders to HTML, would it suffice to embed the HTML table inside the Makie plot?

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [November 2, 2025, 5:51pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/6 "2025-11-02T17:51:28Z")

</div>

Hi @technocrat !

This was an awesome use for PrettyTables.jl! If you do not want to use DataFrames.jl, you can simplify the code as follows:

```julia
data = [
    "All Counties" all_counties "100%"
    "Served Counties" served_counties served_population
    "Served Population" served_population percentage_served_population
]

column_labels = ["Category", "Count", "Percentage"]

str_table = pretty_table(String, table_text; alignment = [:l, :r, :r], column_labels = column_labels)

```

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [November 2, 2025, 6:11pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/7 "2025-11-02T18:11:05Z")

</div>

I wonder if there could be an interface for PrettyTables backends, so that users could write extensions for their own targets by just implementing a certain well-defined set of things. I can imagine people wanting backends for any number of document formats.

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [November 4, 2025, 11:45am UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/8 "2025-11-04T11:45:32Z")

</div>

The internal structure is not very organized right now to allow for external back ends. This is something I plan to do eventually.

---

<div class="post-metadata">

**Author:** ![technocrat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/technocrat/32/220947_2.png) [@technocrat](https://discourse.julialang.org/u/technocrat)\
**Post date:** [November 4, 2025, 7:04pm UTC](https://discourse.julialang.org/t/column-of-pretty-tables-tables-and-a-plot-to-a-png-file/133577/9 "2025-11-04T19:04:13Z")

</div>

@Ronis_BR Great “less is more improvement.” I tried to do it without PrettyTable.jl either, but had to rely on TOML.Parser().

```julia-auto
headers = ["Name", "Age", "City"]
rows = [["Alice", "25", "New York"], 
        ["Bob", "30", "Chicago"],
        ["Carol", "22", "Boston"]]
table = format_table_as_text(headers, rows)
println(table)

```

```julia-auto
┌───────┬────┬──────────┐
│Name │Age │City │
├───────┼────┼──────────┤
│Alice │25 │New York │
│Bob │30 │Chicago │
│Carol │22 │Boston │
└───────┴────┴──────────┘

```

“”"  
format\_table\_as\_text(headers::Vector{String}, rows::Vector{Vector{String}}, padding::Int=2)

Format data as an ASCII table with borders and proper column alignment.

# Arguments

- `headers::Vector{String}`: Column header names
- `rows::Vector{Vector{String}}`: Data rows, where each row is a vector of strings
- `padding::Int=2`: Additional padding space around each cell (default: 2)

# Returns

- `String`: Formatted ASCII table with Unicode box-drawing characters  
# Examples

```julia
headers = ["Name", "Age", "City"]
rows = [["Alice", "25", "New York"], 
        ["Bob", "30", "Chicago"],
        ["Carol", "22", "Boston"]]
table = format_table_as_text(headers, rows)
\# Returns a formatted table with borders and proper alignment
\# Notes
- Uses Unicode box-drawing characters (┌─┬─┐│├─┼─┤└─┴─┘)
- Automatically calculates column widths based on content
- Each cell is padded for consistent spacing
- Useful for creating publication-ready ASCII tables
"""
function format_table_as_text(headers::Vector{String}, rows::Vector{Vector{String}}, 
    padding::Int=2)
    parser = Parser()
    all_rows = [headers; rows]

    # Calculate column widths
    col_widths = Int[]
    for col in 1:length(headers)
    max_width = maximum(length(row[col]) for row in all_rows)
    push!(col_widths, max_width + padding)
    end

    # Format rows
    formatted_lines = String[]

    # Header
    header_line = join([rpad(headers[i], col_widths[i]) for i in 1:length(headers)], "│")
    push!(formatted_lines, "│" * header_line * "│")

    # Separator
    separator = "├" * join([repeat("─", col_widths[i]) for i in 1:length(headers)], "┼") * "┤"
    push!(formatted_lines, separator)

    # Data rows
    for row in rows
    data_line = join([rpad(row[i], col_widths[i]) for i in 1:length(row)], "│")
    push!(formatted_lines, "│" * data_line * "│")
    end

    # Top and bottom borders
    top_border = "┌" * join([repeat("─", col_widths[i]) for i in 1:length(headers)], "┬") * "┐"
    bottom_border = "└" * join([repeat("─", col_widths[i]) for i in 1:length(headers)], "┴") * "┘"

    return join([top_border, formatted_lines..., bottom_border], "\n")
end

export format_table_as_text
```
