150

Is there a way to have 'colspan' on github markdown?

I'm trying to create a table where one row takes up four columns.

| One     | Two        | Three   | Four          | 
| ------------- |-------------| ---------| ------------- |
| One                | Two               | Three          | Four                |

| One     | Two        | Three   | Four          | 
| ------------- |-------------| ---------| ------------- |
| Span Across ||||

You can see a live preview by pasting the above here http://markdown-here.com/livedemo.html

user391986
  • 29,536
  • 39
  • 126
  • 205

5 Answers5

117

You can use HTML tables on GitHub (but not on StackOverflow)

<table>
  <tr>
    <td>One</td>
    <td>Two</td>
  </tr>
  <tr>
    <td colspan="2">Three</td>
  </tr>
</table>

Becomes

HTML table output

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
fregante
  • 29,050
  • 14
  • 119
  • 159
82

Compromise minimum solution:

| One    | Two | Three | Four    | Five  | Six 
| -
| Span <td colspan=3>triple  <td colspan=2>double

So you can omit closing </td> for speed, оr can leave for consistency.

Result from http://markdown-here.com/livedemo.html : markdown table with colspan

Works in Jupyter Markdown.

Update:

As of 2019 year all pipes in the second line are compulsory in Jupyter Markdown.

| One    | Two | Three | Four    | Five  | Six
|-|-|-|-|-|-
| Span <td colspan=3>triple  <td colspan=2>double

minimally (does not work at Jupyter Lab):

One    | Two | Three | Four    | Five  | Six
-|||||-
Span <td colspan=3>triple  <td colspan=2>double
sherdim
  • 1,159
  • 8
  • 19
  • 8
    I got an issue with this solution if I try to use a colspan over the first column, a hack to avoid that in turn would be to add another first column that has no content... Yuck... – consideRatio Aug 07 '17 at 00:34
  • 50
    This does not work on GitHub, CommonMark nor StackOverflow – fregante Apr 20 '18 at 06:39
  • 7
    As of writing, this works on GitHub wikis. However, GH doesn't know you've added extra columns, so it adds blank cells on the right. – cxw Nov 10 '18 at 01:46
  • I understood that Pipes are ether optional at the beginning and the end, or none of them. Maybe should you add one at the end of this lines? – Sandburg Mar 22 '19 at 13:36
  • How to make it works also for table header (it has two rows as header, where the first row has spanned column)? I have tried in Jupyter Notebook and it does not work. – dudung May 31 '22 at 04:12
  • I believe that the syntax supports the single row header, and does not supports thead and tbody tags as you want, I suppose. You can check in sources of markdown parser. Anyway this is not a speedy syntax anymore. Try emdebbed tables in header string (can omit the first ): One |
    Two upper
    Two lower
    | Three tall |
    Four upper
    Four lower
    | Five | Six -|-|-|-|-|- Span triple double
    – sherdim Jun 01 '22 at 12:12
22

There is no way to do so. Either use an HTML table, or put the same text on several cells.

like this:

| Can Reorder | 2nd operation |2nd operation |2nd operation |
| :---: | --- |
|1st operation|Normal Load <br/>Normal Store| Volatile Load <br/>MonitorEnter|Volatile Store<br/> MonitorExit|
|Normal Load <br/> Normal Store| | | No|
|Volatile Load <br/> MonitorEnter| No|No|No|
|Volatile store <br/> MonitorExit| | No|No|

which looks like

HTML table

3ocene
  • 2,102
  • 1
  • 15
  • 30
landerlyoung
  • 1,693
  • 17
  • 14
17

I recently needed to do the same thing, and was pleased that the colspan worked fine with consecutive pipes ||

MultiMarkdown v4.5

Tested on v4.5 (latest on macports) and the v5.4 (latest on homebrew). Not sure why it doesn't work on the live preview site you provide.

A simple test that I started with was:

| Header ||
|--------------|
| 0 | 1 |

using the command:

multimarkdown -t html test.md > test.html
Mark
  • 660
  • 1
  • 6
  • 9
-12

Adding break resolves your issue. You can store more than a record in a cell as markdown doesn't support much features.

41 72 6c
  • 1,600
  • 5
  • 19
  • 30
  • 12
    It's unclear what you mean by "Adding break". Could you illustrate? – ivan_pozdeev Jul 06 '19 at 03:38
  • 3
    What is a `break` in MarkDown? – Sohail Si Oct 25 '19 at 11:51
  • 2
    I am inclined to assume that they meant "line" break, so `
    ` - which would kind of help to emulate a `rowspan`-like behavior (not `colspan`). In the "spanned" cells, you would do nothing, while on the granular, "unspanned" cells, you add line breaks to produce a multi-row effect. Not a terrible idea, just poor explanation if that was the case.
    – gyohza Feb 02 '22 at 19:05