@@ -229,8 +229,7 @@ gridTable opts blocksToDoc headless aligns widths headers rows = do
229229 -- handleGivenWidths wraps the given blocks in order for them to fit
230230 -- in cells with given widths. the returned content can be
231231 -- concatenated with borders and frames
232− let handleGivenWidths widths' = do
233− let widthsInChars' = officialWidthsInChars widths'
232+ let handleGivenWidthsInChars widthsInChars' = do
234233 -- replace page width (in columns) in the options with a
235234 -- given width if smaller (adjusting by two)
236235 let useWidth w = opts{writerColumns = min (w - 2) (writerColumns opts)}
@@ -241,6 +240,8 @@ gridTable opts blocksToDoc headless aligns widths headers rows = do
241240 (\cs -> zipWithM blocksToDoc columnOptions cs)
242241 rows
243242 return (widthsInChars', rawHeaders', rawRows')
243+ let handleGivenWidths widths' = handleGivenWidthsInChars
244+ (officialWidthsInChars widths')
244245 -- handleFullWidths tries to wrap cells to the page width or even
245246 -- more in cases where `--wrap=none`. thus the content here is left
246247 -- as wide as possible
@@ -262,9 +263,22 @@ gridTable opts blocksToDoc headless aligns widths headers rows = do
262263 let handleZeroWidths widths' = do
263264 (widthsInChars', rawHeaders', rawRows') <- handleFullWidths widths'
264265 if foldl' (+) 0 widthsInChars' > writerColumns opts
265− then -- use even widths
266− handleGivenWidths
267− (replicate numcols (1.0 / fromIntegral numcols) :: [Double])
266+ then do -- use even widths except for thin columns
267+ let evenCols = max 5
268+ (((writerColumns opts - 1) `div` numcols) - 3)
269+ let (numToExpand, colsToExpand) =
270+ foldr (\w (n, tot) -> if w < evenCols
271+ then (n, tot + (evenCols - w))
272+ else (n + 1, tot))
273+ (0,0) widthsInChars'
274+ let expandAllowance = colsToExpand `div` numToExpand
275+ let newWidthsInChars = map (\w -> if w < evenCols
276+ then w
277+ else min
278+ (evenCols + expandAllowance)
279+ w)
280+ widthsInChars'
281+ handleGivenWidthsInChars newWidthsInChars
268282 else return (widthsInChars', rawHeaders', rawRows')
269283 -- render the contents of header and row cells differently depending
270284 -- on command line options, widths given in this specific table, and