'String form of Matrix as a table.
``printer`` is the printer to use for on the elements (generally
something like StrPrinter())
``rowstart`` is the string used to start each row (by default \'[\').
``rowend`` is the string used to end each row (by default \']\').
``rowsep`` is the string used to separate rows (by default a newline).
``colsep`` is the string used to separate columns (by default \', \').
``align`` defines how the elements are aligned. Must be one of \'left\',
\'right\', or \'center\'.  You can also use \'<\', \'>\', and \'^\' to mean the
same thing, respectively.
This is used by the string printer for Matrix.
Examples
>>> from sympy import Matrix
>>> from sympy.printing.str import StrPrinter
>>> M = Matrix([[1, 2], [-33, 4]])
>>> printer = StrPrinter()
>>> M.table(printer)
\'[  1, 2]\n[-33, 4]\'
>>> print(M.table(printer))
[  1, 2]
[-33, 4]
>>> print(M.table(printer, rowsep=\',\n\'))
[  1, 2],
[-33, 4]
>>> print(\'[%s]\' % M.table(printer, rowsep=\',\n\'))
[[  1, 2],
[-33, 4]]
>>> print(M.table(printer, colsep=\' \'))
[  1 2]
[-33 4]
>>> print(M.table(printer, align=\'center\'))
[ 1 , 2]
[-33, 4]
>>> print(M.table(printer, rowstart=\'{\', rowend=\'}\'))
{  1, 2}
{-33, 4}'

def table(self, printer, rowstart='[', rowend=']', rowsep='\n', colsep=',    ', align='right'):

    if ((self.rows == 0) or (self.cols == 0)):
        return '[]'
    res = []
    maxlen = ([0] * self.cols)
    for i in range(self.rows):
        res.append([])
        for j in range(self.cols):
            s = printer._print(self[(i, j)])
            res[(-1)].append(s)
            maxlen[j] = max(len(s), maxlen[j])
    align = {'left': 'ljust', 'right': 'rjust', 'center': 'center', '<': 'ljust', '>': 'rjust', '^': 'center'}[align]
    for (i, row) in enumerate(res):
        for (j, elem) in enumerate(row):
            row[j] = getattr(elem, align)(maxlen[j])
        res[i] = ((rowstart + colsep.join(row)) + rowend)
    return rowsep.join(res)
