Tables in Markdown (in Jupyter)

The first row of the table defines the headers, then the next row defines the alignment of each column. You duplicated the alignment at the top of the table and where it’s actually supposed to go.

The right Markdown should simply be what you have in your syntax, but remove the first row:

| Stretch/Untouched | ProbDistribution | Accuracy |
| --- | --- | --- |
| Stretched | Gaussian | .843 |

The --- in between the column definitions | | mean that the column is unjustified. In standard Markdown, this would align to the left of the column but in Jupyter notebook, it appears to align to the right instead.

With that, I get this table:


If you’d like to left align or centre align, you can use :- and :-: respectively. Depending on what Jupyter notebook environment you’re using, you will need to use -: to right align.

| Stretch/Untouched | ProbDistribution | Accuracy |
| :- | -: | :-: |
| Stretched | Gaussian | .843

The first column will be left aligned, centre column is right aligned and last column is centre aligned. Interestingly using Google Colab, --- left aligns the text:


Is the alignment not working as expected in your Jupyter notebook?

The alignment syntax that I’ve mentioned above unfortunately does not work as of this date (June 25th, 2020) when using local installations of the Jupyter notebook environment. This is because of a bug in the Jupyter source where the Markdown alignment is not taken into account and all of the text is right aligned. See the Github issue here: https://github.com/jupyter/notebook/issues/3919. However, it does work using jupyterlab as well as on Google Colab.

Leave a Comment