Ask Your Question
1

Is there a way to center a sagecell result

asked 2022-03-17 10:19:59 +0100

Cyrille gravatar image

I have some tables displayed in Sagecell but I do not know how to center them. Is there a way ?

edit retag flag offensive close merge delete

Comments

Minimal example please.

slelievre gravatar imageslelievre ( 2022-03-19 14:54:14 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2022-03-19 16:03:11 +0100

dsejas gravatar image

updated 2022-03-19 16:04:53 +0100

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!

edit flag offensive delete link more

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: 2022-03-17 10:19:59 +0100

Seen: 158 times

Last updated: Mar 19 '22