Override table in sphinx

I'm using sphinx to generate documentations. The tables it produces via latex are pretty ugly, so I'd like to give them some global styling. What I'd like to achieve is

• Always 100% width
• Maybe some more spacing

So what sphinx does is it writes tables like this:

\begin{tabulary}{\linewidth}{|L|L|L|}
\hline
\textsf{\relax
Nummer
} & \textsf{\relax
Name
} & \textsf{\relax
Bemerkungen
}\\
\hline
0
&
Allgemeines
&
Enthält Meta-Informationen zum Dossier
\\
[...]
\hline\end{tabulary}


My approach was something like this (for the header row color):

\RequirePackage{tabu}

\renewenvironment{tabulary}[2]{\bgroup\begin{tabu} to \textwidth{#2}
}%
{\end{tabu}\egroup}


This results in following error:

! Missing # inserted in alignment preamble.
&
l.294 \hline\end{tabulary}

? x

• Why the \bgroup and \egroup? They serve no purpose whatsoever. Did you try with \tabu and \endtabu instead of \begin{tabu} and \end{tabu}? – egreg Apr 1 '15 at 11:10
• Uh I think I saw a renewenvironment example with them. I've been trying back and forth. Using \tab produces the same error. – Schtibe Apr 1 '15 at 11:44

The L column type is useless as far as tabu is concerned.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{tabu,tabulary}
\usepackage[table]{xcolor}

% redefine the L column type
\newcolumntype{L}{X[l]<{\strut}}

\renewenvironment{tabulary}[3]
{\endtabu}

\begin{document}

\begin{tabulary}{\linewidth}{|L|L|L|}
\hline
\textsf{Nummer} & \textsf{Name} & \textsf{Bemerkungen}\\
%\hline
0
&
Allgemeines
&
Enthält Meta-Informationen zum Dossier
\\
\hline
\end{tabulary}

\end{document}


Note that we have to swallow the first \hline otherwise and place it by hand, because it's illegal after \rowcolor.

• currently Sphinx uses three different ways of doing tables: tabular and tabulary, wrapped in a threeparttable if there is a caption, and longtable if either requested by an instruction in the mark-up or if the table has at least 30 rows. No table is actually rendered as a float, which is good as it alleviates some issues with footnotes for example. tabular is used as fall-back if the (small) table contains verbatim material. This legacy situation is very unsatisfactory, switching to tabu is tempting except that FC said next one will break things. And Sphinx must work on TL2009 or older as is. – user4686 Oct 14 '16 at 20:12

Since sphinx 1.6.5 you can now add files

_templates/latex.tex_t
_templates/longtable.tex_t
_templates/tabular.tex_t
_templates/tabulary.tex_t


and override everything quite nicely. You can get the templates from github or from sphinx source.

I don't think there is any documentation for it yet, at least I couldn't find it.