65

Is it possible to merge cells in Org-mode tables?

Examples of horizontal merging would be something like that:

| Header | Merged header |
|--------+-------+-------|
| Text1  | Text2 | Text3 |
| Text4  | Text5 | Text6 |

Example of vertical merging:

| Header1 | Header2 | Header3 |
|---------+---------+---------|
| Merged  | Text1   | Text2   |
| text    |---------+---------|
| here    | Text3   | Text4   |

If that is somehow possible in org-mode? If not, what is the most idiomatic way to simulate merged cells?

Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166

2 Answers2

22

It is not possible with org-mode tables. However, have a look at table.el package (included with emacs for some time so try: C-h d table). Org-mode has some support for tables from this library, e.g. when exporting, but don't expect full compatibility.

As for simulating merged cell, it depends on what you want. Inlining text strings in the same cell might be enough for computation/publication, but not for visualisation.

alls0rts
  • 248
  • 3
  • 9
bzg
  • 2,515
  • 17
  • 19
  • 1
    table.el cannot support the basic features like link of doc, calculation that already existed in org-table. It's sad. – Dean Chen Apr 22 '19 at 08:59
6

I just found an example from emacs-orgmode mail list which works just fine for me.

+---+-----+-----------+
|   | A   | B         |
+---+-----+-----+-----+
| 1 | A1  | B1  | C1  |
|   |     +-----+-----+
|   | A1b | B1b | C1b |
+---+-----+-----+-----+
| 2 | A2  |   B2 C2   |
|   +-----+           |
|   | A2b |  B2b C2b  |
+---+-----+-----------+

If you modify your table like below, it works too.

+---------+---------+---------+
| Header1 | Header2 | Header3 |
+---------+---------+---------+
| Merged  | Text1   | Text2   |
| text    +---------+---------+
| here    | Text3   | Text4   |
+---------+---------+---------+

So I find some tips on that:

  • Use | to expand row

  • Use +-..-+ to surround the split row


Here is another alternative choice which is not very convenient. You can use Quoting HTML tags to handle HTML table export.

#+BEGIN_EXPORT html
<TABLE BORDER="1">
  <TR>
    <TH>Header1</TH>
    <TH>Header2</TH>
    <TH>Header3</TH>
  </TR>
  <TR>
    <TD ROWSPAN="2">Merged text here</TD>
    <TD>Text1</TD>
    <TD>Text2</TD>
  </TR>
  <TR>
    <TD>Text3</TD>
    <TD>Text4</TD>
  </TR>
</TABLE>
#+END_EXPORT

This synatx works only when exported to html. If you want export table to pdf, you should use syntax below. You can use LaTeX Tables Generator to generate latex table online.

#+BEGIN_EXPORT latex
% Please add the following required packages to your document preamble:
% \usepackage{multirow}
\begin{table}[]
\begin{tabular}{lll}
Header1                           & Header2 & Header3 \\
\multirow{2}{*}{Merged text here} & Text1   & Text2   \\
                                  & Text3   & Text4  
\end{tabular}
\end{table}
#+END_EXPORT

There exsist many back-ends in in org export, you possiblely need to write customzation code to those backends if you want to export to those backends.

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
  • 2
    Org-mode does not recognize this as a table. Even though exporting your example works, when you try to have a link in a cell, HTML export is broken. You can not use tabs either. That's far from ideal, unfortunately. – Ataias Reis Jan 04 '20 at 11:41
  • These are [table.el](https://www.gnu.org/software/emacs/manual/html_node/emacs/Text-Based-Tables.html) tables: Org mode exports them but other than that, it provides very little support for them. See [17.14.1 Packages that Org cooperates with](https://orgmode.org/manual/Cooperation.html#Cooperation) – NickD May 22 '22 at 12:14