Reputation: 1638
I want to add a table from a csv file in the Sphinx documentation. In the rst file, I used the csv-table directive as follows:
.. csv-table:: xyz
:header-rows: 1
:file: path/file.csv
:widths: 20, 30, 50
As a result, I get the required table in the Sphinx documentation as shown below:
I want to wrap text in the third column "Significance". The format should be wrapped text inside the table as shown below. Source:
I tried different things such as removing widths or changing its values.
I am relatively new to CSS. I tried various suggestions found in the internet. For example, I tried adding following elements to my css file.
@import url('theme.css');
.table {
table-layout: fixed;
}
td {
word-wrap: break-word !important;
overflow-wrap: break-word !important;
word-break: break-all !important;
}
And changing the directive in rst file as follows:
.. table::
:class: contentstable
:widths: 100%
.. csv-table:: Databases in MESSAGE
:header-rows: 1
:file: csv_file/message_databases.csv
:widths: 20 30 50
However, these techniques still don't resolve the issue. I tried searching and trying ways to increase rows and so on. I found that it is possible add a new line in rst using a pipe symbol "|". However, I have several csv files to be added as tables. And I don't want to add pipe symbols in texts in individual cells.
How can I wrap the text- increase the row height and reduce the column width of the table in the Sphinx documentation? Scrolling a bit is fine, but scrolling too long makes you lose the important contents in previous columns.
Upvotes: 5
Views: 2075
Reputation: 2337
Try using :class: longtable
. This is needed when also generating a PDF of the Sphinx docs, especially when it hits the end of a page.
.. csv-table:: xyz
:header-rows: 1
:file: path/file.csv
:widths: 20, 30, 50
:class: longtable
Upvotes: -2