Ask Your Question
0

Title for table

asked 2021-01-06 05:10:25 -0600

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
1

answered 2021-01-06 06:05:35 -0600

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

html(new)

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

edit flag offensive delete link more

Comments

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

Cyrille gravatar imageCyrille ( 2021-01-06 11:14:48 -0600 )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 11:17:04 -0600 )edit

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

Cyrille gravatar imageCyrille ( 2021-01-06 11:18:55 -0600 )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

Stats

Asked: 2021-01-06 05:10:25 -0600

Seen: 39 times

Last updated: Jan 06