# Markdown tables

**URL:** https://discourse.julialang.org/t/markdown-tables/11385
**Category:** General Usage
**Tags:** question, package, proposal, markdown
**Created:** [June 3, 2018, 12:51pm UTC](https://discourse.julialang.org/t/markdown-tables/11385 "2018-06-03T12:51:17Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 3, 2018, 12:51pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/1 "2018-06-03T12:51:17Z")

</div>

Is anyone sitting on or thinking of building an implementation to parse arrays (e.g. `Matrix`, `DataFrame`, `AbstractArray`, etc.) into markdown tables (specifically one of the four table formats described in [pandoc’s documentation](http://pandoc.org/MANUAL.html#tables): `simple_tables`, `multiline_tables`, `grid_tables`, and `pipe_tables`)?

This has been discussed to some extent elsewhere ([show-is-too-low-level](https://discourse.julialang.org/t/show-is-too-low-level/7531), [best-tool-for-printing-tables](https://discourse.julialang.org/t/best-tool-for-printing-tables-in-jupyter-notebook/3548), [pretty-printing-of-tables](https://discourse.julialang.org/t/pretty-printing-of-tables/7254), and [ann-regressiontables-jl](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516)), it seems like something a lot of people need, and I’m sure it’s been partly and separately re/implemented in various un/registered packages.

Here’s my puny baaaaare bones first effort: [https://github.com/yakir12/MDtables.jl](https://github.com/yakir12/MDtables.jl) (now with GridedTables as well)

Should we have a package for printing markdown tables of `T <: AbstractArray`s?

---

<div class="post-metadata">

### Author: ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)
#### Post date: [June 3, 2018, 1:59pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/2 "2018-06-03T13:59:33Z")

</div>

Has Weave already dealt with this? I couldn’t really tell but there’s this:

[https://github.com/mpastell/Weave.jl/issues/125](https://github.com/mpastell/Weave.jl/issues/125)

And DataFrames already does some basic table formatting?

But a pandoc tables package for the REPL/weave/whatever else with would be good. Something like pander in R but it may as well be useful everywhere.

AxisArrays etc. methods could add row and column labels…

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 3, 2018, 2:02pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/3 "2018-06-03T14:02:20Z")

</div>

I agree with everything you said. IMHO, It’s one of those things that are mildly needed in many different cases and would benefit from a centralized single solution.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 3, 2018, 3:51pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/4 "2018-06-03T15:51:42Z")

</div>

Right, so I added `grid_tables` as well, and I wanted to be able to have multi-line cells, but I see now that this isn’t utterly trivial (for me). Will keep hacking at it at some point, but if anyone wants to pick up the ball, be my guest!

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 3, 2018, 8:14pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/5 "2018-06-03T20:14:30Z")

</div>

Can you spec this out a little bit?

Are you just asking for people to print any 2-D array to html in some table format?

// then the hard part comes in adapting anything to a 2-D array?

* * *

**edit:** or is there some `lpad`’ing and texty stuff you want done to it too?

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 3, 2018, 8:23pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/6 "2018-06-03T20:23:26Z")

</div>

I’m working it now. I agree, there’s hardly anything there now…

My ultimate use-case is:

1. Produce some numbers, url links, and strings from some input.
2. Populate a String array with those.
3. Some of these strings in that table will have `'\n'` newlines in them (to make the final cells a little less wide).
4. Convert this array to a markdown table.
5. Insert it to a larger markdown template document (using `Mustache.jl`).
6. Use `pandoc` to convert it all to: html (webpage), html (email), and pdf.

So I don’t care what the markdown code ends up looking like. For instance I actually don’t care about the distinction of how simple\_tables, multiline\_tables, grid\_tables, and pipe\_tables all look differently in markdown. That’s because the end `pandoc`ed result looks the same no matter what. I **do** care about the distinction that grid\_tables for instance can take multiline cells.

My implementation looks very different than what’s online right now…

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 3, 2018, 8:27pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/7 "2018-06-03T20:27:06Z")

</div>

Are you going to be happy with the end result? The newline hack sounds like it’s going to be touchy.

Why not just do HTML all the way down and use CSS to get you to the goal line? (i.e. `max-width`, `flex`, etc.)

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 3, 2018, 8:30pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/8 "2018-06-03T20:30:16Z")

</div>

I am crappy in that domain (HTML, CSS). But what do you mean, pandoc the html to pdf? In any case, I feel I’m doing good by finally building a markdown printer for arrays…

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 3, 2018, 8:32pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/9 "2018-06-03T20:32:00Z")

</div>

Wasn’t attacking! Just trying to spitball. Think it’s cool there’ll be a tool for this 🙂

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 3, 2018, 8:32pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/10 "2018-06-03T20:32:44Z")

</div>

Lord, didn’t think you were 🙂  
Please spit away! I was so happy to see anyone even responding to this…

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [June 3, 2018, 8:33pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/11 "2018-06-03T20:33:47Z")

</div>

I don’t know if this is a valid option for you, but my advice based on experience is stay away from anything but _very_ simple tables in markdown. They are easily broken, and sometimes don’t display the same way everywhere when they should. My advice would be to stick to LaTeX if possible which pandoc will convert much more reliably.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 3, 2018, 8:35pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/12 "2018-06-03T20:35:30Z")

</div>

So you mean, populate a LaTeX (which I am comfortable) template and _then_ convert it with pandoc to everything else?

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 3, 2018, 8:39pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/13 "2018-06-03T20:39:48Z")

</div>

Latex does sound like a good option.

* * *

If you went the html route though, this is how you can make a table.

For the simplest table that would work on a very old browser:

- [HTML Tables](https://www.w3schools.com/html/html_tables.asp)

For a bootstrap table (which classes are available in jupyter):

- [Tables · Bootstrap](https://getbootstrap.com/docs/4.1/content/tables/) – _you just add the “table” class to a table element_

// the second option is what is used in: [Best tool for printing tables in Jupyter notebook? - #8 by djsegal](https://discourse.julialang.org/t/best-tool-for-printing-tables-in-jupyter-notebook/3548/8)

( beyond this, i guess i don’t really understand the use-case 😕 )

* * *

**edit:** you could for example, then, prevent cells from being wider than 160px or something

// see the `max-width` style [attribute](https://www.w3schools.com/cssref/pr_dim_max-width.asp)

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 3, 2018, 8:43pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/14 "2018-06-03T20:43:36Z")

</div>

Thanks for the links. The use-case is: I have clients that I want send an invoice, quote, or receipt to. I need to populate those with data I save in simple txt files. The whole pipe-line from a test file with their name, the expenses, etc to an automated email+pdf attachment+stripe website (for them to pay with a credit card) requires me to build about 3-4 tables.  
My “bottleneck” format where everything needed to go through is/was markdown. I guess I should switch that up to LaTeX… Feel free to PM me if you want to know more.

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [June 3, 2018, 9:04pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/15 "2018-06-03T21:04:26Z")

</div>

Yes, I think that would be much safer than having markdown as the “primary” source. Relying on markdown would just be asking for trouble if there are tables.

---

<div class="post-metadata">

### Author: ![NiclasMattsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclasmattsson/32/21988_2.png) [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)
#### Post date: [June 3, 2018, 9:38pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/16 "2018-06-03T21:38:37Z")

</div>

When I read the name “Markdown tables”, my brain short-circuited and I assumed you were aiming at solving the following problem:

Pretty-printing simple 2D data with row and column headers to the REPL or a text file (i.e. assuming a monospaced typeface), with a few simple customization options concerning lines (where to put lines & which Unicode characters to use for them) and cell alignment (e.g. left, right, center, decimal point).

But now I get the impression that your package is for outputing nice-looking tables in proportional typefaces, using smart layout engines like LaTeX or HTML/CSS to “just do the right thing” for whatever output format or size you need. Is this roughly correct?

Now that I am no longer confusing Markdown text input with its output rendering, can someone point me to some packages that address the “simple monospaced table” use case? (And sorry for hijacking the thread to ask this!)

---

<div class="post-metadata">

### Author: ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)
#### Post date: [June 3, 2018, 11:51pm UTC](https://discourse.julialang.org/t/markdown-tables/11385/17 "2018-06-03T23:51:17Z")

</div>

> [@NiclasMattsson](#):
>
> Now that I am no longer confusing Markdown text input with its output rendering, can someone point me to some packages that address the “simple monospaced table” use case?

Just gonna throw it out there:

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

// for example: [tetris.jl](https://github.com/djsegal/Tetris.jl/blob/b5aa672bfab704f23ceffa22d15fb1520457f65b/src/Tetris.jl#L69-L74) loads differently if you’re in the REPL

---

<div class="post-metadata">

### Author: ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)
#### Post date: [June 4, 2018, 1:26am UTC](https://discourse.julialang.org/t/markdown-tables/11385/18 "2018-06-04T01:26:51Z")

</div>

I like the markdown idea better than html/latex… using markdown means you can print it in the REPL _and_ convert it to anything else as well as well. It will be useful everywhere, packages that extend arrays and dataframes can use it in show().

But multiline could be hard!

---

<div class="post-metadata">

### Author: ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)
#### Post date: [June 4, 2018, 2:01am UTC](https://discourse.julialang.org/t/markdown-tables/11385/19 "2018-06-04T02:01:53Z")

</div>

Might be some useful code in here if your comfortable with haskell:

[https://github.com/baig/pandoc-csv2table](https://github.com/baig/pandoc-csv2table)

or python:  
[https://github.com/ickc/pantable](https://github.com/ickc/pantable)

---

<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: [June 4, 2018, 2:30am UTC](https://discourse.julialang.org/t/markdown-tables/11385/20 "2018-06-04T02:30:02Z")

</div>

Latexify can do this with the `md` function

> **[GitHub - korsbo/Latexify.jl: Convert julia objects to LaTeX equations, arrays...](https://github.com/korsbo/Latexify.jl)**
>
> Convert julia objects to LaTeX equations, arrays or other environments. - GitHub - korsbo/Latexify.jl: Convert julia objects to LaTeX equations, arrays or other environments.

to get something copy and pasteable, you can just do `show(md(df))`

[Next page](https://discourse.julialang.org/t/markdown-tables/11385.md?page=2)
