Merge pull request #3381 from jfbu/3379slightrewrite

Simplify LaTeX mark-up for table column widths (ref #3379)
This commit is contained in:
Jean-François B 2017-02-04 09:02:04 +01:00 committed by GitHub
commit 6808e5aa2e
2 changed files with 16 additions and 15 deletions

View File

@ -6,7 +6,7 @@
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sphinx}[2017/01/16 v1.6 LaTeX package (Sphinx markup)]
\ProvidesPackage{sphinx}[2017/02/01 v1.6 LaTeX package (Sphinx markup)]
% we delay handling of options to after having loaded packages, because
% of the need to use \definecolor.
@ -24,6 +24,9 @@
******** ERROR !! PLEASE UPDATE titlesec.sty !!********^^J%
******** THIS VERSION SWALLOWS SECTION NUMBERS.********}}}}{}
\RequirePackage{tabulary}
% use of \X to minimize possibility of conflict with one-character column types
\newcolumntype{\X}[2]{p{\dimexpr
(\linewidth-\arrayrulewidth)*#1/#2-\tw@\tabcolsep-\arrayrulewidth\relax}}
\RequirePackage{makeidx}
% For framing code-blocks and warning type notices, and shadowing topics
\RequirePackage{framed}

View File

@ -1194,9 +1194,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
elif self.table.has_verbatim:
self.body.append('\n\\noindent\\begin{tabular}')
endmacro = '\\end{tabular}\n\n'
elif self.table.has_problematic and not self.table.colspec:
# if the user has given us tabularcolumns, accept them and use
# tabulary nevertheless
elif self.table.colspec:
self.body.append('\n\\noindent\\begin{tabulary}{\\linewidth}')
endmacro = '\\end{tabulary}\n\n'
elif self.table.has_problematic or self.table.colwidths:
self.body.append('\n\\noindent\\begin{tabular}')
endmacro = '\\end{tabular}\n\n'
else:
@ -1206,20 +1207,17 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.body.append(self.table.colspec)
elif self.table.colwidths:
total = sum(self.table.colwidths)
colspec = ['p{\\dimexpr(\\linewidth-\\arrayrulewidth)*%d/%d'
'-2\\tabcolsep-\\arrayrulewidth\\relax}' % (width, total)
colspec = ['\\X{%d}{%d}' % (width, total)
for width in self.table.colwidths]
self.body.append('{|%s|}\n' % '|'.join(colspec))
elif self.table.has_problematic:
colspec = ('*{%d}{\\X{1}{%d}|}' %
(self.table.colcount, self.table.colcount))
self.body.append('{|' + colspec + '}\n')
elif self.table.longtable:
self.body.append('{|' + ('l|' * self.table.colcount) + '}\n')
else:
if self.table.has_problematic:
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')
else:
self.body.append('{|' + ('L|' * self.table.colcount) + '}\n')
self.body.append('{|' + ('L|' * self.table.colcount) + '}\n')
if self.table.longtable and self.table.caption is not None:
self.body.append(u'\\caption{')
for caption in self.table.caption: