1

I am new to Emacs. Is there any way to create a table in Org mode like in the example table below. Particularly I'd need to be able to circle some of the words and hide some of the grid lines. The end goal is in pdf format (ODT would also be useful).

Example table: enter image description here

Owing to a very useful link, this is about as far as I got:

+-----------+-----------------+------------------------------------------+
| Example #1|                                                            |
| *creative*|                                                            | 
+-----------+-----+-----------+------------------------------------------+
|           | A   | B         |                                          |
|           | A1  | B1        |           other bits                     |
|           | A1b | B1b       |                                          |
|           | A2  |   B2C2    |                                          |
+-----------+-----+-----------+------------------------------------------+
|   A2b  B2b C2b anjafkjnfjnef  janakjf  jknfajf b a jkf fa jbf a        |
| afjasf  afasf ajbf af  fajfasf a fa fasf af af  asf ajksf basf  as     |
+-----------+-----+-----------+------------------------------------------+

I have read that grid lines can be hidden here. However, the suggested command #+LATEX_HEADER: \renewcommand{\hline}{} gets rid of all horizontal grid lines when I need to get rid of all vertical grid lines as well as the intermediate horizontal grid lines instead. It might have something to do with cline, but I couldn't get this to work yet (see: link).

The table, once complete, will form part of a larger Org file with plain text elements. Hence, I'd like to get this done in Org mode. However, I am flexible in terms of the type of table used (org table, table.el etc.) as well as how to accomplish the circles and table editing (be it via Latex or other), only the output file should be in pdf format (or ODT). Does anyone have an idea?

4
  • What you are showing is a table.el table, not an Org mode table. Read the comments after the answer to see why they are unsatisfactory. For the kind of table formatting you are asking, you'll have to use LaTeX (for PDF output - don't know enough about ODT to say anything useful).
    – NickD
    Feb 19 at 1:27
  • "... why they are unsatisfactory" - I should have said "... why they are unsatisfactory from the point of view of an Org mode user".
    – NickD
    Feb 19 at 2:58
  • @NickD: Thanks a ton! I have tried to clarify the question, highlighting that I just need a table that works in org mode and can be displayed in pdf format later - I am flexible in terms of how this is accomplished. Which answer are you referring to?
    – Tiberius
    Feb 21 at 14:04
  • 1
    Τhe one you link to in your question: stackoverflow.com/questions/10616460/…
    – NickD
    Feb 21 at 15:59

2 Answers 2

1

You can't do this with org syntax. However, when org exports to pdf, it converts the text to LaTeX first. As a consequence, you can include raw LaTeX code in your org file. LaTeX is very powerful, and allows for limitless customization of your tables. However, you'll have to code it by hand, and it can get quite complex.

Here's a rough example of your table:

#+LATEX_HEADER: \usepackage{tikz}

* My Org File

My LaTeX table:

\begin{tabular}{lllc }
\hline
 Example #1 \\
*creative* \\
\hline
& A   & B    & \\
& A1  & \tikz[baseline=(word.base)] \node[draw,circle] (word) {B1}; & other bits \\
& A1b & B1b  & \\
& A2  & B2C2 & \\
\hline
\multicolumn{4}{l}{A2b  B2b C2b anjafkjnfjnef  janakjf  jknfajf b a jkf fa jbf a} \\
\multicolumn{4}{l}{afjasf  afasf ajbf af  fajfasf a fa fasf af af  asf ajksf basf as} \\
\hline
\end{tabular}

On export, this produces the following:

enter image description here

The downside, as you can see, is the source text for the table is much less readable.

To further customize the appearance of the exported pdf, you'll need to consult a LaTeX reference. I think it's off-topic for an Emacs site.

1
  • 1
    Thank you so much, this has been very illuminating. I had been hoping I could just edit Org or table.el tables using just a few Latex commands, but this seems more intricate. Your solution works perfectly. I have managed to tweak it a bit to my needs, but it quickly becomes cluttered and is still a work in progress (unlike Org tables). Your answer also helped me understand the limitations of Org tables, much appreciated!
    – Tiberius
    Feb 22 at 16:45
2

(Author of the original ODT exporter here)

All artefacts included in this answer as a zip file

This example uses The Authoritative fork of Org mode's ODT exporter and uses the following features that are exclusive to this exporter

(This example will not work with ODT exporter that ships with Emacs or upstream Org mode)


If you are interested in discussing the nuances, we can have further discussions at my github page ox-odt Discussions#267: Create table with some cells highlighted with ellipsis and with custom gridlines


To get this

Fancy Table

do this

#+odt_preferred_output_format: pdf

#+CAPTION: Table with Custom Grid Lines\\
#+CAPTION: Table with some Cells Highlighted with an "Elliptic" Box
#+ATTR_ODT: :span "@1$2{1:6}"
#+ATTR_ODT: :span "@2$1{4:1}"
#+ATTR_ODT: :span "@6$1{1:7}"
#+ATTR_ODT: :list-table t
#+ATTR_ODT: :style "GriddedTable"
- 
  - 
     Example #1

     Creative

  - 

  - 

  - 

  - 

  - 

  - 

- 

  - 

  - How Often? 

  - About once per month or less

  - 

    #+ATTR_ODT: :anchor "as-char" :shape "ellipse" :width 3  :style "OrgShape1"
    #+begin_customshape
         About once per week
    #+end_customshape

  - About each day

  - 2 or 3 times each day

  - More than 3 times each day

- 

  - 

  - How Intense?

  - Very Low

  - Low

  - Moderate

  - 

    #+ATTR_ODT: :anchor "as-char" :shape "ellipse" :width 3  :style "OrgShape1"
    #+begin_customshape
    High
    #+end_customshape

  - Very High

- 

  - 

  - How long lasting?

  - Less than 1 minute

  - 1-10 minute

  - 11-60 minutes

  - 

     #+ATTR_ODT: :anchor "as-char" :shape "ellipse" :width 3  :style "OrgShape1"
     #+begin_customshape
     1-4 hours
     #+end_customshape

  - Longer than 4 hours

- 

  - 

  - How easy to regulate?

  - Very easy?

  - 

     #+ATTR_ODT: :anchor "as-char" :shape "ellipse" :width 3  :style "OrgShape1"
     #+begin_customshape
     Easy
     #+end_customshape

  - Moderate

  - Difficult

  - Very  Difficult
  
- 

  - 

    In the example above, the person chose “About once per week” for
    “How Often” because they do not feel creative very frequently. The
    person chose “High” for ‘How Intense” because their creativity is
    strong when it does occur. The person chose “1-4 hours” for "How
    Long-Lasting” because when they feel creative the feeling lasts
    for a couple hours. Finally, the person chose “Easy” for ‘How Easy
    to Regulate” because when they feel creative they are able to
    increase this feeling by choosing appropriate activities.

  - 

  - 

  - 

  - 

  - 

  - 

    
This example uses [[https://github.com/kjambunathan/org-mode-ox-odt?tab=readme-ov-file#the-authoritative-fork-of-org-modes-odt-exporter][The Authoritative fork of Org mode's ODT exporter]]

- [[https://github.com/kjambunathan/org-mode-ox-odt/blob/fa8cadfe40175fef5a677c74b004e6848f7478b8/lisp/ox-odt.el#L3518][Custom Shapes]]
- [[https://github.com/kjambunathan/org-mode-ox-odt/blob/fa8cadfe40175fef5a677c74b004e6848f7478b8/lisp/ox-odt.el#L10387][List Tables]]
- [[https://github.com/kjambunathan/org-mode-ox-odt/blob/fa8cadfe40175fef5a677c74b004e6848f7478b8/lisp/ox-odt.el#L11470][Table with Row and Colspans]]
- [[https://github.com/kjambunathan/org-mode-ox-odt/blob/fa8cadfe40175fef5a677c74b004e6848f7478b8/lisp/ox-odt.el#L11834][Custom styles using nxml blocks]]


This document is produced with following version of ~ox-odt.el~

#+CAPTION: ~ox-odt~ Version Info
#+begin_example
commit fa8cadfe40175fef5a677c74b004e6848f7478b8 (HEAD -> master, origin/master, origin/HEAD)
Author: Jambunathan K <[email protected]>
Date:   Sun Jan 21 15:59:10 2024 +0530
#+end_example

and rendered on following on version of ~LibreOffice~

#+CAPTION: ~Emacs~ Version Info
#+begin_example
Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: 60(Build:1)
CPU threads: 4; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-IN (en_IN); UI: en-US
Debian package version: 4:7.6.4~rc1-1+b2
Calc: threaded
#+end_example

The author uses following version of ~Emacs~

#+CAPTION: ~Emacs~ Version Info
#+begin_example
$ emacs --version

GNU Emacs 30.0.50
Development version 5af4e346b0b0 on master branch; build date 2024-02-09.
Copyright (C) 2024 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
#+end_example


#+ATTR_ODT: :target "master_styles" :backends (odt)
#+begin_src nxml
<style:master-page style:name="Standard"
                   style:page-layout-name="A4LandscapeLayout">
  <style:footer>
    <text:p text:style-name="OrgFooter">
      <text:page-number text:select-page="current" />
    </text:p>
  </style:footer>
</style:master-page>
#+end_src


#+ATTR_ODT: :target "automatic_styles" :backends (odt)
#+begin_src nxml
<style:style style:name="OrgShape1"
             style:family="graphic">
  <style:graphic-properties draw:auto-grow-height="true"
                            draw:fill-color="#ffffff"
                            draw:textarea-horizontal-align="justify"
                            draw:textarea-vertical-align="middle"
                            draw:wrap-influence-on-position="once-concurrent"
                            fo:margin-bottom="0cm"
                            fo:margin-left="0cm"
                            fo:margin-right="0cm"
                            fo:margin-top="0cm"
                            fo:min-height="0cm"
                            fo:min-width="0cm"
                            style:flow-with-text="true"
                            style:horizontal-pos="from-left"
                            style:horizontal-rel="paragraph"
                            style:repeat="no-repeat"
                            style:run-through="foreground"
                            style:vertical-pos="from-top"
                            style:vertical-rel="paragraph"
                            style:wrap="none"
                            style:wrap-contour-mode="full"
                            svg:stroke-color="#000000"
                            svg:stroke-width="0cm" />
  <style:paragraph-properties style:writing-mode="lr-tb" />
</style:style>
#+end_src

This document is produced with following version of ox-odt.el

commit fa8cadfe40175fef5a677c74b004e6848f7478b8 (HEAD -> master, origin/master, origin/HEAD)
Author: Jambunathan K <[email protected]>
Date:   Sun Jan 21 15:59:10 2024 +0530

and rendered on following on version of LibreOffice

Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: 60(Build:1)
CPU threads: 4; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-IN (en_IN); UI: en-US
Debian package version: 4:7.6.4~rc1-1+b2
Calc: threaded

The author uses following version of Emacs

$ emacs --version

GNU Emacs 30.0.50
Development version 5af4e346b0b0 on master branch; build date 2024-02-09.
Copyright (C) 2024 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

6
  • 1
    Now that my answer targets odt exporter, can someone with some reputation add odt tag the question. I wanted to add some additiona internatioall links for "Further Reading" and my reputation is coming in way. Never mind. What interested me was the implicit challenge posed by the question, and how my own exporter stands up to the "custom" needs" of random folks out there in the internet.
    – mxnt
    Feb 24 at 5:28
  • This looks incredible. Not only does it create the entire table I had in mind, but it does so with utmost simplicity! I'd love to test this, but have some minor questions in terms of installing the exporter. On your github you say "Add kjambunathan.github.io/elpa to package-archives. Once that is done, you can install the exporter with M-x list-packages." Being new to emacs, it's unclear to me how exactly to add the link to the package-archives. Presumably once this is done I should be able to find " org-mode-ox-odt" amongst the list of packages? Any chance you could kindly elaborate?
    – Tiberius
    Feb 28 at 18:47
  • Another quick follow up question, would it be possible to omit some of the gridlines, as in the example picture or would we be looking at more intricate changes for this?
    – Tiberius
    Feb 28 at 19:20
  • M-x customize-variable RET package-archives RET and add my archive. Do M-x package-refresh-contents RET and and M-x package-install ox-odt Or Download the ox-odt tar from github.com/kjambunathan/kjambunathan.github.io/tree/master/elpa. And then do M-x package-install-file <ox-odt-<whatever>.tar. If you run in to issues, don't hesitate to ask questions on github page
    – mxnt
    Feb 29 at 14:13
  • In some configs the Emacs supplied odt exporter loads eagerly before my own exporter. Once you have started you Emacs, do M-x find-library RET ox-odt RET, and see if it ends up in ox-odt.el from ELPA dir. In that case, you can do M-x load-library ox-odt and you are all setup. If ox-odt that is loaded is from vanilla Emacs / Orgmode, then some more adjustments needs to be made. For example using setting up :load-path in use-package directive etc. Don't hesitate to open a new discussion in my github page, or comment on the new discussion I already created for you
    – mxnt
    Feb 29 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.