From 17f0a23a8534e47957dba0091fba52b73af4061e Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 21 Nov 2018 07:11:04 -0500 Subject: Center tables in example --- fpdf_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fpdf_test.go b/fpdf_test.go index 89c90b6..b3732e0 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -558,11 +558,14 @@ func ExampleFpdf_CellFormat_tables() { } // Simple table basicTable := func() { + left := (210.0 - 4*40) / 2 + pdf.SetX(left) for _, str := range header { pdf.CellFormat(40, 7, str, "1", 0, "", false, 0, "") } pdf.Ln(-1) for _, c := range countryList { + pdf.SetX(left) pdf.CellFormat(40, 6, c.nameStr, "1", 0, "", false, 0, "") pdf.CellFormat(40, 6, c.capitalStr, "1", 0, "", false, 0, "") pdf.CellFormat(40, 6, c.areaStr, "1", 0, "", false, 0, "") @@ -578,13 +581,16 @@ func ExampleFpdf_CellFormat_tables() { for _, v := range w { wSum += v } + left := (210 - wSum) / 2 // Header + pdf.SetX(left) for j, str := range header { pdf.CellFormat(w[j], 7, str, "1", 0, "C", false, 0, "") } pdf.Ln(-1) // Data for _, c := range countryList { + pdf.SetX(left) pdf.CellFormat(w[0], 6, c.nameStr, "LR", 0, "", false, 0, "") pdf.CellFormat(w[1], 6, c.capitalStr, "LR", 0, "", false, 0, "") pdf.CellFormat(w[2], 6, strDelimit(c.areaStr, ",", 3), @@ -593,6 +599,7 @@ func ExampleFpdf_CellFormat_tables() { "LR", 0, "R", false, 0, "") pdf.Ln(-1) } + pdf.SetX(left) pdf.CellFormat(wSum, 0, "", "T", 0, "", false, 0, "") } // Colored table @@ -609,6 +616,8 @@ func ExampleFpdf_CellFormat_tables() { for _, v := range w { wSum += v } + left := (210 - wSum) / 2 + pdf.SetX(left) for j, str := range header { pdf.CellFormat(w[j], 7, str, "1", 0, "C", true, 0, "") } @@ -620,6 +629,7 @@ func ExampleFpdf_CellFormat_tables() { // Data fill := false for _, c := range countryList { + pdf.SetX(left) pdf.CellFormat(w[0], 6, c.nameStr, "LR", 0, "", fill, 0, "") pdf.CellFormat(w[1], 6, c.capitalStr, "LR", 0, "", fill, 0, "") pdf.CellFormat(w[2], 6, strDelimit(c.areaStr, ",", 3), @@ -629,6 +639,7 @@ func ExampleFpdf_CellFormat_tables() { pdf.Ln(-1) fill = !fill } + pdf.SetX(left) pdf.CellFormat(wSum, 0, "", "T", 0, "", false, 0, "") } loadData(example.TextFile("countries.txt")) -- cgit v1.2.1-24-ge1ad