sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.58k stars 2.12k forks source link

Provide a way to style tables in LaTex #2832

Open vlotorev opened 8 years ago

vlotorev commented 8 years ago

Hi,

as I commented in https://github.com/sphinx-doc/sphinx/issues/2305#issuecomment-182575690 currently there is no way in styling tables for LaTex output. Examples that are cannot be 'styled' for tables:

Also currently sphinx wraps table header with '\textsf{' which also can't be disabled.

andreacassioli commented 8 years ago

+1

(Especially for the text header)

christinaweyher commented 8 years ago

+1

(Also especially regarding the the table header \textsf )

jfbu commented 8 years ago

side note, in fact on master branch since b3d8961c, it is not \textsf{ but \sphinxstylethead{ hence this can be customized from the 'preamble' key. Thus this sub-issue may be already closed (on master branch).

liminkai520520 commented 8 years ago

how to set the table header colour?

jfbu commented 8 years ago

@liminkai520520 it is not clear if you mean the background colour or the text colour. Anyway, you can insert commands in a redefinition of \sphinxstylethead. That is, starting with future release 1.5.

rakhimov commented 7 years ago

How to set the background row color for the table head?

jfbu commented 7 years ago

You can try this in conf.py.

latex_elements = {
    'passoptionstopackages': r'\PassOptionsToPackage{table}{xcolor}',
    'preamble' : r'\protected\def\sphinxstylethead{\cellcolor{red}\textsf}',
}

This does not answer directly your question because it colours the cells not the row, but may be functionally equivalent in default situation. Perhaps it will help you.

The LaTeX advice at wikibook of using \rowcolors has issues : does not work with longtable header, forces repeated use at each table because the macro does not reset row count after tables, does not work well with complicated grid tables. (further, \rowcolors does not seem to allow easily coloring only the header row)

rakhimov commented 7 years ago

Thanks @jfbu ! It indeed does the trick.

jfbu commented 7 years ago

Just to mention here that table templates were introduced at 976fc32 on master branch for Sphinx 1.6 release and will be modifiable by user (2a37b0e). This will make it easier for user knowing well LaTeX to customize tables: for example with table option passed to xcolor package, the templates could contain \rowcolors command and thus get coloring of rows; indeed this xcolor provided \rowcolors macro requires being used at each table, and template is perfect way to achieve this. Perhaps 1.6 will already provide some higher level interface to color table rows without the constraint of a \rowcolors at each table.