Simplify LaTeX mark-up for table column widths (ref #3379)

The ``\X`` token is used as column-specifier: this does not define or
redefine ``\X`` as a LaTeX macro. Using a letter could have led to
conflict with user defined column types or table packages. This column
specifier takes two arguments which must be positive integers, as
produced by LaTeX writer for ``:widths:`` option or for equal widths
columns. As it always uses ``\linewidth`` the latter was not abstracted
into a third argument.
This commit is contained in:
jfbu 2017-02-01 19:50:53 +01:00
parent ecdcb4c123
commit e97d4e955b
2 changed files with 6 additions and 5 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

@ -1206,14 +1206,12 @@ 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))
else:
if self.table.has_problematic:
colspec = ('*{%d}{p{\\dimexpr(\\linewidth-\\arrayrulewidth)/%d'
'-2\\tabcolsep-\\arrayrulewidth\\relax}|}' %
colspec = ('*{%d}{\\X{1}{%d}|}' %
(self.table.colcount, self.table.colcount))
self.body.append('{|' + colspec + '}\n')
elif self.table.longtable: