2

I'm using this code to create a table from csv for my documentation in readthedocs:

.. csv-table:: Markram et al. Model & Network configuration file
   :file: ../config_files/Markram_config_file.csv
   :header-rows: 1

The CSV is large and has a lot of rows and columns. For columns, everything is fine since it just fits a few columns in the page and the others can be accessed by scrolling to the right in the table. However, all of the rows are placed in the the page and I cannot specify a particular "length" or "height" for the csv table. I tried to specify the height by :height: 100px but it's not defined for the tables. Is there anyway to specify that? Here's a sample of what I'm using in the table.

Kennet Celeste
  • 4,593
  • 3
  • 25
  • 34

2 Answers2

0

Immediately before your .. csv-table directive, put this above with a blank line separating (see https://stackoverflow.com/a/46195021/2214933):

.. rst-class:: table-myclass

.. csv-table:: blah blah blah

The above will apply a class name to the rendered HTML table.

Then in your Sphinx theme, add a custom style. Assuming you want to limit the height of each table row (not the table itself since 100px is pretty short for a lot of data) put the following:

table.myclass tbody tr {height: 100px;}

Adjust the CSS selector and style to taste.

See how to create custom styles in Sphinx.

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • I created a file in `./_static/css/custom.css` and added `table.myclass tbody tr {height: 100px;}` into the file. Then I added `def setup(app): app.add_stylesheet('css/custom.css')` to my conf.py according to [this](http://docs.readthedocs.io/en/latest/guides/adding-custom-css.html) link, but still my table is presented very long. Just to remind you, I want it to be short but scrollable. – Kennet Celeste Feb 09 '18 at 00:41
0

I added a file _static/css/custom.css with the following contents (inspired by https://stackoverflow.com/a/4457290/3362993):

table.docutils {
    display: block;
    height: <your_height>px;
    overflow-y: scroll;
    width: <your_width>%
  }

and added the following line to conf.py:

html_css_files = [
    "css/custom.css",
]

I found that the trailing list-comma was necessary for the css file to be recognized :shrug:

jsta
  • 3,216
  • 25
  • 35