# \[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:** 2

<div class="post-metadata">

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

</div>

That is a nice package @Ronis_BR! Thanks!

Would it make sense to have it as a dependency in DataFrames.jl and use it there? The current print methods in DataFrames.jl aren’t that flexible.

cc: @bkamins

---

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

</div>

> [@juliohm](#):
>
> Would it make sense to have it as a dependency in DataFrames.jl and use it there? The current print methods in DataFrames.jl aren’t that flexible.

That crossed my mind, too. But, I think it’s more ambitious than `PrettyTables` is at the moment. The right way to go about it would be to define a generic interface for printing table-like things with `PrettyTables`. In fact it would probably be fairly easy to make minor changes to `DataFrames` to allow it to work with a `PrettyDataFrames` glue package, so people can try it out and see if it is strongly preferred.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [January 13, 2019, 4:02pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/23 "2019-01-13T16:02:10Z")

</div>

I think the right approach is not to have PrettyTables.jl as a dependency in DataFrames.jl, but change DataFrames.jl in such a way that PrettyTables.jl can overwrite the default printing.

If I understand you correctly this is exactly what you propose - right @jlapeyre?

If yes - what would be the changes needed in DataFrames.jl to follow this path?

Or maybe in general it should be `Tables.jl` not `DataFrames.jl` to be even more flexible.

---

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

</div>

> [@bkamins](#):
>
> right @jlapeyre?

Yes, that’s exactly what I was thinking about. I guess a glue package between `PrettyTables` and `Tables` would be the most useful. I don’t know enough to details to say more. It makes sense to offload the display code for tables, like eg. using `CSV` for saving/reading.

This might be drifting from what `PrettyTables` was meant to be.

But, if it were to work, I guess such an interface would be _very_ widely appreciated.

---

<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, 7:47pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/25 "2019-01-13T19:47:23Z")

</div>

Maybe the best approach is provide a way to “register” in Tables.jl a printing system. Then the users can select whatever they want by loading the specific package that will register itself using this API. PrettyTables.jl was thought to be a printing system for Text tables, we have others for LaTeX, etc.

---

<div class="post-metadata">

**Author:** ![LaszloH](https://avatars.discourse-cdn.com/v4/letter/l/fbc32d/32.png) [@LaszloH](https://discourse.julialang.org/u/LaszloH)\
**Post date:** [January 13, 2019, 11:59pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/26 "2019-01-13T23:59:10Z")

</div>

One can print quite nice tables with just 30-odd lines of Julia code, as in

> [Show ASCII table - Rosetta Code](http://rosettacode.org/wiki/Show_Ascii_table#Julia)

---

<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 14, 2019, 12:45am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/27 "2019-01-14T00:45:18Z")

</div>

OK guys, I bring updates!

Now we have a documentation (even an icon! 🎉), which can be accessed [here](http://ronisbr.github.io/PrettyTables.jl/latest/).

I also did some modifications, as the introduction of what I called sub-headers. Basically, you can now have multiple lines in the header to add information such as the unit of the data:

 ![welcome_figure](https://global.discourse-cdn.com/julialang/original/3X/1/4/1433cec5eec3352c6ce619d42e0cdfe0c2a391c8.jpeg)

Using this, PrettyTables.jl can now print DataFrames.jl showing the types (as the default print system of DataFrames.jl does).

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

Now my next steps should be:

- Wait for the package be approved on METADATA.jl 😅
- Figure out what to do when the data is too wide to fit the screen (ideas?)

---

<div class="post-metadata">

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

</div>

How do I add your package PrettyTables.jl

```julia
julia> 
$ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.0.3 (2018-12-18)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia>]

(v1.0) pkg> add PrettyTables
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
ERROR: The following package names could not be resolved:
 * PrettyTables (not found in project, manifest or registry)
Please specify by known `name=uuid`.

```

Please help.

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [January 14, 2019, 4:52am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/29 "2019-01-14T04:52:42Z")

</div>

try

```julia
] add https://github.com/ronisbr/PrettyTables.jl

```

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [January 14, 2019, 5:03am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/30 "2019-01-14T05:03:47Z")

</div>

> [@tlienart](#):
>
> add [GitHub - ronisbr/PrettyTables.jl: Print data in formatted tables.](https://github.com/ronisbr/PrettyTables.jl)

I think it worked. I will find out soon

```julia
julia> 
$ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.0.3 (2018-12-18)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia>]

(v1.0) pkg> add https://github.com/ronisbr/PrettyTables.jl
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Cloning git-repo `https://github.com/ronisbr/PrettyTables.jl`
  Updating git-repo `https://github.com/ronisbr/PrettyTables.jl`
 Resolving package versions...
 Installed DataStructures ─── v0.15.0
 Installed NearestNeighbors ─ v0.4.3
  Updating `~/.julia/environments/v1.0/Project.toml`
  [bf2635c2] + PrettyTables v0.1.0 #master (https://github.com/ronisbr/PrettyTables.jl)
  Updating `~/.julia/environments/v1.0/Manifest.toml`
  [864edb3b] ↑ DataStructures v0.14.0 ⇒ v0.15.0
  [b8a86587] ↑ NearestNeighbors v0.4.2 ⇒ v0.4.3
  [bf2635c2] + PrettyTables v0.1.0 #master (https://github.com/ronisbr/PrettyTables.jl)

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 ;]
7×4 Array{Any,2}:
  "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   

julia> pretty_table(data)
ERROR: UndefVarError: pretty_table not defined
Stacktrace:
 [1] top-level scope at none:0

julia> using PrettyTables
[Info: Precompiling PrettyTables [bf2635c2-15c2-11e9-0b27-5fb50ccc2906]

julia> pretty_table(data)
┌────────┬────────┬────────┬────────┐
│ Col. 1 │ Col. 2 │ Col. 3 │ Col. 4 │
├────────┼────────┼────────┼────────┤
│ 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 │
└────────┴────────┴────────┴────────┘

```

It worked. Thank you.

---

<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 14, 2019, 6:00am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/31 "2019-01-14T06:00:23Z")

</div>

This is excellent. I really like the generality of an API. This is great for visualization of results.

---

<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 14, 2019, 9:31am UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/32 "2019-01-14T09:31:24Z")

</div>

This will work as soon as it gets accepted in METADATA!

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [January 14, 2019, 8:59pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/33 "2019-01-14T20:59:28Z")

</div>

Looks nice – I’ll try it soon. Question: someone suggested that it would be great if it is possible to “LaTeXify” the table, i.e., so that we can paste the table into a LaTeX document. Is that something that might be possible?

---

<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 14, 2019, 9:19pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/34 "2019-01-14T21:19:53Z")

</div>

If you read the thread you will find 2 options for 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 15, 2019, 2:14pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/35 "2019-01-15T14:14:34Z")

</div>

Package was accepted and updated!

Now you can install it by typing `]add PrettyTables`.

I would love some feedback! I am expecting lots of bugs…

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 15, 2019, 4:14pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/36 "2019-01-15T16:14:12Z")

</div>

Very useful !  
Does it make sense to add limiter (like in print\_matrix) ?

---

<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 15, 2019, 6:05pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/37 "2019-01-15T18:05:35Z")

</div>

> [@LaurentPlagne](#):
>
> Very useful !  
> Does it make sense to add limiter (like in print\_matrix) ?

Thanks! I do not know. Maybe it will be nice to add a limit when the screen is not big enough to fit the data. But then I think this is a package to print data and not create data, then is it useful to omit data?

It is a good discussion… what do you think?

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [January 15, 2019, 6:33pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/38 "2019-01-15T18:33:22Z")

</div>

I found the output so nice that I was considering to use it as the default output for my own ND-Array struct…  
In this case the limit makes sense (I use print\_matrix right now). I understand that this use case is a bit out of the primary scope of your package 😉

---

<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 15, 2019, 6:42pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/39 "2019-01-15T18:42:36Z")

</div>

Ah, Good! I see. Well, then yes 🙂 I will see if I can do such limit.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [January 15, 2019, 9:34pm UTC](https://discourse.julialang.org/t/ann-prettytables-jl-print-formatted-tables-in-julia/19550/40 "2019-01-15T21:34:15Z")

</div>

Thanks – I assume you refer to the suggestions (1) LatexPrint, (2) Latexify, and (3) TexTables. What I meant by my questions was more whether it is possible to pipe the result of PrettyTables into, say, Latexify – which might be interesting if PrettyTables has more (or rather: simpler) control of the layout/typesetting. Anyway, I’ll check around a little.

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

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