def rst_dict_table(dict_, key_format=str, val_format=str, header=None,
                   sort=True):
    keys, values = zip(*dict_.items())
    keys = map(key_format, keys)
    values = map(val_format, values)
    nckey = max(map(len, keys))
    ncval = max(map(len, values))
    if header:
        khead, vhead = header
        nckey = max(nckey, len(khead))
        ncval = max(ncval, len(vhead))
    divider = "{}  {}".format('='*nckey, '='*ncval)
    def row(key, val):
        fmt = '{{0:{0}s}}  {{1}}'.format(nckey, ncval)
        return fmt.format(key, val)
    lines = [divider]
    if header:
        lines.extend((row(*header), divider))
    params = zip(keys, values)
    if sort:
        params = sorted(params)
    for key, val in params:
        fmt = '{{0:{0}s}}  {{1}}'.format(nckey, ncval)
        lines.append(fmt.format(key, val))
    lines.append(divider)
    return '\n'.join(lines)