# Table frame not showing in Jupyter Notebook and inconsistent in other environments

Hello, Sage community!

The table command in Sage has this useful option called frame. If I set frame=True in SageCell, CoCalc, the Sage terminal and SageTeX, the result is the expected: a frame is shown for the corresponding table. However, the same command does not work properly in Jupyter Notebooks. Also, the results are quite different in SageCell and CoCalc.

The following three images show the result of executing the following commands:

rows = [[100,2,3], [4,5,60]]
t = table(rows, frame=True)
show(t)


This is the result in SageCell:

This is the result in CoCalc:

This is the result in Jupyter (executed using sage -n jupyter):

Here are my questions:

1. Why is the frame=True option not working in Jupyter?
2. Why the difference in the results?
3. Is there any way to make these results consistent through these environments?
edit retag close merge delete

The table module was written by John Palmieri (and reviewed by me:) before the inclusion of the Jupyter notebook in Sage. You are welcome to contribute to Sage to fix those issues.

( 2020-04-06 21:02:56 +0200 )edit

Hello, @Sébastien! I have been thinking about enhancing the table module a little bit, ever since I was translating Prof. Bard's "Sage for Undergraduates" to Spanish. Basically, I would like a little bit more of customization. This could be a good opportunity to do that and fix the issues you mentioned.

I hope you don't mind my asking: How can I send patches of code or new code if I don't know how to use git? (Of course, I can learn, but it will take me a few weeks.)

( 2020-04-07 02:20:15 +0200 )edit

Perhaps it is worth writing first to Andrey Novoseltsev, the maintainer of SageCell. How has he managed to get working the frame=True option?

( 2020-04-07 03:50:49 +0200 )edit

"How can I send patches of code or new code if I don't know how to use git? (Of course, I can learn, but it will take me a few weeks.)"

It seems to be a nice question to ask on ask! :)

( 2020-04-07 09:53:13 +0200 )edit

Hello, @Sébastien! I was about to post the question, but I can see that you already did. Thank you very much, I appreciate it! I hope I can collaborate with the Sage community!

( 2020-04-10 18:57:11 +0200 )edit

Sort by » oldest newest most voted

The appearance of tables strongly depends of the active CSS attributes applying to them. For example, as shown in the screen capture below, if you add and evaluate the following code in a Jupyter notebook, you will get tables more similar to those in SageCell:

%%html
<style>
table.table_form{
border: 1px solid gray;
border-collapse: separate;
border-spacing: 2px;}
table.table_form td {
border: 1px solid gray;
color: #00a;
background-color: #f8f8f8;
text-align: left;
font-size:medium}
</style>


Now, consider the code

rows = [[100,2,3], [4,5,60]]
t = table(rows, frame=True)
print(html(t))


The output is

<div class="notruncate">
<table border="1" class="table_form">
<tbody>
<tr class ="row-a">
<td><script type="math/tex">100</script></td>
<td><script type="math/tex">2</script></td>
<td><script type="math/tex">3</script></td>
</tr>
<tr class ="row-b">
<td><script type="math/tex">4</script></td>
<td><script type="math/tex">5</script></td>
<td><script type="math/tex">60</script></td>
</tr>
</tbody>
</table>
</div>


Look at the second line. The border attribute of table is not longer supported in HTML5. Since it has no effect in a modern browser, the frame is not shown.

In SageCell, however, the frame option works. So I imagine that the base code has been modified somehow. Quite surely the same patch could be applied for Jupyter notebooks.

Reading \$SAGE_SRC/sage/misc/table.py, it seems that the problem comes from lines 720-723, that is,

if self._options['frame']:
frame = 'border="1"'
else:
frame = ''


Perhaps it would suffice to replace frame = 'border="1"' by

frame = 'style="border-style: solid"'


or something similar.

more

Thank you very much, @Juanjo! This was really helpful. If I could give you more than one upvote, I would do it.

( 2020-04-07 02:11:12 +0200 )edit

Many thanks, @dsejas. I also learn a lot from your questions and answers. By the way, it is nice to know from a comment above that there exists a translation to Spanish of Sage for Undergraduates and that you are precisely the translator ;-) . I have quickly searched, found and downloaded it!

( 2020-04-07 03:44:08 +0200 )edit

I really hope the translation will be useful for everybody, especially for Sage beginners and undergraduates.

If you are interested, I will be uploading information regularly on the book's website: www.sage-para-estudiantes.com.

Disclaimer: This is not intended as a shameless publicity.

( 2020-04-07 05:22:44 +0200 )edit