Commits

Georg Brandl committed 5098aee

Even more tweaking of the latex tabular environment selection code.

Comments (0)

Files changed (2)

doc/markup/misc.rst

 
 .. warning::
 
-   Tables that contain block-level elements such as object descriptions, literal
-   blocks, blockquotes or any kind of lists cannot be set with ``tabulary``.
-   They are therefore set with the standard LaTeX ``tabular`` environment.
-   Also, the verbatim environment used for literal blocks only works in
-   ``p{width}`` columns, which means that by default, Sphinx generates such
-   column specs for such tables.  Use the :rst:dir:`tabularcolumns` directive to
-   get finer control over such tables.
+   Tables that contain list-like elements such as object descriptions,
+   blockquotes or any kind of lists cannot be set out of the box with
+   ``tabulary``.  They are therefore set with the standard LaTeX ``tabular``
+   environment if you don't give a ``tabularcolumns`` directive.  If you do, the
+   table will be set with ``tabulary``, but you must use the ``p{width}``
+   construct for the columns that contain these elements.
+
+   Literal blocks do not work with ``tabulary`` at all, so tables containing a
+   literal block are always set with ``tabular``.  Also, the verbatim
+   environment used for literal blocks only works in ``p{width}`` columns, which
+   means that by default, Sphinx generates such column specs for such tables.
+   Use the :rst:dir:`tabularcolumns` directive to get finer control over such
+   tables.

sphinx/writers/latex.py

         self.rowcount = 0
         self.had_head = False
         self.has_problematic = False
+        self.has_verbatim = False
         self.caption = None
         self.longtable = False
 
                              u'\\capstart\\caption{%s}\n' % self.table.caption)
         if self.table.longtable:
             self.body.append('\n\\begin{longtable}')
-        elif self.table.has_problematic:
+            endmacro = '\\end{longtable}\n\n'
+        elif self.table.has_verbatim:
             self.body.append('\n\\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
+            self.body.append('\n\\begin{tabular}')
+            endmacro = '\\end{tabular}\n\n'
         else:
             self.body.append('\n\\begin{tabulary}{\\linewidth}')
+            endmacro = '\\end{tabulary}\n\n'
         if self.table.colspec:
             self.body.append(self.table.colspec)
         else:
         else:
             self.body.append('\\hline\n')
         self.body.extend(self.tablebody)
-        if self.table.longtable:
-            self.body.append('\\end{longtable}\n\n')
-        elif self.table.has_problematic:
-            self.body.append('\\end{tabular}\n\n')
-        else:
-            self.body.append('\\end{tabulary}\n\n')
+        self.body.append(endmacro)
         if not self.table.longtable and self.table.caption is not None:
             self.body.append('\\end{threeparttable}\n\n')
         self.table = None
             hlcode = hlcode.replace('\\begin{Verbatim}',
                                     '\\begin{OriginalVerbatim}')
             self.table.has_problematic = True
+            self.table.has_verbatim = True
         # get consistent trailer
         hlcode = hlcode.rstrip()[:-14] # strip \end{Verbatim}
         hlcode = hlcode.rstrip() + '\n'