mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add a "longtable" flag option to the "tabularcolumn" directive.
If used, the latex writer will use a \longtable instead of \tabular(y)
This commit is contained in:
parent
b1dbe95255
commit
646c75ad9b
@ -396,11 +396,14 @@ class TabularColumns(Directive):
|
||||
required_arguments = 1
|
||||
optional_arguments = 0
|
||||
final_argument_whitespace = True
|
||||
option_spec = {}
|
||||
option_spec = {
|
||||
'longtable': directives.flag,
|
||||
}
|
||||
|
||||
def run(self):
|
||||
node = addnodes.tabular_col_spec()
|
||||
node['spec'] = self.arguments[0]
|
||||
node['longtable'] = 'longtable' in self.options
|
||||
return [node]
|
||||
|
||||
|
||||
|
@ -34,6 +34,7 @@ HEADER = r'''%% Generated by Sphinx.
|
||||
%(babel)s
|
||||
%(fontpkg)s
|
||||
%(fncychap)s
|
||||
%(longtable)s
|
||||
\usepackage{sphinx}
|
||||
%(preamble)s
|
||||
|
||||
@ -111,9 +112,11 @@ class Table(object):
|
||||
self.col = 0
|
||||
self.colcount = 0
|
||||
self.colspec = None
|
||||
self.rowcount = 0
|
||||
self.had_head = False
|
||||
self.has_verbatim = False
|
||||
self.caption = None
|
||||
self.longtable = False
|
||||
|
||||
|
||||
class Desc(object):
|
||||
@ -140,6 +143,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
'babel': '\\usepackage{babel}',
|
||||
'fontpkg': '\\usepackage{times}',
|
||||
'fncychap': '\\usepackage[Bjarne]{fncychap}',
|
||||
'longtable': '\\usepackage{longtable}',
|
||||
'preamble': '',
|
||||
'title': '',
|
||||
'date': '',
|
||||
@ -585,6 +589,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
|
||||
def visit_tabular_col_spec(self, node):
|
||||
self.next_table_colspec = node['spec']
|
||||
self.next_table_longtable = node['longtable']
|
||||
raise nodes.SkipNode
|
||||
|
||||
def visit_table(self, node):
|
||||
@ -594,15 +599,18 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
(self.curfilestack[-1], node.line or ''))
|
||||
self.table = Table()
|
||||
self.tablebody = []
|
||||
self.table.longtable = self.next_table_longtable
|
||||
# Redirect body output until table is finished.
|
||||
self._body = self.body
|
||||
self.body = self.tablebody
|
||||
def depart_table(self, node):
|
||||
self.body = self._body
|
||||
if self.table.caption is not None:
|
||||
if not self.table.longtable and self.table.caption is not None:
|
||||
self.body.append('\n\\begin{threeparttable}\n'
|
||||
'\\caption{%s}\n' % self.table.caption)
|
||||
if self.table.has_verbatim:
|
||||
if self.table.longtable:
|
||||
self.body.append('\n\\begin{longtable}')
|
||||
elif self.table.has_verbatim:
|
||||
self.body.append('\n\\begin{tabular}')
|
||||
else:
|
||||
self.body.append('\n\\begin{tabulary}{\\textwidth}')
|
||||
@ -616,12 +624,31 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.body.append('{|' + colspec + '}\n')
|
||||
else:
|
||||
self.body.append('{|' + ('L|' * self.table.colcount) + '}\n')
|
||||
if self.table.longtable and self.table.caption is not None:
|
||||
self.body.append('\\caption{%s} \\\\\n' % self.table.caption)
|
||||
|
||||
if self.table.longtable:
|
||||
self.body.append('\\hline\n')
|
||||
self.body.append('\\endfirsthead\n\n')
|
||||
self.body.append('\multicolumn{%s}{c}%%\n' % self.table.colcount)
|
||||
self.body.append('{{\\bfseries \\tablename\\ \\thetable{} -- %s}} \\\\\n' % _('continued from previous page'))
|
||||
self.body.append('\\hline\n')
|
||||
self.body.append('\\endhead\n\n')
|
||||
self.body.append('\\hline \multicolumn{%s}{|r|}{{%s}} \\\\ \\hline\n' % (
|
||||
self.table.colcount, _('Continued on next page')))
|
||||
self.body.append('\\endfoot\n\n')
|
||||
self.body.append('\\hline\n')
|
||||
self.body.append('\\endlastfoot\n\n')
|
||||
else:
|
||||
self.body.append('\\hline\n')
|
||||
self.body.extend(self.tablebody)
|
||||
if self.table.has_verbatim:
|
||||
if self.table.longtable:
|
||||
self.body.append('\\end{longtable}\n\n')
|
||||
elif self.table.has_verbatim:
|
||||
self.body.append('\\end{tabular}\n\n')
|
||||
else:
|
||||
self.body.append('\\end{tabulary}\n\n')
|
||||
if self.table.caption is not None:
|
||||
if not self.table.longtable and self.table.caption is not None:
|
||||
self.body.append('\\end{threeparttable}\n\n')
|
||||
self.table = None
|
||||
self.tablebody = None
|
||||
@ -640,8 +667,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
if self.next_table_colspec:
|
||||
self.table.colspec = '{%s}\n' % self.next_table_colspec
|
||||
self.next_table_colspec = None
|
||||
self.body.append('\\hline\n')
|
||||
self.table.had_head = True
|
||||
# self.body.append('\\hline\n')
|
||||
# self.table.had_head = True
|
||||
def depart_thead(self, node):
|
||||
self.body.append('\\hline\n')
|
||||
|
||||
@ -655,6 +682,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.table.col = 0
|
||||
def depart_row(self, node):
|
||||
self.body.append('\\\\\n')
|
||||
self.table.rowcount += 1
|
||||
|
||||
def visit_entry(self, node):
|
||||
if node.has_key('morerows') or node.has_key('morecols'):
|
||||
|
Loading…
Reference in New Issue
Block a user