code: def _format_multicolumn(self, row, ilevels):
          r
          row2 = list(row[:ilevels])
          ncol = 1
          coltext = ''
  
          def append_col():
              # write multicolumn if needed
              if ncol > 1:
                  row2.append('\\multicolumn{{{ncol:d}}}{{{fmt:s}}}{{{txt:s}}}'
                              .format(ncol=ncol, fmt=self.multicolumn_format,
                                      txt=coltext.strip()))
              # don't modify where not needed
              else:
                  row2.append(coltext)
          for c in row[ilevels:]:
              # if next col has text, write the previous
              if c.strip():
                  if coltext:
                      append_col()
                  coltext = c
                  ncol = 1
              # if not, add it to the previous multicolumn
              else:
                  ncol += 1
          # write last column name
          if coltext:
              append_col()
          return row2
docs: r"""
          Combine columns belonging to a group to a single multicolumn entry
          according to self.multicolumn_format
  
          e.g.:
          a &  &  & b & c &
          will become
          \multicolumn{3}{l}{a} & b & \multicolumn{2}{l}{c}