288

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?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168

9 Answers9

365

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:

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • 3
    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. – Trebor Rude Aug 05 '14 at 12:00
  • 1
    @TreborRude No, because Markdown is not HTML actually. But if you use a library (e.g. [`marked`](https://github.com/chjj/marked)), you probably have this feature (to combine HTML with markdown). – Ionică Bizău Aug 05 '14 at 12:59
  • It's ok, I found out that a `` tag with embedded `
    ` tags did exactly what I was trying to do with the styled list.
    – Trebor Rude Aug 05 '14 at 16:42
  • @TreborRude Sure, you still can have multiple line cells. Probably it accepts `

    ` tags as well.

    – Ionică Bizău Aug 05 '14 at 17:04
  • I'm happy to confirm that the first one (embedded `
    • foo
    `) also works on Bitbucket Server.
    – nwinkler Dec 09 '16 at 15:27
  • 1
    Use `ol` if you need ordered lists. Example `
    1. Enumeration 1
    2. Enumeration 2
    `.
    – user3613932 May 04 '20 at 22:30
  • Perfect. Exactly what I needed. And it stays with Markdown instead of adding extraneous stuff to solve a simple problem. – Ken Ingram Apr 21 '22 at 02:13
  • not sure but can this be done in rmarkdown? – Manny Ma May 27 '22 at 18:38
118

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`|
Amio.io
  • 20,677
  • 15
  • 82
  • 117
  • 2
    Probably because three years ago it was the only reasonable answer? I agree with you that this is a better answer, today. – William Daniel Apr 20 '17 at 15:01
  • 21
    This is an answer to [Newline in markdown table?](http://stackoverflow.com/q/11700487/1048572), not this question about lists – Bergi May 03 '17 at 18:17
  • 2
    @Bergi 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. – Amio.io May 03 '17 at 21:11
  • 4
    You can add bullets with HTML entities: • `facebook-messenger`
    • `skype`
    – shawnhcorey Jul 30 '17 at 14:27
  • markdown lint flags this as [no inline html](https://github.com/DavidAnson/markdownlint/blob/v0.8.1/doc/Rules.md#md033) – andrei.ciprian Mar 23 '18 at 10:34
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.
-------------------------------------------------------------
0xcaff
  • 13,085
  • 5
  • 47
  • 55
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    The Markdown Tables Generator is wrong because it accepts new lines that, as you quote, are not accepted. But thanks for the valuable information. – Gabriel Petrovay Nov 13 '13 at 12:35
  • @GabrielPetrovay The Markdown Tables Generator being a relatively new service, I am not surprised ;) But regarding "GitHub Flavored Markdown", my answer stands. – VonC Nov 13 '13 at 12:37
  • 1
    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) – Gabriel Petrovay Nov 13 '13 at 12:38
  • 1
    @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) – VonC Nov 13 '13 at 12:39
  • Done! Also instructed them to reply here :) with a comment or a new answer. – Gabriel Petrovay Nov 13 '13 at 12:46
  • 1
    @イオニカビザウ 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. – VonC Nov 14 '13 at 12:25
  • @VonC I saw that is tagged as `github-flavored-markdown`. Github Flavored markdown supports HTML. – Ionică Bizău Nov 14 '13 at 12:29
  • @VonC 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? – mavericks May 12 '20 at 17:42
  • @mavericks 7 years later.... no precise idea, really: try and ask a separate question, with illustration of the bug. – VonC May 12 '20 at 18:20
  • 1
    This works well with [Quarto tables](https://quarto.org/docs/authoring/tables.html) and its cross-reference mechanism – wibeasley Apr 28 '23 at 21:03
11

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

VectorX
  • 657
  • 5
  • 12
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

Chris Sewell
  • 679
  • 1
  • 7
  • 19
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>
Diogo Gomes
  • 2,135
  • 16
  • 13
  • 4
    HTML will ignore blank lines and multiple whitespaces, so I don't see any problems with that. Could you explain what will break here? – XenGi Jun 15 '21 at 08:53
2

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 |
Johnny Baloney
  • 3,409
  • 1
  • 33
  • 37
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.

CapitalDot
  • 11
  • 3
  • How did you install it for mkdocs? I don't see it in the default extension lists: https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown/ – nocibambi Jul 15 '22 at 10:33
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.

Nearoo
  • 4,454
  • 3
  • 28
  • 39