Above are great efforts and user need good libraries for having table in the slack.
I have been using prettytable module of python to convert my tablular data into pretty table and post them as code block get my perfect tables in slack messages.
pip install prettytable
from prettytable import PrettyTable
# Create a PrettyTable instance
table = PrettyTable()
# Define columns
table.field_names = ["Name", "Age", "City"]
# Add data rows
table.add_row(["Alice", 25, "New York"])
table.add_row(["Bob", 30, "San Francisco"])
table.add_row(["Charlie", 22, "Los Angeles"])
# Print the table
print(table)
+---------+-----+---------------+
| Name | Age | City |
+---------+-----+---------------+
| Alice | 25 | New York |
| Bob | 30 | San Francisco |
| Charlie | 22 | Los Angeles |
+---------+-----+---------------+