Ask Your Question

Revision history [back]

There currently does not seem to be a way to specify the horizontal alignment of a table.

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

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).augment(b)
zc = vector((-c).list() + [0] * (A.nrows() + 1))
L = matrix(L.rows() + [zc])
rows = list(L)
header_row = ['$x_1$', '$x_2$', '$x_3$', r'$\epsilon_1$', r'$\epsilon_2$', r'$\epsilon_3$', '$b$']
header_column = ['', r'$\epsilon_1$', r'$\epsilon_2$', r'$\epsilon_3$', '$z$']
t = table(rows, header_row=header_row, header_column=header_column, frame=True)

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:

There currently does not seem to be a way to specify Specifying the horizontal alignment of a table.table is currently not supported.

Here is a workaround, tweaking the table's html 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])
I = identity_matrix(3)
L = block_matrix([[A, I]], subdivide=False).augment(b)
zc = vector((-c).list() + [0] * (A.nrows() + 1))
L = matrix(L.rows() A.augment(identity_matrix(A.ncols())).augment(b)
rows = L.rows() + [zc])
rows = list(L)
[zc]

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

header_row = ['$x_1$', '$x_2$', '$x_3$', r'$\epsilon_1$', r'$\epsilon_2$', r'$\epsilon_3$', '$b$']
header_column = ['', r'$\epsilon_1$', r'$\epsilon_2$', r'$\epsilon_3$', '$z$']
t = table(rows, header_row=header_row, header_column=header_column, 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:

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(identity_matrix(A.ncols())).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$', r'$\epsilon_1$', r'$\epsilon_2$', r'$\epsilon_3$', '$b$']
'$x_3$'] + eps + ['$b$']
header_column = ['', r'$\epsilon_1$', r'$\epsilon_2$', r'$\epsilon_3$', '$z$']
[''] + eps + ['$z$']
t = table(rows, header_row=header_row, header_column=header_column, 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:

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(identity_matrix(A.ncols())).augment(b)
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: