Render table row number in separate column
This commit is contained in:
parent
8f1b233dbe
commit
245a5ee46e
BIN
example.pdf
BIN
example.pdf
Binary file not shown.
@ -145,10 +145,10 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
)
|
||||
|
||||
def render_table(self, token):
|
||||
align = ['X' for col in token.column_align]
|
||||
align = [r'l@{\hspace{1ex}}'] + ['X' for col in token.column_align]
|
||||
if hasattr(token, 'header'):
|
||||
for i, col in enumerate(token.header.children):
|
||||
align[i] += '[{}]'.format(col.weight)
|
||||
align[i+1] += '[{}]'.format(col.weight)
|
||||
|
||||
result = [
|
||||
format('{\\footnotesize\\begin{longtabu} to \\dimexpr\\columnwidth-<lmarg>\\relax [r] {'),
|
||||
@ -168,21 +168,24 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
return ''.join(result)
|
||||
|
||||
def render_table_header(self, token):
|
||||
cells1 = ['{\\bfseries Column ' + child.label + '}' for child in token.children]
|
||||
cells2 = ['{\\bfseries ' + self.render_inner(child) + '}' for child in token.children]
|
||||
cells1 = []
|
||||
cells2 = []
|
||||
|
||||
for cell in token.children:
|
||||
if cell.colnum == 0:
|
||||
cells1.append('\\multicolumn{2}{l}{\\bfseries Column ' + cell.label + '}')
|
||||
cells2.append('\\multicolumn{2}{l}{\\bfseries ' + self.render_inner(cell) + '}')
|
||||
else:
|
||||
cells1.append('{\\bfseries Column ' + cell.label + '}')
|
||||
cells2.append('{\\bfseries ' + self.render_inner(cell) + '}')
|
||||
|
||||
return ' & '.join(cells1) + ' \\\\\\midrule\n' + ' & '.join(cells2) + ' \\\\'
|
||||
|
||||
def render_table_row(self, token):
|
||||
cells = [self.render_table_cell(child) for child in token.children]
|
||||
cells = [(token.children[0].label + '.') if token.children[0].label else ''] + [self.render_table_cell(child) for child in token.children]
|
||||
return ' & '.join(cells) + ' \\\\'
|
||||
|
||||
def render_table_cell(self, token):
|
||||
if token.colnum == 0 and token.label:
|
||||
return format(r'\makebox[2.2em][l]{<rownum>.}<content>',
|
||||
rownum=token.label,
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
else:
|
||||
return self.render_inner(token)
|
||||
|
||||
def render_document(self, token):
|
||||
|
Loading…
Reference in New Issue
Block a user