Available at http://table.sourceforge.net/ together with a tutorial. Provided by default with emacs version >= 22.
Table.el provides EMACS with text based table creation and editing capabilities.
Be sure to use C-h b to see the default bindings.
Let us give an example. Assume we want to convert the following to a html table.
Name cmd calls Percentage rgb 93 534 46% Xah 82 090 40% total 203 118 100%
– First, we select the text and capture the table with the M-x table-capture
command.
– We must then specify a column delimiter regexp. SPC SPC
is ok for this table.
– For the row delimiter, we want a newline. This can be entered either with C-o
or C-q C-j
.
– We just type RET
when asked for justification, this will select the default.
– For Minimum Cell Width, we can take a value of 10. Here is the final result:
+----------+----------+----------+ |Name |cmd calls |Percent | Name cmd calls Percent +----------+----------+----------+ rgb 93 534 46% |rgb |93 534 |46% | Xah 82 090 40% => +----------+----------+----------+ total 203 118 100% |Xah |82 090 |40% | +----------+----------+----------+ |total |203 118 |100% | +----------+----------+----------+
The point should be in the first cell. Press TAB to go to the next cell, S-TAB to come back to the previous cell. Columns can be widened/shrunk with C->
and C-<
. You can write in the cells, the table will be expanded or redrawn as needed.
Commands available with tables are prefixed with table
. They can be listed by typing M-x table- TAB
. Their names are self-explanatory. For example, we can center the second column by putting the cursor on that column and typing M-x table-justify
. Just answer column
then center
when asked. The following gives additional information on these commands:
C-h f table-insert
When finished with editing, several options are available.
M-x table-unrecognize
The result is a plain text table, which can be activated again with M-x table-recognize
. Note that you can remove/add rows, draw additionnal cells in a plain text table, and these changes will be taken into account when the table is recognized. For example, try to recognize the following table, which is obtained by removing some lines from the table above.+--------+-----------+---------+ | Name | cmd calls | Percent | +--------+ +---------+ | rgb | 93 534 | 46% | | Xah | 82 090 | 40% | +--------+ +---------+ | total | 203 118 | 100% | +--------+-----------+---------+
M-x table-release
, thus leaving only the lined-up text.+--------+-----------+---------+ | Name | cmd calls | Percent | Name cmd calls Percent +--------+-----------+---------+ | rgb | 93 534 | 46% | rgb 93 534 46% +--------+-----------+---------+ => | Xah | 82 090 | 40% | Xah 82 090 40% +--------+-----------+---------+ | total | 203 118 | 100% | total 203 118 100% +--------+-----------+---------+
M-x table-generate-source
. Note that this command operates on an “activated” ascii table (use first M-x table-recognize
if the table is not in an activated state). After a few questions, the code will be generated in another buffer. Unfortunatly, I don’t know how to edit html in the wiki. Here is the raw code.<!-- This HTML table template is generated by emacs 22.1.1 --> <table border="1"> <caption>Table</caption> <tr> <td align="left" valign="top">   class="comment">;Name </td> <td align="center" valign="top">   class="comment">;cmd calls </td> <td align="center" valign="top">   class="comment">;Percent </td> </tr> <tr> <td align="left" valign="top">   class="comment">;rgb </td> <td align="center" valign="top">   class="comment">; 93 534 </td> <td align="center" valign="top">   class="comment">; 46% </td> </tr> <tr> <td align="left" valign="top">   class="comment">;Xah </td> <td align="center" valign="top">   class="comment">; 82 090 </td> <td align="center" valign="top">   class="comment">; 40% </td> </tr> <tr> <td align="left" valign="top">   class="comment">;total </td> <td align="center" valign="top">   class="comment">; 203 118 </td> <td align="center" valign="top">   class="comment">; 100% </td> </tr> </table>
Characters used to recognize/draw the borders of the table can be specified with the help of the following variables:
table-cell-horizontal-chars
Contains a string. All characters in string are valid horizontal delimiters for the table. The first character of the string is used for output.
table-cell-horizontal-char
Contains the character used as the vertical delimiter. “|” by default.
table-cell-intersection-char
Contains the character that appears at the intersection of rows and columns. “+” is the default.
The following settings give interesting results. They use utf-8 characters to draw continuous lines for the border of the table. Arguably, your font should support these character to display the desired effect.
(setq table-cell-horizontal-chars "\u2501") (setq table-cell-vertical-char ?\u2503) (setq table-cell-intersection-char ?\u254B)
Here is the result. The vertical lines may not be lined up, depending on your browser configuration. Expect perfect alignment with no gap from inside emacs.
╋━━━━━━╋━━━━━━╋━━━━━╋ ┃Name ┃cmd calls ┃Percent ┃ ╋━━━━━━╋━━━━━━╋━━━━━╋ ┃rgb ┃93 534 ┃46% ┃ ╋━━━━━━╋━━━━━━╋━━━━━╋ ┃Xah ┃82 090 ┃40% ┃ ╋━━━━━━╋━━━━━━╋━━━━━╋ ┃total ┃203 118 ┃100% ┃ ╋━━━━━━╋━━━━━━╋━━━━━╋
Tables can be pretty memory intensive since several variables are allocated to each cell, so as to record their properties. This means that you will probably run into error messages if the table has more than an hundred rows.
On a modern computer, it is however safe to increase by a factor of 10 the variables max-lisp-eval-depth
and max-specpdl-size
, so that emacs can use more memory and handle bigger tables. Try for example:
M-x set-variable RET max-lisp-eval-depth RET 40000 RET
M-x set-variable RET max-specpdl-size RET 100000 RET
Or put in your InitFile
(setq max-lisp-eval-depth '40000) (setq max-specpdl-size '100000)
For my Emacs (unicode-2 branch), I needed to change the lambda on line 5176 to
(lambda (key value) (set-char-table-range elt key (table--replace-binding1 value)))