Commits

Anonymous committed 9b4e41b

Add multirow / multicol support for latex

Comments (0)

Files changed (1)

sphinx/writers/latex.py

 %(fncychap)s
 %(longtable)s
 \usepackage{sphinx}
+\usepackage{multirow}
 %(preamble)s
 
 \title{%(title)s}
         self.no_contractions = 0
         self.compact_list = 0
         self.first_param = 0
+        self.previous_spanning_row = 0
+        self.previous_spanning_column = 0
+        self.remember_multirow = {}
 
     def astext(self):
         return (HEADER % self.elements +
     def visit_row(self, node):
         self.table.col = 0
     def depart_row(self, node):
-        self.body.append('\\\\\\hline\n')
+        if self.previous_spanning_row == 1:
+            self.previous_spanning_row = 0
+            self.body.append('\\\\\n')
+        else:
+            self.body.append('\\\\\\hline\n')
         self.table.rowcount += 1
 
     def visit_entry(self, node):
-        if 'morerows' in node or 'morecols' in node:
-            raise UnsupportedError('%s:%s: column or row spanning cells are '
-                                   'not yet implemented.' %
-                                   (self.curfilestack[-1], node.line or ''))
+        if self.remember_multirow.has_key('0') and self.remember_multirow['0'] > 1:
+            self.body.append(' & ')
         if self.table.col > 0:
             self.body.append(' & ')
         self.table.col += 1
+        self.context.append('')
+        if 'morerows' in node:
+            self.body.append(' \multirow{')
+            self.previous_spanning_row = 1
+            self.body.append(str(node.get('morerows') + 1))
+            self.body.append('}{*}{')
+            self.context.append('}')
+            self.remember_multirow[str(self.table.col)] = node.get('morerows') + 1;
+        if 'morecols' in node:
+            self.body.append(' \multicolumn{')
+            self.body.append(str(node.get('morecols') + 1))
+            if self.table.col == 1:
+                self.body.append('}{|l|}{')
+            else:
+                self.body.append('}{l|}{')
+            self.context.append('}')
         if isinstance(node.parent.parent, nodes.thead):
             self.body.append('\\textbf{')
             self.context.append('}')
-        else:
-            self.context.append('')
+        if self.remember_multirow.has_key(str(self.table.col + 1)) and self.remember_multirow[str(self.table.col + 1)] > 1:
+            self.remember_multirow[str(self.table.col + 1)] -= 1
+            self.context.append(' & ')
     def depart_entry(self, node):
         self.body.append(self.context.pop()) # header
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.