(defun align (lines &key (stream t) (fs " |") (rs #\Newline) (underline #\-) (before #\Newline) (after "")) (let* ((header (first lines)) (data (rest lines)) (cols (transpose lines)) (widths (mapcar #'longest-string cols)) (sep "") (fmt (with-output-to-string (s) (dolist (width widths) (format s "~a~~~a<~a~~>" sep (1+ width) "~a") (setf sep fs)) (format s "~a" rs)))) (format stream "~a" before) (apply #'format `(,stream ,fmt ,@header)) (setf sep "") (dolist (w widths) (format stream "~a ~a" sep (nchars w underline)) (setf sep fs)) (format stream "~a" rs) (dolist (line data) (apply #'format `(,stream ,fmt ,@line))) (format stream "~a" after))) (deftest test-align () (let ((tmp (with-output-to-string (s) (align '((peace love understanding) (34.1 33.4 324.2) (334 222222 33)) :stream s)))) (samep tmp " PEACE | LOVE | UNDERSTANDING ----- | ------ | ------------- 34.1 | 33.4 | 324.2 334 | 222222 | 33 ")))