# \[ANN\] PrettyTables.jl - Print formatted tables in Julia

**URL:** <https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550>\
**Category:** Package Announcements\
**Created:** [January 12, 2019, 3:49am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550 "2019-01-12T03:49:21Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [January 12, 2019, 3:49am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/1 "2019-01-12T03:49:22Z")

</div>

Hi guys!

I want to announce a new package that I just submitted for registration. It is called `PrettyTables.jl`. The idea is to provide functionality to print data in tables in many formats. Currently, it supports only text tables like we have in the website [ASCII Table Generator – Quickly format ASCII table. Great for source code comments and markdown!](https://ozh.github.io/ascii-tables/)

I decided to code this package because I often need to print data in a human-readable format to analyze or to send to other people. You can see more about the package here: [GitHub - ronisbr/PrettyTables.jl: Print data in formatted tables.](https://github.com/ronisbr/PrettyTables.jl)

In the following, there are some examples of how the following data can be printed:

```julia-repl
julia> data = ["Col. 1" "Col. 2" "Col. 3" "Col. 4";
                     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 ;]

```

 ![fig00001](https://global.discourse-cdn.com/julialang/original/3X/0/8/082579603035166c9404efe0b1c50166c23d2026.png)

 ![fig00002](https://global.discourse-cdn.com/julialang/original/3X/8/d/8daabbfd4172982b83476087d844c1af1f448ca1.png)

 ![fig00003](https://global.discourse-cdn.com/julialang/original/3X/8/e/8e5318998de0e6c69349a1a295133c8f4ef81456.png)

 ![fig00004](https://global.discourse-cdn.com/julialang/original/3X/9/c/9c1245a7f9a22f299356d29c859cc4bb5d00946c.png)

 ![fig00005](https://global.discourse-cdn.com/julialang/original/3X/3/3/3325f650f4486e69e6e8272dc50de982d5db0cab.png)

I am planning to improve the package given the community feedback!

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [January 12, 2019, 4:04am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/2 "2019-01-12T04:04:39Z")

</div>

Nice!

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [January 12, 2019, 4:48am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/3 "2019-01-12T04:48:20Z")

</div>

Hi,

this is really nice package. If you are doing something complex like this, it would be great to have export to latex. We have just making fun with my colleagues that this is something all of as has written by themselves.

Another thing I would like would be highlighting of individual cells. For example to be able to highlight best value in a row. This is very useful when you are comparing different algorithms on different problems and you want to see, which one is the best one.

Thanks for a package,  
Tomas

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [January 12, 2019, 6:45am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/4 "2019-01-12T06:45:27Z")

</div>

You mean like

> **[GitHub - scheinerman/LatexPrint.jl: Print Julia objects in a form suitable...](https://github.com/scheinerman/LatexPrint.jl)**
>
> Print Julia objects in a form suitable for LaTeX mathematics mode. - GitHub - scheinerman/LatexPrint.jl: Print Julia objects in a form suitable for LaTeX mathematics mode.

?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 12, 2019, 7:12am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/5 "2019-01-12T07:12:09Z")

</div>

And [https://github.com/korsbo/Latexify.jl](https://github.com/korsbo/Latexify.jl)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 12, 2019, 10:00am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/6 "2019-01-12T10:00:44Z")

</div>

The dataframe printer is quite similar:

```julia
julia> DataFrame(Col1 = 1:6, Col2 = [false, true, false, true, false, true], Col3 = 1.0:6.0, Col4 = 0x01:0x06)
6×4 DataFrame
│ Row │ Col1 │ Col2 │ Col3 │ Col4 │
│ │ Int64 │ Bool │ Float64 │ UInt8 │
├─────┼───────┼───────┼─────────┼───────┤
│ 1 │ 1 │ false │ 1.0 │ 0x01 │
│ 2 │ 2 │ true │ 2.0 │ 0x02 │
│ 3 │ 3 │ false │ 3.0 │ 0x03 │
│ 4 │ 4 │ true │ 4.0 │ 0x04 │
│ 5 │ 5 │ false │ 5.0 │ 0x05 │
│ 6 │ 6 │ true │ 6.0 │ 0x06 │

```

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 12, 2019, 10:47am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/7 "2019-01-12T10:47:28Z")

</div>

or [GitHub - jacobadenbaum/TexTables.jl: Publication quality regression and statistical tables](https://github.com/jacobadenbaum/TexTables.jl)

---

<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:** [January 12, 2019, 11:16am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/8 "2019-01-12T11:16:43Z")

</div>

But DataFrames.jl does not allow to change to alignments of the cells, the format of the numbers that will be print, the color, etc. I see DataFrames as a container to store data. This simple package is just a “printer” for data.

For example, when I try to use DataFrames to do this, the headers of the tables cannot have spaces. Hence I decided to do something that is supposed only to print data of matrices. Makes sense?

---

<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:** [January 12, 2019, 11:18am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/9 "2019-01-12T11:18:59Z")

</div>

Good point!

What will be better: add some options like `highlight_lowest`, etc. or let the users control which cells they want to highlight using a matrix?

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [January 12, 2019, 11:51am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/10 "2019-01-12T11:51:17Z")

</div>

You can have names with spaces, you just have to do `Symbol("Name with multiple spaces)`

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [January 12, 2019, 12:20pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/11 "2019-01-12T12:20:49Z")

</div>

> [@Ronis\_BR](#):
>
> I see DataFrames as a container to store data. This simple package is just a “printer” for data.

Yes. Using `DataFrames`, or worse depending on it, just to view your data is unpleasant.

```julia
julia> @time using DataFrames
  4.812422 seconds (11.94 M allocations: 620.775 MiB, 8.39% gc time)

```

```julia
julia> @time using PrettyTables
  0.149606 seconds (181.03 k allocations: 11.123 MiB, 11.44% gc time)

```

But, having an alternative `DataFrames`-like interface would make it easier for people to learn to use it.

---

<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:** [January 12, 2019, 1:22pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/12 "2019-01-12T13:22:59Z")

</div>

Thanks!

Let me understand: do you mean create an interface to print DataTables or to add a interface equal to DataTables to print the information, so that we do not depend on DataTables?

---

<div class="post-metadata">

**Author:** ![elshera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elshera/32/6638_2.png) [@elshera](https://discourse.julialang.org/u/elshera)\
**Post date:** [January 12, 2019, 1:51pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/13 "2019-01-12T13:51:04Z")

</div>

This is very nice. Especially as table formats around have no good printing methods. Sometime I need to have data-frames only to get this functionalities and not for the processing of data. It means I do not have to do it anymore ? What functionalities do you want to offer with PrettyTables ?

From the other side, I am seeing lot of different table formats each trying to do same things. Somehow all this available Packages are generating confusion. Maybe this is due to my lower experience in Julia but I would assume it would be the same for other programming languages too.

Some consolidation of what is around feels to be necessary. Collecting the best features of different packages and having to import the wrapper packages which till take care of picking up the right functionalities.

---

<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:** [January 12, 2019, 3:29pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/14 "2019-01-12T15:29:36Z")

</div>

> [@elshera](#):
>
> This is very nice. Especially as table formats around have no good printing methods. Sometime I need to have data-frames only to get this functionalities and not for the processing of data. It means I do not have to do it anymore ? What functionalities do you want to offer with PrettyTables ?

This is due to a necessity I have. I need to print on the screen or save in a file the data of a table in a human-readable format. I also often need to print the data formatted, like with 3 decimal digits. This is what I want this package to do.

I am not planning to add functionality to compute things, like DataFrames.jl have, like mean, standard deviation, etc. I want that this package remains simple to just print data on screen or save on text files.

Anyway, I am open to the community feedback!

> [@elshera](#):
>
> From the other side, I am seeing lot of different table formats each trying to do same things. Somehow all this available Packages are generating confusion. Maybe this is due to my lower experience in Julia but I would assume it would be the same for other programming languages too.

This is not like the same, each one has its good and bad side. IMHO, I like diversity in open-source environment (not duplication). It helps to improve the language. What you should do is to download and try to see what fits you best 🙂

> [@elshera](#):
>
> Some consolidation of what is around feels to be necessary. Collecting the best features of different packages and having to import the wrapper packages which till take care of picking up the right functionalities.

If you find something that would be nice to add to a package that is already provided in another, then you can submit a PR or open an issue at this package to discuss the matter with the maintainers.

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [January 12, 2019, 3:31pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/15 "2019-01-12T15:31:17Z")

</div>

> [@Ronis\_BR](#):
>
> Let me understand: do you mean create an interface to print DataTables or to add a interface equal to DataTables to print the information, so that we do not depend on DataTables?

I think I mean something like the second option:

```julia
import PrettyTables.pretty_table

function pretty_table(columns::AbstractVector{<:AbstractVector},
                      cnames::AbstractVector{Symbol})
    pretty_table(vcat(reshape(cnames, 1, :), Base.typed_hcat(Any, columns...)))
end

```

```julia
julia> pretty_table([rand(2), rand(Bool, 2), [:x, :y]], [:a, :b, :c])
┌─────────────────────┬──────┬───┐
│ a │ b │ c │
├─────────────────────┼──────┼───┤
│ 0.8906227251914487 │ true │ x │
│ 0.39124822148078553 │ true │ y │
└─────────────────────┴──────┴───┘

```

Or using keyword options or something like that.

---

<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:** [January 12, 2019, 3:31pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/16 "2019-01-12T15:31:51Z")

</div>

Perfect! I can add it! 🙂

---

<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:** [January 12, 2019, 4:38pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/17 "2019-01-12T16:38:52Z")

</div>

I really liked your suggestion. I have added support to what I called `Highlighter`. It is a structure that has three fields:

- `f`: A function `f(data,i,j)` that should return `true` if the element `(i,j)` must be highlighted or `false` otherwise.
- `bold`: If the highlight style should be **bold**.
- `color`: The color of the highlight style.

Then we can have multiple highlight styles like in this example, in which I mark the maximum (blue) and minimum (red) values of the table considering the columns 1, 3, and 4:

 ![fig00006](https://global.discourse-cdn.com/julialang/original/3X/8/2/827dce655a7f35743d152d42a74a5ab61341ff33.png)

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [January 12, 2019, 5:47pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/18 "2019-01-12T17:47:49Z")

</div>

Two questions (easily verifiable but I can’t test right now).

Does this implement the table interface (I believe `TableTraits` that many table packages use? I.e. if I put a `DataFrame` through this, will it pretty print?

In your code, I see you are using `using Parameters`, are you using any of the features that `Parameters`? As far as I know, `@with_kw` is now being tested in `stdlib`.

---

<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:** [January 12, 2019, 5:51pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/19 "2019-01-12T17:51:58Z")

</div>

I was just advised by @dave.f.kleinschmidt to do precisely this!

And yes, I am using Parameters because it is way better if you want to take a pre-defined format and change just one thing.

---

<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:** [January 13, 2019, 12:35am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/20 "2019-01-13T00:35:10Z")

</div>

Ok, now we have an initial interface with Tables.jl. Thus, we can now pretty print DataFrames.jl. However, I am no expert on this API. Can anyone please test with other packages?

 ![fig00007](https://global.discourse-cdn.com/julialang/original/3X/e/2/e2ccc18a38107c9b3771e38425e62daa88bdf788.png)

[Next page](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550.md?page=2)
