3

Try as I might, I cannot figure out how to change the default table format in the pdf output from sphinx.

I could edit the .tex file, or the writer.py source code... but both of those seem like bad options.

Is there any thing that can be passed to the preamble to accomplish that?

Justin
  • 42,475
  • 9
  • 93
  • 111

1 Answers1

2

Depending on what you are trying to accomplish by changing the table format. For instance if you want to define row colors and change the tables accordingly across the document you can use both the xcolor package and redefine how tabular handles that at the point of definition by changing the tabular environment.

So in the preamble you would do

\usepackage[table]{xcolor}
\definecolor{foo}{RGB}{236,137,29}
\definecolor{bar}{RGB}{232,108,31}

\let\newtabular\tabular
\let\newendtabular\endtabular
\renewenvironment{tabular}{\rowcolors{2}{foo}{bar}\newtabular}{\newendtabular}

This will overwrite the default tabular environment and apply the foo and bar row colors throughout the document, starting at the second row.

For having more directives related to tables. You should take a look at sphinxtr

Jeff Terrace has some great extensions included, but the two main ones to use are numfig and figtable. You can wrap a csv table into figtable.

.. figtable::
   :label: my-csv-label
   :caption: My CSV Table
   :nofig:

   .. csv-table::
     :file: data/foo.csv
     :header-rows: 1

Changing the standard table format with the caption below instead of above. Then you also have the added benefit of being able to directly link to that table by using :num:.

:num:`Table #my-csv-label`

It will automatically number accordingly, without referencing the label name. You can also use

.. figtable::
   :spec: {r l r l}

To better define how you want your table to appear.

table

table2

Cole
  • 1,699
  • 1
  • 17
  • 21