Printing aligned tables in Go terminal output with uitable

uitable prints rows of values as aligned columns in the terminal. It measures each column’s widest cell, pads the rest to match, and can truncate or wrap long cells. There are no borders or box-drawing characters; if you want those, look at a heavier package such as go-pretty.
The API is small: New(), AddRow(), RightAlign(), and the MaxColWidth, Wrap and Separator fields. The latest tag is v0.0.4 (2019).
Install
Section titled “Install”Inside a Go module:
go get github.com/gosuri/uitableA basic table
Section titled “A basic table”package main
import ( "fmt"
"github.com/gosuri/uitable")
type item struct { Name string Qty int Price float64}
func main() { items := []item{ {"Keyboard", 2, 49.99}, {"Monitor", 1, 189.5}, {"USB-C cable", 10, 7.25}, }
table := uitable.New() table.Separator = " " // the default is a tab table.RightAlign(1) // QTY table.RightAlign(2) // PRICE
table.AddRow("ITEM", "QTY", "PRICE") for _, it := range items { table.AddRow(it.Name, it.Qty, fmt.Sprintf("%.2f", it.Price)) }
fmt.Println(table)}Output:
ITEM QTY PRICEKeyboard 2 49.99Monitor 1 189.50USB-C cable 10 7.25Some details:
AddRowtakes...interface{}and formats each value with%v. There is no per-column formatter, so format numbers yourself before adding them, as with the price above.RightAligntakes a zero-based column index.*TableimplementsString(), sofmt.Println(table)works.table.Bytes()gives you a[]byteif you’re writing to anio.Writer.- The default separator is a tab (
uitable.Separator = "\t"), which makes the column gaps depend on your terminal’s tab stops. SettingSeparatorto spaces gives predictable output.
Long values: truncate or wrap
Section titled “Long values: truncate or wrap”Set MaxColWidth to cap how wide any column can get. By default, longer cells are cut and end in ...:
table := uitable.New()table.MaxColWidth = 30table.AddRow("NAME", "BIO")table.AddRow("Ada Lovelace", "Mathematician and writer, known for her work on Babbage's Analytical Engine.")fmt.Println(table)Set Wrap to true to break long cells across several lines instead. The other cells in that row are padded so the columns stay aligned:
table.Wrap = trueWrapping works on word boundaries, and it is the better choice for descriptive text; truncation suits IDs and paths where the first part is enough.
When not to use it
Section titled “When not to use it”uitable only lays out text; it doesn’t sort, page, or draw borders, and it hasn’t seen a release since 2019. For simple aligned output, the standard library’s text/tabwriter does the same job with no dependency.
Further reading
Section titled “Further reading”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)