Ask Your Question
2

side by side html tables

asked 2011-09-11 22:51:30 +0100

calc314 gravatar image

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 flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
5

answered 2011-09-12 00:05:44 +0100

benjaminfjones gravatar image

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.

edit flag offensive delete link more

Comments

This is also a good answer.

kcrisman gravatar imagekcrisman ( 2011-09-12 12:05:27 +0100 )edit
1

answered 2011-09-12 12:05:18 +0100

kcrisman gravatar image

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)]
html.table(c,header=['x','f(x)','y','g(y)'])

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)$']]
html.table(T+L,header=True)
edit flag offensive delete link more
1

answered 2011-09-15 15:14:23 +0100

Eugene gravatar image

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>')
edit flag offensive delete link more

Comments

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

process91 gravatar imageprocess91 ( 2011-10-25 02:31:07 +0100 )edit
0

answered 2011-10-05 10:56:17 +0100

calc314 gravatar image

Thanks for all the help. This is working great!

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

Stats

Asked: 2011-09-11 22:51:30 +0100

Seen: 1,480 times

Last updated: Oct 05 '11