Ask Your Question
1

Centering a result

asked 2020-10-11 09:16:15 +0100

Cyrille gravatar image

A simple question. I construct the table t (see the following code), and I want the table displayed centered in the cell. I do not know how since I use Sagecell. I wonder if through html display, there is a way to achieve this.

 A=matrix(QQ,[[(1/2),(1/4),0],[1,3,-1], [1,1,0]])
b = vector(QQ,[100, 200, 300])
c = vector(QQ,[40, 50, 60])
I=identity_matrix(3)
L=block_matrix([[A,I]],subdivide=False)
L=L.augment(b)
n=A.nrows()
z1=vector([0 for i in range(n+1)])
c=flatten(-c)
z1=flatten(z1)
zc=vector(c+z1)
L=matrix(L.rows()+[zc])
rows = list(L)
t = table(rows, header_row=['$x_1$', '$x_2$','$x_3$','$\\epsilon_1$','$\\epsilon_2$','$\\epsilon_3$','$b$'], header_column=['','$\\epsilon_1$','$\\epsilon_2$','$\\epsilon_3$','z'], frame=True)
show(LatexExpr(r"\text{Le tableau initial du simplex (ou premier dictionnaire)   est     :}"))
show(t)

I encounter the same problem for displaying plots.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-10-11 20:59:25 +0100

slelievre gravatar image

updated 2020-10-11 21:48:37 +0100

Specifying the horizontal alignment of a table is currently not supported.

Here is a workaround, tweaking the table's HTML representation by hand.

The code is slightly streamlined along the way.

Define a matrix, two vectors, an augmented matrix, the table rows:

A = matrix(QQ, [[1/2, 1/4, 0], [1, 3, -1], [1, 1, 0]])
b = vector(QQ, [100, 200, 300])
c = vector(QQ, [40, 50, 60])
zc = vector((-c).list() + [0] * (A.nrows() + 1))
L = A.augment(A.parent().identity_matrix()).augment(b)
rows = L.rows() + [zc]

Setup the header row and header column and define the table:

eps = [fr'$\varepsilon_{i}$' for i in range(1, 4)]
header_row = ['$x_1$', '$x_2$', '$x_3$'] + eps + ['$b$']
header_column = [''] + eps + ['$z$']
t = table(rows, header_row=hrow, header_column=hcol, frame=True)

Show an introductory sentence and the table:

show(LatexExpr(r"\text{Le tableau initial du simplexe (ou premier dictionnaire) est:}"))
s = str(t._html_()).replace('<table ', '<table align="center" ')
html(s)

Demo on SageCell:

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: 2020-10-11 09:16:15 +0100

Seen: 591 times

Last updated: Oct 11 '20