Commits

Georg Brandl committed b1c7aa5

Support table captions in LaTeX output.

  • Participants
  • Parent commits 9ada6a5

Comments (0)

Files changed (3)

 Bugs fixed
 ----------
 
+* Support table captions in LaTeX output.
+
 * Work around a bug in Jinja that caused "<generator ...>" to be
   emitted in HTML output.
 

File sphinx/latexwriter.py

         self.colspec = None
         self.had_head = False
         self.has_verbatim = False
+        self.caption = None
 
 
 class Desc(object):
         elif isinstance(parent, nodes.Admonition):
             self.body.append('{')
             self.context.append('}\n')
+        elif isinstance(parent, nodes.table):
+            self.table.caption = self.encode(node.astext())
+            raise nodes.SkipNode
         else:
-            self.builder.warn('encountered title node not in section, topic, admonition'
-                              ' or sidebar')
+            self.builder.warn('encountered title node not in section, topic, '
+                              'table, admonition or sidebar')
             self.body.append('\\textbf{')
             self.context.append('}\n')
         self.in_title = 1
         self.body = self.tablebody
     def depart_table(self, node):
         self.body = self._body
+        if self.table.caption is not None:
+            self.body.append('\n\\begin{threeparttable}\n'
+                             '\\caption{%s}\n' % self.table.caption)
         if self.table.has_verbatim:
             self.body.append('\n\\begin{tabular}')
         else:
             self.body.append('\\end{tabular}\n\n')
         else:
             self.body.append('\\end{tabulary}\n\n')
+        if self.table.caption is not None:
+            self.body.append('\\end{threeparttable}\n\n')
         self.table = None
         self.tablebody = None
 

File sphinx/texinputs/sphinx.sty

 \RequirePackage{framed}
 \RequirePackage{color}
 \RequirePackage{fancyvrb}
+\RequirePackage{threeparttable}
 
 % Redefine these colors to your liking in the preamble.
 \definecolor{TitleColor}{rgb}{0.126,0.263,0.361}