Ask Your Question

Title for table

asked 2021-01-06 12:10:25 +0200

Cyrille gravatar image

Is there a way to gice a title to a table above the row header or under the table. It would be nice.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-01-06 13:05:35 +0200

tmonteil gravatar image

I looked into the source code of table and there is unfortunately no title or footer attribute, so you have to hack something yourself. I guess you are using the notebook, so you have to modify the html version of the table, with the following method : table ->html -> string -> add some title -> html back -> display:

rows = [['a', 'b', 'c'], [100,2,3], [4,5,60]]
t = table(rows, header_row=True)
title = "My title"
footer = "My footer"
s = str(html(t))
new = '<h1>{}</h1> {}<h3>{}</h3>'.format(title,s,footer)

Now, you can see your hacked table with


You can change the size of the title and footer my modifying the <h1> and <h3> tags.

edit flag offensive delete link more


thanks. I always forget that we can mix html with python in sagemath.

Cyrille gravatar imageCyrille ( 2021-01-06 18:14:48 +0200 )edit

Unfortunately here is the outcome in a notebook

'<h1>My title</h1> <div class="notruncate">\n<table class="table_form">\n<tbody>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n<tr class ="row-a">\n<td><script type="math/tex">100</script></td>\n<td><script type="math/tex">2</script></td>\n<td><script type="math/tex">3</script></td>\n</tr>\n<tr class ="row-b">\n<td><script type="math/tex">4</script></td>\n<td><script type="math/tex">5</script></td>\n<td><script type="math/tex">60</script></td>\n</tr>\n</tbody>\n</table>\n</div><h3>My footer</h3>'

Cyrille gravatar imageCyrille ( 2021-01-06 18:17:04 +0200 )edit

Ok I have understud you nave forgoten html(new). Full thanks

Cyrille gravatar imageCyrille ( 2021-01-06 18:18:55 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-01-06 12:10:25 +0200

Seen: 357 times

Last updated: Jan 06 '21