I am writing some documentation with Haddock, and I need to put a multi-column table with some values in it. How can I do it with Haddock? I cannot find info about it. Embedding some html as alternative looks no possible too.
Asked
Active
Viewed 303 times
3
-
I don't think there is any proper support for tables. You may have to make do with an image file. – leftaroundabout Jan 07 '17 at 12:49
-
There is now mathjax support in haddock so it may be possible to create a table using e.g. \begin{matrix} and \mathrm{...} - a bit rubbish but possibly better than an image file. Alternatively, you could add table support to haddock - the code is not difficult to modify but you'd have to worry about output formats other than html. – idontgetoutmuch Jan 07 '17 at 13:23
2 Answers
7
Haddock bundled with GHC 8.4 or newer (Haddock version >= 2.18.2) supports tables. As per the pull request where this was added, the syntax is based on RST Grid tables.
Sample use:
module Sample where
-- | A table:
--
-- +------------------------+------------+----------+----------+
-- | Header row, column 1 | Header 2 | Header 3 | Header 4 |
-- | (header rows optional) | | | |
-- +========================+============+==========+==========+
-- | body row 1, column 1 | column 2 | column 3 | column 4 |
-- +------------------------+------------+----------+----------+
-- | body row 2 | Cells may span columns. |
-- +------------------------+------------+---------------------+
-- | body row 3 | Cells may | \[ |
-- +------------------------+ span rows. | f(n) = \sum_{i=1} |
-- | body row 4 | | \] |
-- +------------------------+------------+---------------------+
sample :: ()
sample = ()
Turns into

Alec
- 31,829
- 7
- 67
- 114
1
Haddock "markup" doesn't currently support tables, see also Haddock User Guide - Chapter 3. Documentation and Markup. There is an open issue to add support for simple tables.

Giovanni Cappellotto
- 4,597
- 1
- 30
- 33