216

Is there a way to create merged rows in a column of table in markdown files like ReadMe.md files?

Something like this:

table

5
  • I'm afraid from not. Markdown is a simple HTML/text editor. You don't have a lot of features... 😞 Oct 7, 2017 at 15:19
  • @H.Pauwelyn do you khow an alternative solution? can i embed excel file in it?
    – dev-masih
    Oct 7, 2017 at 15:22
  • Nope like I said it's an simple thing. I suggest to use a code block. It begins and ends with three back ticks xor every row starts with for spaces. Oct 7, 2017 at 15:25
  • maybe try raw HTML tables inside your markdown file?
    – mb21
    Oct 9, 2017 at 9:20
  • 1
    @dev-masih, answering your question about an alternative solution. You can use AsciiDoc instead of Markdown. GitHub supports it now. Your table in AsciiDoc syntax: [cols="^,^,^"] \n|=== \n|Layer1 |Layer2 |Layer3 \n \n.4+.^|L1 Name .2+.^|L2 Name A |L3 Name A \n|L3 Name B \n.2+.^|L2 Name B |L3 Name C \n|L3 Name D \n \n|===. Replace all \n with line separator.
    – Peter
    Apr 8, 2020 at 4:33

6 Answers 6

150

No, this is not possible with GitHub-Flavored Markdown. As the spec explains (emphasis added):

The remainder of the table’s rows may vary in the number of cells. If there are a number of cells fewer than the number of cells in the header row, empty cells are inserted. If there are greater, the excess is ignored:

Of course, you can always fall back to raw HTML.

<table>
    <thead>
        <tr>
            <th>Layer 1</th>
            <th>Layer 2</th>
            <th>Layer 3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td rowspan=4>L1 Name</td>
            <td rowspan=2>L2 Name A</td>
            <td>L3 Name A</td>
        </tr>
        <tr>
            <td>L3 Name B</td>
        </tr>
        <tr>
            <td rowspan=2>L2 Name B</td>
            <td>L3 Name C</td>
        </tr>
        <tr>
            <td>L3 Name D</td>
        </tr>
    </tbody>
</table>

Try it yourself at https://jsfiddle.net/7h89y55r/

4
  • this is perfect and result is exactly what i wants
    – dev-masih
    Oct 9, 2017 at 18:27
  • 9
    Using raw HTML is a trade-off. It’s more flexible, but you can no longer use markdown within the HTML tags. <table><tr><td>This is not emphasized text: *the asterisks* will be rendered literally.</td></tr></table>
    – chharvey
    May 2, 2020 at 17:07
  • Perfect! Here's also a HTML table generator to make a table easily: tablesgenerator.com/html_tables
    – Niko Fohr
    May 27, 2020 at 20:14
  • 2
    @chharvey Well, to be specific, in GFM you can, you just have to put blank lines between the HTML and Markdown content. Had to escape them for this comment, but: <td>\n\n*markdown* [foo]\n\n</td> github.github.com/gfm/#example-157
    – Kroltan
    Jun 2 at 17:41
41

The standard commonmark does not support tables and does not refer to or recommend any specific table extensions (latest revision permalink as of 2018-03). Your question doesn't specifically ask about Github-flavored Markdown (GFM), but GFM is based on commonmark with a table extension which doesn't support this.

MultiMarkdown from at least v5 supports these types of tables (docs permalink) in the same way that Michael Fortin for PHP Markdown Extra does, turning:

|             |          Grouping           ||
First Header  | Second Header | Third Header |
 ------------ | :-----------: | -----------: |
Content       |          *Long Cell*        ||
Content       |   **Cell**    |         Cell |

New section   |     More      |         Data |
And more      | With an escaped '\|'         ||  
[Prototype table]

into Table

I'm commonly using markdown-it (VSCode built-in markdown & my Ghost blog use it) which only supports Github-flavored tables, but someone created an extension (markdown-it-multimd-table) for these tables with it. Ultimately, you've got options.

7

I was answering OP's question in the comments about an alternative solution, but the comment got squashed to one line. Adding it as an answer here to show formatting properly.

You can use AsciiDoc instead of Markdown. GitHub supports it now. Just use README.adoc instead of README.md Your table in AsciiDoc syntax:

[cols="^.^,^.^,^.^"]
|===
|Layer1 |Layer2 |Layer3

.4+|L1 Name .2+|L2 Name A |L3 Name A
|L3 Name B
.2+|L2 Name B |L3 Name C
|L3 Name D
|===
0
4

vscode plugin Markdown Extended supports extended table formats described by other answers by integrating markdown-it-multimd-table

3

It is not possible in standard Markdown, however, there are some solutions which is supporting this feature. One of the previously mentioned Multimarkdown, but I would like to recommend another online Markdown editor which is supporting it: μr² editor

It is supporting row and column merge and also generate a nice PDF from the output. Example:

|               |          Grouping             ||         Grouping 2         ||  Not Grouped    |
| First Header  | Second Header | Third Header   | Forth Header | Fifth Header | Sixth Header    |
| ------------- | :-----------: | -------------: | :----------: | :----------: | --------------- |
| Tall Cell     |          *Long Cell*          ||         *Long Long Cell*                    |||
| ^^            |   **Bold**    | 1. first item  | *Italic*     | 3. third item | + first point  |\
| ^^            |               | 1. second item |              | 1. forth item | + second point |

| New section   |     More      |         Data   | ... - -- --- |||
| And more      | With an escaped \|          || "Try 'quotes' in quotes "         |||
[Compicated table]

Will be rendered like:

enter image description here

1

I was using Postman to document an API and found that you can mix line readme .md notation with HTML by inserting HTML inside your | | separators to make even more robust designs. I assume it is the same for other platforms that use markup such as GitHub, try it and see if it works for you.

The following example nests a table inside a table cell:

       | Field  | Description |  Optional | Default |
       | ------ | ----------- | --------- | ------- |
       | manual_entry_indicator | no: is not is allow manual entry <br /> yes: is manual entry enabled| yes | no |
       | amounts | json object containing all transaction amounts <br /> <br /> <table> <tr> <td> Subfield </td> <td> Description </td> <td> Optional </td> <td> Default </td> </tr> <tr> <td> tip </td>  <td> transaction tip amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> total </td> <td> equal to Base  Amount + Base amount for  Reduced State Tax + City Tax + State Tax + Reduced State Tax + Tip or Cash back </td> <td> no </td> <td> NA </td> </tr> <tr> <td> cashback </td> <td> cash back amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> state_tax </td> <td> State tax amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> city_tax </td> <td> City tax amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> reduced_tax </td> <td> Reduced state tax amount </td> <td> yes </td> <td> NA </td> </tr> <tr> <td> base_reduced_tax </td> <td> Reduced state tax base amount </td> <td> yes </td> <td> NA </td> </tr> </table> | no | NA |

will be rendered like this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.