<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: atorin</title>
    <description>The latest articles on DEV Community by atorin (@atorin).</description>
    <link>https://dev.to/atorin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F36280%2F122d2a63-c237-46ce-acef-67418c82cc2e.jpeg</url>
      <title>DEV Community: atorin</title>
      <link>https://dev.to/atorin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/atorin"/>
    <language>en</language>
    <item>
      <title>Tables (+) reStructuredText</title>
      <dc:creator>atorin</dc:creator>
      <pubDate>Mon, 19 Mar 2018 21:32:58 +0000</pubDate>
      <link>https://dev.to/atorin/tables--restructuredtext-1m6n</link>
      <guid>https://dev.to/atorin/tables--restructuredtext-1m6n</guid>
      <description>&lt;p&gt;&lt;em&gt;This post is an extract from a post I published on my &lt;a href="http://blog.albertotorin.it" rel="noopener noreferrer"&gt;personal blog&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  What's inside
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;RST + Tables + Vim&lt;/li&gt;
&lt;li&gt;Sphinx + Tables + PDF output&lt;/li&gt;
&lt;li&gt;HTML Table -&amp;gt; RST Table&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  RST + Tables + Vim
&lt;/h1&gt;

&lt;p&gt;I love Vim (actually, &lt;a href="http://macvim-dev.github.io/macvim/" rel="noopener noreferrer"&gt;MacVim&lt;/a&gt;), and as soon as I started working with &lt;a href="http://docutils.sourceforge.net/rst.html" rel="noopener noreferrer"&gt;reStructuredText&lt;/a&gt; (RST) documents for the first time, I hoped to find a nice plug-in to speed up my editing. Creating tables manually was particularly painful!&lt;/p&gt;

&lt;p&gt;Of course, someone had already figured out a solution to that... Enter &lt;strong&gt;Riv&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/gu-fan/riv.vim" rel="noopener noreferrer"&gt;Riv&lt;/a&gt; is a great plug-in, with many shortcuts to make your life easier when dealing with RST files. In my opinion, the best thing about Riv is how it handles table creation. You create cells by simply pressing tab, and when you modify the content, the table automagically reshapes when you exit the edit mode. &lt;/p&gt;

&lt;p&gt;A few shortcuts for you (on MacOS):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tab&lt;/code&gt;: move to the next cell&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;option + enter&lt;/code&gt;: create the header row&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;control + enter&lt;/code&gt;: create a new regular row&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx2oyxk01fnj3b4930qc5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx2oyxk01fnj3b4930qc5.gif" alt="Tables with Riv" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you try Riv, don't forget to install &lt;a href="https://github.com/gu-fan/InstantRst" rel="noopener noreferrer"&gt;InstantRst&lt;/a&gt; as well. This will enable a live preview in the browser, as you edit your document. &lt;/p&gt;

&lt;h1&gt;
  
  
  Sphinx + Tables + PDF output
&lt;/h1&gt;

&lt;p&gt;If you write technical documentation, sooner or later you're bound to stumble on &lt;a href="http://www.sphinx-doc.org/" rel="noopener noreferrer"&gt;Sphinx&lt;/a&gt; and &lt;a href="http://readthedocs.org/" rel="noopener noreferrer"&gt;Read the Docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Tables in Sphinx can be a very frustrating thing (see above!). Sometimes you have a large table that is difficult to render with the RST syntax; in other cases, the table looks good in the HTML page but awful in the PDF output. &lt;/p&gt;

&lt;p&gt;For those cases, I have created a &lt;a href="http://http://tables-with-sphinx.readthedocs.io/" rel="noopener noreferrer"&gt;short tutorial about tables with Sphinx&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One of the best options, in my option, is to work with &lt;strong&gt;CSV tables&lt;/strong&gt;. You can create your table in a spreadsheet, without the need to worry about the proper formatting in RST. &lt;/p&gt;

&lt;p&gt;To take care of the PDF output for those long tables that won't fit on a single page, you can use the &lt;code&gt;longtable&lt;/code&gt; class. Then, with the &lt;code&gt;tabularcolumns&lt;/code&gt; directive, you can control the width of the columns in your PDF. &lt;/p&gt;

&lt;p&gt;This is a sample code snippet to render a table from a CSV file with two columns. Check the result in the &lt;a href="http://tables-with-sphinx.readthedocs.io/en/latest/csv-table.html" rel="noopener noreferrer"&gt;tutorial&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   .. tabularcolumns:: |p{1cm}|p{7cm}|

   .. csv-table:: Caption of the table
      :file: path-to-the/file.csv 
      :header-rows: 1 
      :class: longtable
      :widths: 1 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach also works if you use a &lt;a href="http://www.sphinx-doc.org/en/master/rest.html#tables" rel="noopener noreferrer"&gt;grid table&lt;/a&gt; (the type of tables shown in the GIF above) instead of a CSV table, with the proper changes.&lt;/p&gt;

&lt;h1&gt;
  
  
  HTML Table -&amp;gt; RST Table
&lt;/h1&gt;

&lt;p&gt;Speaking of tables, if you start from a table in HTML, you can use &lt;a href="https://github.com/doakey3/DashTable" rel="noopener noreferrer"&gt;DashTable&lt;/a&gt; to convert it to RST. &lt;/p&gt;

&lt;p&gt;This tool will produce for you a nice grid table that you can easily copy and paste in your RST document. &lt;/p&gt;

</description>
      <category>rst</category>
      <category>sphinx</category>
      <category>documentation</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
