[Tex/LaTex] Override table in sphinx

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
  • A header row color
  • Bold header text
  • 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}

\definecolor{tablehead}{rgb}{0.7294117647058823, 0.6823529411764706, 0.6235294117647059}

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

This results in following error:

! Missing # inserted in alignment preamble.
<to be read again> 
                   &
l.294 \hline\end{tabulary}

? x

Best Answer

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}

\definecolor{tablehead}{rgb}{0.7294117647058823, 0.6823529411764706, 0.6235294117647059}

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

\renewenvironment{tabulary}[3]
 {\noindent\tabu to \textwidth{#2}\hline\rowcolor{tablehead}}
 {\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}

enter image description here

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