# Centering a result

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

Sort by » oldest newest most voted

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$']


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:

more