Support row/colspans in tables

Georg Brandl avatarGeorg Brandl created an issue

Needs adapting the code from the existing docutils writer.

Comments (4)

  1. Anonymous

    I have created a patch for this issue that works for me but i haver never do any python before so it may be ugly, i don't know if i cover all case but most of them are working.

    This patch is only for latex

    # HG changeset patch
    # User Joel Wurtz <joel.wurtz@gmail.com>
    # Date 1304600637 -7200
    # Node ID 5fba470f5f487f1cad71eb69fc0ebbea441158a5
    # Parent  4b8d012cf82e2c5ca916f5f23c40a38854a027e9
    Add possibility to do multirow and multicolumn with latex
    
    diff -r 4b8d012cf82e -r 5fba470f5f48 sphinx/writers/latex.py
    --- a/sphinx/writers/latex.py	Fri Apr 29 14:01:54 2011 +0200
    +++ b/sphinx/writers/latex.py	Thu May 05 15:03:57 2011 +0200
    @@ -40,6 +40,7 @@
     %(fncychap)s
     %(longtable)s
     \usepackage{sphinx}
    +\usepackage{multirow}
     %(preamble)s
     
     \title{%(title)s}
    @@ -251,6 +252,9 @@
             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 +
    @@ -715,22 +719,41 @@
         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
     
    
  2. Anonymous

    Thanks for the patch Joel and thanks for the merge Georg ! In an incredible time coincidence, I was investigating this issue these last few days when I found this ticket. And this morning I just see the patch being merged !

    I actually only had one table with a span, but it worked for me. Thanks !

    Pierre

  3. Log in to comment
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.