pdf - 调整 pdf 输出的表格宽度以完美适合线宽

标签 pdf latex python-sphinx pdflatex

我的公司使用 Sphinx 来创建我们的用户手册,并且我们正在广泛使用不同种类的表格。在许多情况下,需要手动调整表格的列宽才能生成高质量的 pdf 输出。

为此我尝试使用:

.. tabularcolumns:: |p{0.2\linewidth}|p{0.8\linewidth}|

+------+--------+
| A    | B      |
+------+--------+

我的意图是,表格应该完全适合周围的文本, 但有一点重叠。看起来百分比并没有考虑到内盒所占用的空间。

如何正确计算所需的数量,以便盒子整齐地适合空间?

最佳答案

使用 Sphinx 1.6 或更高版本,您可以使用

.. tabularcolumns:: |\Y{0.2}|\Y{0.8}|

(它是 \Y,而不是 Y。)请参阅 http://www.sphinx-doc.org/en/stable/markup/misc.html?highlight=tabularcolumns#directive-tabularcolumns .

在 Sphinx 1.5 或更高版本中,您可以使用 |\X{2}{10}|\X{8}{10}|

使用 Sphinx < 1.5,您需要一些特殊的 LaTeX,您可以从此代码中提取它

\newcolumntype{\X}[2]{p{\dimexpr
      (\linewidth-\arrayrulewidth)*#1/#2-2\tabcolsep-\arrayrulewidth\relax}}
\newcolumntype{\Y}[1]{p{\dimexpr
      #1\dimexpr\linewidth-\arrayrulewidth\relax-2\tabcolsep-\arrayrulewidth\relax}}

来自当前的sphinx.sty,它解释了\X\Y是如何定义的。

关于pdf - 调整 pdf 输出的表格宽度以完美适合线宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690298/

相关文章:

r - 如何更改 Rmarkdown、LaTeX 和 .pdf 中表格的字体大小?

python-sphinx - 在Python sphinx中,如何链接到_static目录中的文件

python - 狮身人面像自动摘要 "toctree contains reference to nonexisting document"警告

windows - 用于 Windows 的 PDF 文件

java - 使用ICEpdf "inside"java程序

pdf - 使用 iText 为带标签的 pdf (PDF/UA) 中的图像添加替代文本

python - PDF 抓取 : how to automate the creation of txt files for each pdf scraped in Python?

r - 使用 knit 和 Rstudio 自动调整 LaTeX 表格宽度以适合 pdf

search - 为什么在我的 Sphinx 中无法搜索到该短语?

php - 将页面保存为 PDF 或 HTML,但包含所有条目