# side by side html tables

Is there a way to display two html tables (of different sizes) side by side?

Here is a simple, silly example. Can I display the arrays below in side by side tables?

a=[[i,i^2] for i in range(0,10)]

b=[[i,i^3] for i in range(0,15)]

html.table(a)

html.table(b)

edit retag close merge delete

Sort by » oldest newest most voted

You can insert html commands to wrap the two tables into a larger table. Something like:

a=[[i,i^2] for i in range(0,10)]
b=[[i,i^3] for i in range(0,15)]
html('<table><tr><td>')
html.table(a)
html('</td><td>')
html.table(b)
html('</td></tr></table>')


You can change the table (and row and column) style to your liking by modifying the html commands that wrap the html.table calls.

more

This is also a good answer.

( 2011-09-12 05:05:27 -0500 )edit

If your tables are the same length, you can try to make just one table - I do this sometimes.

a=[[i,i^2] for i in range(0,10)]
b=[[i,i^3] for i in range(0,10)]
c=[flatten(z) for z in zip(a,b)]


As a corollary for your case (not the same length), it's possible to insert None and then replace that with ''. Here's one I've actually used. It's a bit annoying, but doable. In this case I really didn't know how big they would be ahead of time, because n was potentially much bigger than 7.

n=7
L = map(None,[p for p in prime_range(n+1) if p%4==1],[p for p in prime_range(n+1) if p%4==3])
L = [['',l[1]] if l[0] is None else l for l in L]
T = [['$p\equiv 1\\text{ mod }(4)$','$p\equiv 3\\text{ mod }(4)$']]

more

You can also play with div tags:

a=[[i,i^2] for i in range(0,10)]
b=[[i,i^3] for i in range(0,15)]

html('<div style="float:left; width:256px;">')
html.table(a)
html('</div><div style="float:right; width:256px">')
html.table(b)
html('</div>')

more

From a web design perspective, this is the proper way to do it.

( 2011-10-24 19:31:07 -0500 )edit

Thanks for all the help. This is working great!

more