Exporting Tables With Borders

This page explains how to configure exported tables borders either with the variable org-html-table-default-attributes, which is ignored with HTML5 export, or properties.

The default table export doesn’t include borders and it is difficult to read.

WordPress seems to render table borders automatically, so here is an example of the raw HTML instead. It doesn’t set borders.

| Alpha   | Bravo    |
|---------+----------|
| Charlie | December |
|         |          |
<table>
<colgroup>
<col  class="org-left">
<col  class="org-left">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Alpha</th>
<th scope="col" class="org-left">Bravo</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">Charlie</td>
<td class="org-left">December</td>
</tr>
</tbody>
</table>

But if you add some attributes they look like this

#+ATTR_HTML: :border 2 :rules all :frame border
| Alpha   | Bravo    |
|---------+----------|
| Charlie | December |
|         |          |
<table border="2" rules="all" frame="border">
<colgroup>
<col  class="org-left">
<col  class="org-left">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Alpha</th>
<th scope="col" class="org-left">Bravo</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">Charlie</td>
<td class="org-left">December</td>
</tr>
<tr>
<td class="org-left">&#xa0;</td>
<td class="org-left">&#xa0;</td>
</tr>
</tbody>
</table>

Here is a snippet to make it easier to remember.

(lambda () (interactive) (insert "#+ATTR_HTML: :border 2 :rules all :frame border"))

Here is how to set the properties if you aren’t using HTML5. Most of us don’t need to anyway.

(setq org-html-table-default-attributes
      (plist-put org-html-table-default-attributes :rules "all"))
(setq org-html-table-default-attributes
      (plist-put org-html-table-default-attributes :frame "border"))

2 thoughts on “Exporting Tables With Borders”

  1. Will this work if I want proper one line border around the table? Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *