coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/19388578/badge)](https://coveralls.io/builds/19388578)

Coverage increased (+0.1%) to 78.662% when pulling **978717442ecec309e869354ad98254032368ca67 on Sideboard:master** into **d3e55f597be47dbfb245768d23a0176c1b059f1e on pri22296:master**.

pri22296: Thanks for the Pull Request. Can you just squash the 2 commits into a single one? Other than that this looks good to me.
diff --git a/beautifultable/beautifultable.py b/beautifultable/beautifultable.py
index 0835eca..804e7a6 100644
--- a/beautifultable/beautifultable.py
+++ b/beautifultable/beautifultable.py
@@ -622,7 +622,8 @@ class BeautifulTable(object):
         actual_space = sum_ - temp_sum
         for i, _ in enumerate(widths):
             if not flag[i]:
-                widths[i] = int(round(widths[i] * avail_space / actual_space))
+                new_width = int(round(widths[i] * avail_space / actual_space))
+                widths[i] = min(widths[i], new_width)
         self.column_widths = widths
 
     def set_padding_widths(self, pad_width):

Incorrect calculation of column width
Minimal example:
```py
table = beautifultable.BeautifulTable(max_width=150)
table.column_headers = ['t', 'u', 'v', 'w', 'x', 'y', 'z']
table.append_row(['q123456789012345678', 'a', 'b', 'c', 'd', 'e', 'f'])
print(table)
```

Output:
```
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
|                                                             t                                                              | u | v | w | x | y | z |
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
|                                                    q123456789012345678                                                     | a | b | c | d | e | f |
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
```

The first column is too wide. If I omit the last character, it works as expected:
```py
table.append_row(['q12345678901234567', 'a', 'b', 'c', 'd', 'e', 'f'])
```
```
+--------------------+---+---+---+---+---+---+
|         t          | u | v | w | x | y | z |
+--------------------+---+---+---+---+---+---+
| q12345678901234567 | a | b | c | d | e | f |
+--------------------+---+---+---+---+---+---+
```

It also seems to work as expected if I change the `max_width`, or if I use fewer columns.

diff --git a/test.py b/test.py
index a02b6bc..edc0c45 100644
--- a/test.py
+++ b/test.py
@@ -371,6 +371,18 @@ class TableOperationsTestCase(unittest.TestCase):
         width = self.table.get_table_width()
         self.assertEqual(width, 0)
 
+    def test_table_auto_width(self):
+        row_list = ['abcdefghijklmopqrstuvwxyz', 1234, 'none']
+
+        self.create_table(200)
+        self.table.append_row(row_list)
+        len_for_max_width_200 = len(str(self.table))
+
+        self.create_table(80)
+        self.table.append_row(row_list)
+        len_for_max_width_80 = len(str(self.table))
+
+        self.assertEqual(len_for_max_width_80, len_for_max_width_200)
 
 if __name__ == '__main__':
     unittest.main()

pip install -e .
parse_log_pytest
pytest
pytest
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
-e git+https://github.com/pri22296/beautifultable.git@d3e55f597be47dbfb245768d23a0176c1b059f1e#egg=beautifultable
certifi==2021.5.30
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: beautifultable
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
prefix: /opt/conda/envs/beautifultable

test.py::TableOperationsTestCase::test_table_auto_width
test.py::TableOperationsTestCase::test_access_column_by_header test.py::TableOperationsTestCase::test_access_row_by_index test.py::TableOperationsTestCase::test_access_row_element_by_header test.py::TableOperationsTestCase::test_access_row_element_by_index test.py::TableOperationsTestCase::test_append_column test.py::TableOperationsTestCase::test_append_row test.py::TableOperationsTestCase::test_column_count test.py::TableOperationsTestCase::test_contains test.py::TableOperationsTestCase::test_delitem_int test.py::TableOperationsTestCase::test_delitem_slice test.py::TableOperationsTestCase::test_delitem_str test.py::TableOperationsTestCase::test_empty_header test.py::TableOperationsTestCase::test_empty_table_by_column test.py::TableOperationsTestCase::test_empty_table_by_row test.py::TableOperationsTestCase::test_get_column_header test.py::TableOperationsTestCase::test_get_column_index test.py::TableOperationsTestCase::test_get_string test.py::TableOperationsTestCase::test_getitem_slice test.py::TableOperationsTestCase::test_insert_column test.py::TableOperationsTestCase::test_insert_row test.py::TableOperationsTestCase::test_left_align test.py::TableOperationsTestCase::test_mixed_align test.py::TableOperationsTestCase::test_pop_column_by_header test.py::TableOperationsTestCase::test_pop_column_by_position test.py::TableOperationsTestCase::test_pop_row test.py::TableOperationsTestCase::test_right_align test.py::TableOperationsTestCase::test_row_count test.py::TableOperationsTestCase::test_serialno test.py::TableOperationsTestCase::test_setitem_int test.py::TableOperationsTestCase::test_setitem_slice test.py::TableOperationsTestCase::test_setitem_str test.py::TableOperationsTestCase::test_signmode_plus test.py::TableOperationsTestCase::test_table_width_zero test.py::TableOperationsTestCase::test_update_column test.py::TableOperationsTestCase::test_update_row test.py::TableOperationsTestCase::test_update_row_slice test.py::TableOperationsTestCase::test_wep_ellipsis test.py::TableOperationsTestCase::test_wep_strip test.py::TableOperationsTestCase::test_wep_wrap
beautifultable/beautifultable.py
beautifultable/beautifultable.py