Is there a way to center a sagecell result
I have some tables displayed in Sagecell but I do not know how to center them. Is there a way ?
I have some tables displayed in Sagecell but I do not know how to center them. Is there a way ?
Hello, @Cyrille! As pointed by slelievre, I could have used a minimal working example; however, from what I understand, the following should achieve the desired result:
rows = [['a', 'b', 'c'], [100,2,3], [4,5,60]]
t = table(rows)
t_html = '<center>' + html(t) + '</center>'
html(t_html)
I have defined a simple table t
with rows rows
for the purpose of this example, but this should work with any other Sage table. The key lines here are the last two. SageCell is, in essence, a webpage, so it can be manipulated by means of adequate HTML tags and CSS files in any conceivable ways.
The html
command can convert Sage objects into HTML notation for you. That's what I did in the third line with the html(t)
part. I also surrounded this code with the center
tag from the HTML language, which is what achieves the desired effect. I stored the resulting code (as text or string) into the variable t_html
(i.e., up to this point, you have the HTML code to create a centered table as text inside t_html
).
Another thing the html
command from Sage does is to take some HTML code and "pass it" to the browser so it renders it as part of the SageCell webpage. That's what the last line does. And voilá!
Hope this helps!
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2022-03-17 10:19:59 +0100
Seen: 158 times
Last updated: Mar 19 '22
Minimal example please.