Код: Выделить всё
latex_elements = {
"preamble": r"""
% option 1
% \usepackage{etoolbox}
% \AtBeginEnvironment{tabulary}{\setlength{\extrarowheight}{0pt}}
% \renewcommand{\arraystretch}{1.5}
% option 2
% \usepackage[table]{xcolor}
% \renewcommand{\arraystretch}{2} % Reduces extra vertical space
% \setlength{\extrarowheight}{0pt} % Avoids extra height in rows
"""
}
Вот файл .tex, созданный Sphinx.
Код: Выделить всё
%% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt,english]{sphinxmanual}
\ifdefined\pdfpxdimen
\let\sphinxpxdimen\pdfpxdimen\else\newdimen\sphinxpxdimen
\fi \sphinxpxdimen=.75bp\relax
\ifdefined\pdfimageresolution
\pdfimageresolution= \numexpr \dimexpr1in\relax/\sphinxpxdimen\relax
\fi
%% let collapsible pdf bookmarks panel have high depth per default
\PassOptionsToPackage{bookmarksdepth=5}{hyperref}
\PassOptionsToPackage{booktabs}{sphinx}
\PassOptionsToPackage{colorrows}{sphinx}
\PassOptionsToPackage{warn}{textcomp}
\usepackage[utf8]{inputenc}
\ifdefined\DeclareUnicodeCharacter
% support both utf8 and utf8x syntaxes
\ifdefined\DeclareUnicodeCharacterAsOptional
\def\sphinxDUC#1{\DeclareUnicodeCharacter{"#1}}
\else
\let\sphinxDUC\DeclareUnicodeCharacter
\fi
\sphinxDUC{00A0}{\nobreakspace}
\sphinxDUC{2500}{\sphinxunichar{2500}}
\sphinxDUC{2502}{\sphinxunichar{2502}}
\sphinxDUC{2514}{\sphinxunichar{2514}}
\sphinxDUC{251C}{\sphinxunichar{251C}}
\sphinxDUC{2572}{\textbackslash}
\fi
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amstext}
\usepackage{babel}
\usepackage{tgtermes}
\usepackage{tgheros}
\renewcommand{\ttdefault}{txtt}
\usepackage[Bjarne]{fncychap}
\usepackage{sphinx}
\fvset{fontsize=auto}
\usepackage{geometry}
% Include hyperref last.
\usepackage{hyperref}
% Fix anchor placement for figures with captions.
\usepackage{hypcap}% it must be loaded after hyperref.
% Set up styles of URL: it should be placed after hyperref.
\urlstyle{same}
\usepackage{sphinxmessages}
% option 1
% \usepackage{etoolbox}
% \AtBeginEnvironment{tabulary}{\setlength{\extrarowheight}{0pt}}
% \renewcommand{\arraystretch}{1.5}
% option 2
% \usepackage[table]{xcolor}
% \renewcommand{\arraystretch}{2} % Reduces extra vertical space
% \setlength{\extrarowheight}{0pt} % Avoids extra height in rows
\title{Custom CSV Extension}
\date{Apr 20, 2025}
\release{0.0.1}
\author{Me}
\newcommand{\sphinxlogo}{\vbox{}}
\renewcommand{\releasename}{Release}
\makeindex
\begin{document}
\ifdefined\shorthandoff
\ifnum\catcode`\=\string=\active\shorthandoff{=}\fi
\ifnum\catcode`\"=\active\shorthandoff{"}\fi
\fi
\pagestyle{empty}
\sphinxmaketitle
\pagestyle{plain}
\sphinxtableofcontents
\pagestyle{normal}
\phantomsection\label{\detokenize{index::doc}}
\begin{savenotes}\sphinxattablestart
\sphinxthistablewithglobalstyle
\centering
\sphinxcapstartof{table}
\sphinxthecaptionisattop
\sphinxcaption{csv\sphinxhyphen{}table directive.}\label{\detokenize{index:id1}}
\sphinxaftertopcaption
\begin{tabulary}{\linewidth}[t]{TTT}
\sphinxtoprule
\sphinxstyletheadfamily
\sphinxAtStartPar
Name
&\sphinxstyletheadfamily
\sphinxAtStartPar
Score
&\sphinxstyletheadfamily
\sphinxAtStartPar
Category
\\
\sphinxmidrule
\sphinxtableatstartofbodyhook
\sphinxAtStartPar
Alice
&
\sphinxAtStartPar
95
&
\sphinxAtStartPar
High
\\
\sphinxhline
\sphinxAtStartPar
Bob
&
\sphinxAtStartPar
75
&
\sphinxAtStartPar
Medium
\\
\sphinxhline
\sphinxAtStartPar
Carol
&
\sphinxAtStartPar
55
&
\sphinxAtStartPar
Low
\\
\sphinxhline
\sphinxAtStartPar
Dave
&
\sphinxAtStartPar
40
&
\sphinxAtStartPar
Low
\\
\sphinxbottomrule
\end{tabulary}
\sphinxtableafterendhook\par
\sphinxattableend\end{savenotes}
\begin{savenotes}\sphinxattablestart
\sphinxthistablewithglobalstyle
\centering
\sphinxcapstartof{table}
\sphinxthecaptionisattop
\sphinxcaption{colored\sphinxhyphen{}csv\sphinxhyphen{}table directive}\label{\detokenize{index:id2}}
\sphinxaftertopcaption
\begin{tabulary}{\linewidth}[t]{TTT}
\sphinxtoprule
\sphinxstyletheadfamily
\sphinxAtStartPar
Name
&\sphinxstyletheadfamily
\sphinxAtStartPar
Score
&\sphinxstyletheadfamily
\sphinxAtStartPar
Category
\\
\sphinxmidrule
\sphinxtableatstartofbodyhook
\sphinxAtStartPar
Alice
&
\sphinxAtStartPar
95
&
\sphinxAtStartPar
\cellcolor{red} High
\\
\sphinxhline
\sphinxAtStartPar
Bob
&
\sphinxAtStartPar
75
&
\sphinxAtStartPar
\cellcolor{orange} Medium
\\
\sphinxhline
\sphinxAtStartPar
Carol
&
\sphinxAtStartPar
55
&
\sphinxAtStartPar
\cellcolor{green} Low
\\
\sphinxhline
\sphinxAtStartPar
Dave
&
\sphinxAtStartPar
40
&
\sphinxAtStartPar
\cellcolor{green} Low
\\
\sphinxbottomrule
\end{tabulary}
\sphinxtableafterendhook\par
\sphinxattableend\end{savenotes}
\renewcommand{\indexname}{Index}
\printindex
\end{document}
< /code>
Если я создаю таблицу с LaTex вместо Sphinx, я не вижу этого дополнительного расстояния, поэтому Sphinx должен как -то добавлять дополнительное расстояние. < /p>
\documentclass{article}
\usepackage{tabulary}
\usepackage[table]{xcolor} % Needed for \cellcolor
\begin{document}
\begin{tabulary}{\textwidth}{CCC}
\hline
Name & Score & Category \\
\hline
Alice & 95 & High \cellcolor{red} \\
Bob & 75 & Medium \cellcolor{orange} \\
Carol & 55 & Low \cellcolor{green} \\
Dave & 40 & Low \cellcolor{green} \\
\hline
\end{tabulary}
\end{document}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ith-sphinx