使用 booktabs 套件設計 sphinx LaTeX 表格的樣式

使用 booktabs 套件設計 sphinx LaTeX 表格的樣式

我正在嘗試改進 Sphinx 生成的 LaTeX 表格的外觀。特別是,我想使用書籤頂部、中間和底部規則並抑制垂直單元格分隔符號。

這個 rST 表:

+--------------+---+-----------+
|  simple text | 2 | 3         |
+==============+===+===========+
|  simple text | 2 | 3         |
+--------------+---+-----------+
|  simple text | 2 | 3         |
+--------------+---+-----------+

轉換為:

\begin{savenotes}\sphinxattablestart
\centering
\begin{tabulary}{\linewidth}[t]{JJJ}
\hline
\sphinxstyletheadfamily 
simple text
&\sphinxstyletheadfamily

 
2
&\sphinxstyletheadfamily 
3
\\
\hline
simple text
&
2

&
3
\\
\hline
simple text
&
2
&
3
\\
\hline
\end{tabulary}
\par
\sphinxattableend\end{savenotes}

我希望它隱藏為:

\begin{savenotes}\sphinxattablestart
\centering
\begin{tabulary}{\linewidth}[t]{JJJ}
\toprule
\sphinxstyletheadfamily 
simple text
&\sphinxstyletheadfamily 
2
&\sphinxstyletheadfamily 
3
\\
\toprule
simple text
&
2
&
3
\\
\midrule
simple text
&
2
&
3
\\
\bottomrule
\end{tabulary}
\par
\sphinxattableend\end{savenotes}

我可以從 conf.py 載入 booktabs。

目前的 Sphinx 文件在這裡https://www.sphinx-doc.org/en/master/latex.html意味著這種層級的控制無法透過 conf.py 取得,但頁面底部有一條註解暗示可以透過範本進行自訂:

作為一項實驗性功能,如果您的專案中有名為 _templates/latex.tex_t 的文件,Sphinx 可以使用使用者定義的 LaTeX 來源範本檔案。可以將其他檔案 longtable.tex_t、tabulary.tex_t 和 tabular.tex_t 新增至 _templates/ 以配置表格渲染的某些方面(例如標題位置)。

並且有一個指向它的參數,我在conf.py中設定如下:

templates_path = '_templates'

我新增了模板https://github.com/sphinx-doc/sphinx/tree/3.x/sphinx/templates/latex

不讀取模板。

問題:

  1. 這可以透過模板實現嗎?此功能在 Sphinx 1.6 中是實驗性的,可能已被刪除。
  2. 如果沒有,是否有辦法透過序言、sty 檔案或其他方式重新定義表格以使用 booktabs?

非常感謝。

相關內容