markdown

Is There A Way to make complex Markdown Table?


I Wanted to create a markdown table Complex table

but can't get it right:

| Available     | Process   | Allocation       |     Max         |
|---------------|-----------|:----------------:|----------------:|
| A | B | C | D |           |   A | B | C | D  | A | B | C | D   |
| 1 | 5 | 2 | 0 | P0        |   0 | 0 | 1 | 2  | 0 | 0 | 1 | 2   |
|               | P1        |   1 | 0 | 0 | 0  | 1 | 7 | 5 | 0   |
|               | P2        |   1 | 3 | 5 | 4  | 2 | 3 | 5 | 6   |
|               | P3        |   0 | 6 | 3 | 2  | 0 | 6 | 5 | 2   |
|               | P4        |   0 | 0 | 1 | 4  | 0 | 6 | 5 | 6   |

Solution

  • Markdown supports some HTML syntax, such as <table> elements. To make a column like the headers on the image, the magic attribute is

    colspan="X"  
    

    Where X is the number of columns you want it to extend to, as well as

    rowspan="Y"
    

    Where Y is the number of rows you want it to extend to

    For example:

    table {
      border-collapse:collapse;
    }
    
    td {
      border: 1px solid #000;
      margin: 0;
      padding: 0.5em;
    }
    <table>
      <tr>
        <td colspan="4">
          Available
        </td>
        <td rowspan="2">
          Processes
        </td>
        <td colspan="4">
          Allocation
        </td>
        <td colspan="4">
          Max
        </td>
      </tr>
      <tr>
        <td>
          A
        </td>
        <td>
          B
        </td>
        <td>
          C
        </td>
        <td>
          D
        </td>
        <td>
          A
        </td>
        <td>
          B
        </td>
        <td>
          C
        </td>
        <td>
          D
        </td>
        <td>
          A
        </td>
        <td>
          B
        </td>
        <td>
          C
        </td>
        <td>
          D
        </td>
      </tr>
      <tr>
        <td>
          1
        </td>
        <td>
          5
        </td>
        <td>
          2
        </td>
        <td>
          0
        </td>
        <td>
          P0
        </td>
        <td>
          0
        </td>
        <td>
          0
        </td>
        <td>
          1
        </td>
        <td>
          2
        </td>
        <td>
          0
        </td>
        <td>
          0
        </td>
        <td>
          1
        </td>
        <td>
          2
        </td>
      </tr>
      <tr>
        <td colspan="4">
        </td>
        <td>
          P1
        </td>
        <td>
          1
        </td>
        <td>
          0
        </td>
        <td>
          0
        </td>
        <td>
          0
        </td>
        <td>
          1
        </td>
        <td>
          7
        </td>
        <td>
          5
        </td>
        <td>
          0
        </td>
      </tr>
    </table>

    Note that CSS is only necessary here because the Markdown interpreter will be rendering the table with the default styling.