From 303f163b0a9ddf15ce425c171dc4c84158c59d2d Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 21 Jun 2016 22:37:41 +0200 Subject: [PATCH 1/4] Fix #2707: (latex) the column width is badly computed for tabular MEMO: the used formula is correct as long as package array is loaded. Package array (which modifies how the width of vertical rules is counted in the total width of the tabular) is a dependency of packages tabulary, and eqparbox, and possibly others which are currently loaded by sphinx.sty. Even if usage of package tabulary is dropped in future version of sphinx.sty, there would still remain the dependency on array via eqparbox, and the formula configured in latex.py will remain correct. --- sphinx/writers/latex.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index e6199bc1b6..ef1dd744de 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1052,9 +1052,9 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append(self.table.colspec) else: if self.table.has_problematic: - colwidth = 0.95 / self.table.colcount - colspec = ('p{%.3f\\linewidth}|' % colwidth) * \ - self.table.colcount + colspec = ('p{\\dimexpr(\\linewidth-\\arrayrulewidth)/%d' + '-2\\tabcolsep-\\arrayrulewidth\\relax}|' % \ + self.table.colcount) * self.table.colcount self.body.append('{|' + colspec + '}\n') elif self.table.longtable: self.body.append('{|' + ('l|' * self.table.colcount) + '}\n') From 8e45f54d0705b9558f52078ad8c8b48554589c8b Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 21 Jun 2016 23:19:56 +0200 Subject: [PATCH 2/4] Fix #2707: output more compact ``*{N}{p{...}}`` notation --- sphinx/writers/latex.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index ef1dd744de..6b6b333687 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1052,9 +1052,9 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append(self.table.colspec) else: if self.table.has_problematic: - colspec = ('p{\\dimexpr(\\linewidth-\\arrayrulewidth)/%d' - '-2\\tabcolsep-\\arrayrulewidth\\relax}|' % \ - self.table.colcount) * self.table.colcount + colspec = ('*{%d}{p{\\dimexpr(\\linewidth-\\arrayrulewidth)/%d' + '-2\\tabcolsep-\\arrayrulewidth\\relax}|}' % \ + (self.table.colcount, self.table.colcount)) self.body.append('{|' + colspec + '}\n') elif self.table.longtable: self.body.append('{|' + ('l|' * self.table.colcount) + '}\n') From c88193e3dfd5e689976fa080f0a789f1bf25d6d2 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 21 Jun 2016 23:25:06 +0200 Subject: [PATCH 3/4] fix flake8 violation --- sphinx/writers/latex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 6b6b333687..84c21e8b3a 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1053,7 +1053,7 @@ class LaTeXTranslator(nodes.NodeVisitor): else: if self.table.has_problematic: colspec = ('*{%d}{p{\\dimexpr(\\linewidth-\\arrayrulewidth)/%d' - '-2\\tabcolsep-\\arrayrulewidth\\relax}|}' % \ + '-2\\tabcolsep-\\arrayrulewidth\\relax}|}' % (self.table.colcount, self.table.colcount)) self.body.append('{|' + colspec + '}\n') elif self.table.longtable: From 4ab9854483ded6a4ae451f99a7ee70c0f1d6a1df Mon Sep 17 00:00:00 2001 From: jfbu Date: Wed, 22 Jun 2016 09:36:10 +0200 Subject: [PATCH 4/4] Update CHANGES for PR#2708 --- CHANGES | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index 11c9b4135a..9432c8cb9f 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,7 @@ Incompatible changes * LaTeX package newfloat (which was shipped with Sphinx since 1.3.4) is no longer a dependency of sphinx.sty (ref #2660) + Features added -------------- @@ -33,10 +34,14 @@ Features added * public names for latex environments and parameters used by note, warning, and other admonition types, allowing full customizability from the ``'preamble'`` key (ref: feature request #2674, #2685) +* latex better computes column widths of some tables (as a result, there will + be slight changes as tables now correctly fill the line with; ref: #2708) Bugs fixed ---------- +* #2707: (latex) the column width is badly computed for tabular + Documentation -------------