<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.101.0">Hugo</generator><title type="html">table on A Scripter's Notes</title><subtitle type="html">Emacs, scripting and anything text oriented.</subtitle><link href="https://scripter.co/tags/table/" rel="alternate" type="text/html" title="HTML"/><link href="https://scripter.co/tags/table/index.xml" rel="alternate" type="application/rss+xml" title="RSS"/><link href="https://scripter.co/tags/table/atom.xml" rel="self" type="application/atom+xml" title="Atom"/><link href="https://scripter.co/tags/table/jf2feed.json" rel="alternate" type="application/jf2feed+json" title="jf2feed"/><updated>2026-04-22T08:24:58-04:00</updated><author><name>Kaushal Modi</name><email>kaushal.modi@gmail.com</email></author><id>https://scripter.co/tags/table/</id><entry><title type="html">Field Formatters in Org table</title><link href="https://scripter.co/field-formatters-in-org-table/?utm_source=atom_feed" rel="alternate" type="text/html"/><link href="https://scripter.co/how-to-quickly-create-a-table-in-org-mode/?utm_source=atom_feed" rel="related" type="text/html" title="How to quickly create a table in Org mode"/><id>https://scripter.co/field-formatters-in-org-table/</id><author><name>Kaushal Modi</name></author><published>2018-03-05T17:40:00-05:00</published><updated>2018-03-05T17:40:00-05:00</updated><content type="html"><![CDATA[<blockquote>Using field-formatters to format results of Org table formulae.</blockquote><div class="ox-hugo-toc toc">
<div class="heading">Table of Contents</div>
<ul>
<li><a href="#using-printf-style-0-dot-1f-formatter">Using <code>printf</code> style <code>%0.1f</code> formatter</a></li>
<li><a href="#using-calc-f1-formatter">Using <em>Calc</em> <code>f1</code> formatter</a></li>
</ul>
</div>
<!--endtoc-->
<p>If you have a simple Org table like:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-org" data-lang="org"><span class="line"><span class="cl"><span class="s">| 0.5 |</span>
</span></span><span class="line"><span class="cl"><span class="s">| 1.5 |</span>
</span></span><span class="line"><span class="cl"><span class="s">|-----|</span>
</span></span><span class="line"><span class="cl"><span class="s">|     |</span>
</span></span></code></pre></div><p>And you want the <em>A3</em> cell to contain the sum of <em>A1</em> and <em>A2</em> cells,
you would add this at the bottom on that table and evaluate it (<kbd>C-c
C-c</kbd>).</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-org" data-lang="org"><span class="line"><span class="cl"><span class="cs">#+tblfm</span><span class="c">: @&gt;$1=vsum(@1..@&gt;&gt;)</span>
</span></span></code></pre></div><p>That formula reads as: &ldquo;Set the value of the cell is last row
(<code>@&gt;</code>)<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>, first column (<code>$1</code>) be equal to the sum of all cells in
the same column from row 1 (<code>@1</code>) to second-to-the-last row (<code>@&gt;&gt;</code>).&rdquo;</p>
<p>But then you end up with an odd-looking <code>2.</code> instead of <code>2.0</code> in the
result cell:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-org" data-lang="org"><span class="line"><span class="cl"><span class="s">| 0.5 |</span>
</span></span><span class="line"><span class="cl"><span class="s">| 1.5 |</span>
</span></span><span class="line"><span class="cl"><span class="s">|-----|</span>
</span></span><span class="line hl"><span class="cl"><span class="s">|  2. |</span>
</span></span><span class="line"><span class="cl"><span class="cs">#+tblfm</span><span class="c">: @&gt;$1=vsum(@1..@&gt;&gt;)</span>
</span></span></code></pre></div><p>So I had <a href="https://lists.gnu.org/r/emacs-orgmode/2016-04/msg00581.html">posted</a> a question on the Org mailing list to understand if
this was a bug &mdash; <em>it was not</em>.</p>

<h2 id="using-printf-style-0-dot-1f-formatter">Using <code>printf</code> style <code>%0.1f</code> formatter&nbsp;<a class="headline-hash no-text-decoration" href="#using-printf-style-0-dot-1f-formatter">#</a></h2>


<p>Thanks to the reply from Thierry Banel to that question, one of the
solutions is to use <em>field formatters</em>, like in <code>printf</code> in C (and
many other languages):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-org" data-lang="org"><span class="line"><span class="cl"><span class="s">| 0.5 |</span>
</span></span><span class="line"><span class="cl"><span class="s">| 1.5 |</span>
</span></span><span class="line"><span class="cl"><span class="s">|-----|</span>
</span></span><span class="line hl"><span class="cl"><span class="s">| 2.0 |</span>
</span></span><span class="line hl"><span class="cl"><span class="cs">#+tblfm</span><span class="c">: @&gt;$1=vsum(@1..@&gt;&gt;);%0.1f</span>
</span></span></code></pre></div>
<h2 id="using-calc-f1-formatter">Using <em>Calc</em> <code>f1</code> formatter&nbsp;<a class="headline-hash no-text-decoration" href="#using-calc-f1-formatter">#</a></h2>


<p>Another solution, also from Thierry, was to use the <em>Calc</em> <code>f1</code>
formatter instead of <code>%0.1f</code> (and similarly <code>f5</code> instead of <code>%0.5f</code>).</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-org" data-lang="org"><span class="line"><span class="cl"><span class="s">| 0.5 |</span>
</span></span><span class="line"><span class="cl"><span class="s">| 1.5 |</span>
</span></span><span class="line"><span class="cl"><span class="s">|-----|</span>
</span></span><span class="line hl"><span class="cl"><span class="s">| 2.0 |</span>
</span></span><span class="line hl"><span class="cl"><span class="cs">#+tblfm</span><span class="c">: @&gt;$1=vsum(@1..@&gt;&gt;);f1</span>
</span></span></code></pre></div><dl>
<dt>Note</dt>
<dd>While the <code>%.1f</code> format is handy for those who are used to
<code>printf()</code> syntax, note that Calc unlimited precision
numbers are converted to double floats before applying
<code>%.1f</code>. Whereas <code>f1</code> operates on Calc numbers without
conversion.</dd>
</dl>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>See <a href="https://orgmode.org/manual/References.html"><abbr title="Read the same section within Emacs by doing 'C-h i g (org) References'">(org) References</abbr></a> for more information on those field references.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content><category scheme="https://scripter.co/categories/emacs" term="emacs" label="emacs"/><category scheme="https://scripter.co/categories/org" term="org" label="org"/><category scheme="https://scripter.co/tags/table" term="table" label="table"/><category scheme="https://scripter.co/tags/field-formatter" term="field-formatter" label="field-formatter"/></entry><entry><title type="html">How to quickly create a table in Org mode</title><link href="https://scripter.co/how-to-quickly-create-a-table-in-org-mode/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://scripter.co/how-to-quickly-create-a-table-in-org-mode/</id><author><name>Kaushal Modi</name></author><published>2014-05-28T12:44:06-04:00</published><updated>2014-05-28T12:44:06-04:00</updated><content type="html"><![CDATA[<p>Set the buffer major mode to <code>org-mode</code>. If the file extension is
<code>.org</code>, that major mode would be set automatically by emacs.</p>
<p>Follow the below steps to create a table ..</p>
<ol>
<li>
<p>Start writing the headers of the table starting with a vertical pipe
<code>|</code>.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">| Header1 | Header2 | Header3 |▮
</span></span></code></pre></div></li>
<li>
<p>Once you have finished writing the headers, do <code>C-u C-c -</code> to insert
a horizontal line above the header row.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">|---------+---------+---------|
</span></span><span class="line"><span class="cl">| Header1 | Header2 | Header3 |▮
</span></span></code></pre></div></li>
<li>
<p>Then do <code>C-c -</code> to insert a horizontal line below the header row.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">|---------+---------+---------|
</span></span><span class="line"><span class="cl">| Header1 | Header2 | Header3 |▮
</span></span><span class="line"><span class="cl">|---------+---------+---------|
</span></span></code></pre></div></li>
<li>
<p>Go down one row ( <code>C-n</code> ) and hit TAB and org-mode will figure out
that you need to create a new row and will put the cursor in the
first cell of the new row.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">|---------+---------+---------|
</span></span><span class="line"><span class="cl">| Header1 | Header2 | Header3 |
</span></span><span class="line"><span class="cl">|---------+---------+---------|
</span></span><span class="line"><span class="cl">|▮        |         |         |
</span></span></code></pre></div></li>
<li>
<p>You can now use TAB and Shift + TAB to navigate the cells and new
rows will be created when you hit TAB when you are in the last cell
of the last created row.</p>
<p>When you want to close the table with a bottom border, hit <code>C-c -</code>
when the cursor is in the last row.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">|---------+---------+---------|
</span></span><span class="line"><span class="cl">| Header1 | Header2 | Header3 |
</span></span><span class="line"><span class="cl">|---------+---------+---------|
</span></span><span class="line"><span class="cl">| A       | B       | C▮      |
</span></span><span class="line"><span class="cl">|---------+---------+---------|
</span></span></code></pre></div></li>
</ol>]]></content><category scheme="https://scripter.co/categories/emacs" term="emacs" label="emacs"/><category scheme="https://scripter.co/categories/org" term="org" label="org"/><category scheme="https://scripter.co/tags/table" term="table" label="table"/></entry></feed>