How to write lists inside a markdown table?
Asked Answered
D

9

301

Can one create a list (bullets, numbered or not) inside a markdown table.

A table looks like this:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |

A list looks like this:

* one
* two
* three

Can I merge them somehow?

Deadlock answered 13/11, 2013 at 9:57 Comment(0)
H
381

Yes, you can merge them using HTML. When I create tables in .md files from Github, I always like to use HTML code instead of markdown.

Github Flavored Markdown supports basic HTML in .md file. So this would be the answer:

Markdown mixed with HTML:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |
| <ul><li>item1</li><li>item2</li></ul>| See the list | from the first column|

Or pure HTML:

<table>
  <tbody>
    <tr>
      <th>Tables</th>
      <th align="center">Are</th>
      <th align="right">Cool</th>
    </tr>
    <tr>
      <td>col 3 is</td>
      <td align="center">right-aligned</td>
      <td align="right">$1600</td>
    </tr>
    <tr>
      <td>col 2 is</td>
      <td align="center">centered</td>
      <td align="right">$12</td>
    </tr>
    <tr>
      <td>zebra stripes</td>
      <td align="center">are neat</td>
      <td align="right">$1</td>
    </tr>
    <tr>
      <td>
        <ul>
          <li>item1</li>
          <li>item2</li>
        </ul>
      </td>
      <td align="center">See the list</td>
      <td align="right">from the first column</td>
    </tr>
  </tbody>
</table>

This is how it looks on Github:

Hygroscope answered 14/11, 2013 at 11:52 Comment(8)
This is great, but is there any way to style the list too? Remove bullets, margins, etc.? Github, for example, doesn't seem to accept a style="list-style: none" tag on the ul element.Stinger
@TreborRude No, because Markdown is not HTML actually. But if you use a library (e.g. marked), you probably have this feature (to combine HTML with markdown).Gingerich
It's ok, I found out that a <span> tag with embedded <br/> tags did exactly what I was trying to do with the styled list.Stinger
@TreborRude Sure, you still can have multiple line cells. Probably it accepts <p> tags as well.Gingerich
I'm happy to confirm that the first one (embedded <ul><li>foo</li></ul>) also works on Bitbucket Server.Oneiromancy
Use ol if you need ordered lists. Example <ol><li>Enumeration 1<li><li>Enumeration 2</li></ol>.Motoring
Perfect. Exactly what I needed. And it stays with Markdown instead of adding extraneous stuff to solve a simple problem.Toweling
not sure but can this be done in rmarkdown?Benne
B
122

If you want a no-bullet list (or any other non-standard usage) or more lines in a cell use <br />

| Event         | Platform      | Description |
| ------------- |-----------| -----:|
| `message_received`| `facebook-messenger`<br/>`skype`|
Boggle answered 21/9, 2016 at 17:22 Comment(5)
Probably because three years ago it was the only reasonable answer? I agree with you that this is a better answer, today.Axolotl
This is an answer to Newline in markdown table?, not this question about listsConsubstantial
@Consubstantial I've upvoted your suggestion. ;) The google search led me to this question and this the solution I needed. I think it's bearable (e.g. non-bulleted list) so I keep it at this very place.Boggle
You can add bullets with HTML entities: &bull; facebook-messenger<br/>&bull; skypeVeldaveleda
markdown lint flags this as no inline htmlArawn
A
60

Not that I know of, because all markdown references I am aware of, like this one, mention:

Cell content must be on one line only

You can try it with that Markdown Tables Generator (whose example looks like the one you mention in your question, so you may be aware of it already).

Pandoc

If you are using Pandoc’s markdown (which extends John Gruber’s markdown syntax on which the GitHub Flavored Markdown is based) you can use either grid_tables:

+---------------+---------------+--------------------+
| Fruit         | Price         | Advantages         |
+===============+===============+====================+
| Bananas       | $1.34         | - built-in wrapper |
|               |               | - bright color     |
+---------------+---------------+--------------------+
| Oranges       | $2.10         | - cures scurvy     |
|               |               | - tasty            |
+---------------+---------------+--------------------+

or multiline_tables.

-------------------------------------------------------------
 Centered   Default           Right Left
  Header    Aligned         Aligned Aligned
----------- ------- --------------- -------------------------
   First    row                12.0 Example of a row that
                                    spans multiple lines.

  Second    row                 5.0 Here's another one. Note
                                    the blank line between
                                    rows.
-------------------------------------------------------------
Agustin answered 13/11, 2013 at 12:5 Comment(10)
The Markdown Tables Generator is wrong because it accepts new lines that, as you quote, are not accepted. But thanks for the valuable information.Deadlock
@GabrielPetrovay The Markdown Tables Generator being a relatively new service, I am not surprised ;) But regarding "GitHub Flavored Markdown", my answer stands.Agustin
I tend to accept your answer. But I wait 1-2 days more, maybe someone posts a hack (if answer accepted, no one will look at it, except others with the same problem)Deadlock
@GabrielPetrovay I agree. You also can contact GitHub support, and see what they have to say about it. (and then update my answer or post your own)Agustin
Done! Also instructed them to reply here :) with a comment or a new answer.Deadlock
@イオニカビザウ I obviously didn't mentioned HTML. With HTML, you can recreate any markdown feature, so it is not a valid solution. The question is about markdown, not HTML.Agustin
@Agustin I saw that is tagged as github-flavored-markdown. Github Flavored markdown supports HTML.Gingerich
@Agustin if I use your grid_tables code in an Rmd file and use knitr to generate PDF output, the table contains a blank line after each list for some reason. Any idea why this is the case or how to circumvent this (pandoc) behavior?Christcrossrow
@Christcrossrow 7 years later.... no precise idea, really: try and ask a separate question, with illustration of the bug.Agustin
This works well with Quarto tables and its cross-reference mechanismCorbitt
G
12

another solution , you can add <br> tag to your table

    |Method name| Behavior |
    |--|--|
    | OnAwakeLogicController(); | Its called when MainLogicController is loaded into the memory , its also hold the following actions :- <br> 1. Checking Audio Settings <br>2. Initializing Level Controller|

enter image description here

Guizot answered 15/1, 2020 at 8:5 Comment(0)
S
4

An alternative approach, which I've recently implemented, is to use the div-table plugin with panflute.

This creates a table from a set of fenced divs (standard in the pandoc implementation of markdown), in a similar layout to html:

---
panflute-filters: [div-table]
panflute-path: 'panflute/docs/source'
---

::::: {.divtable}
:::: {.tcaption}
a caption here (optional), only the first paragraph is used.
::::
:::: {.thead}
[Header 1]{width=0.4 align=center}
[Header 2]{width=0.6 align=default}
::::
:::: {.trow}
::: {.tcell}

1. any
2. normal markdown
3. can go in a cell

:::
::: {.tcell}
![](https://pixabay.com/get/e832b60e2cf7043ed1584d05fb0938c9bd22ffd41cb2144894f9c57aae/bird-1771435_1280.png?attachment){width=50%}

some text
:::
::::
:::: {.trow bypara=true}
If bypara=true

Then each paragraph will be treated as a separate column
::::
any text outside a div will be ignored
:::::

Looks like:

enter image description here

Seagraves answered 2/9, 2018 at 20:26 Comment(0)
S
3

If you happen to be using Kramdown (the default Markdown renderer for Jekyll) then you have to use the nomarkdown extension {::nomarkdown}...{:/}.

For example:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| {::nomarkdown}<ul><li>one</li><li>two</li><li>three</li></ul>{:/} | Kramdown | bullets |
Shirl answered 4/1, 2022 at 19:57 Comment(0)
R
2

If you use the html approach:

don't add blank lines

Like this:

<table>
    <tbody>

        <tr>
            <td>1</td>
            <td>2</td>
        </tr>

        <tr>
            <td>1</td>
            <td>2</td>
        </tr>

    </tbody>
</table>

the markup will break.

Remove blank lines:

<table>
    <tbody>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
    </tbody>
</table>
Rutabaga answered 24/1, 2019 at 16:35 Comment(1)
HTML will ignore blank lines and multiple whitespaces, so I don't see any problems with that. Could you explain what will break here?Richardricharda
J
1

For Python markdown, I recommend using the GridTables markdown extension. In particular, the forked version I linked has worked best for me with mkdocs-material, and it supports lists and most markdown formatting. Multiline code blocks will not render well.

Journalist answered 28/3, 2022 at 12:43 Comment(1)
How did you install it for mkdocs? I don't see it in the default extension lists: squidfunk.github.io/mkdocs-material/setup/extensions/…Femineity
B
0

One solution that hasn't been shown:

  • create the table using html <table> tag
  • write markdown inside table cells

Works by adding a newline after <td>:

<table><tbody>
<tr>
  <th> Left column </th>
  <th> Right column </th>
<tr>
<tr>
  <td>

  * Just `write` **markdown**
  * In _here_
  </td>
  <td>

  ```python
  def or_here():
    pass
  ```
  </td>
<tbody></table>

Looks like this:

enter image description here

How to:

  • add an empty newline after <td>
  • the "zero-indent" indentation is on the level as the <td>

It's a little finicky to get right but is nicer than writing full-blown html.

Bauxite answered 7/8, 2023 at 11:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.