How to center align table – PDFMAKE

Total
2
Shares

Can i create one table with center alignment (page) using PDFMAKE?

Already defined alignment: “center” in Styles and inside the tag table: {}

{
              table: {
                width: "auto",
                body: [
                  [
                    { text: "PERÍODO", style: "tableHeader" },
                    { text: "VOLUME (MW médios)", style: "tableHeader" }
                  ],
                  ["{7} a {8}", "{9}"],
                  ["{10} a {11}", "{12}"],
                  ["{13} a {14}", "{15}"]
                ],
                alignment: "center"
              }
            }

I expect one table align in the center of the page.


Solution

alignment:"center" only aligns the content of the columns in center. You can try as following:

{
    columns: [
        { width: '*', text: '' },
        {
            width: 'auto',
                table: {
                body: [
                  [
                    { text: "PERÍODO", style: "tableHeader" },
                    { text: "VOLUME (MW médios)", style: "tableHeader" }
                  ],
                  ["{7} a {8}", "{9}"],
                  ["{10} a {11}", "{12}"],
                  ["{13} a {14}", "{15}"]
                ],
                alignment: "center"
                }
        },
        { width: '*', text: '' },
    ]
}
Leave a Reply

Your email address will not be published. Required fields are marked *