Tables

Basic tables, styled tables, tables in columns, and vertical alignment

Basic Table

A simple table with headers and data rows.

::pdf-example{pdf="/pdfs/examples/07_table_basic.pdf"}

{
    "page": {"size": "A4", "margins": "15mm"},
    "body": [
        {"row": {"cols": [
            {"span": 12, "elements": [
                {"type": "text", "content": "Basic Table", "style": {"size": 18, "bold": true}},
                {"type": "spacer", "height": "5mm"}
            ]}
        ]}},
        {"row": {"cols": [
            {"span": 12, "table": {
                "header": ["Name", "Age", "City"],
                "rows": [
                    ["Alice", "30", "Tokyo"],
                    ["Bob", "25", "New York"],
                    ["Charlie", "35", "London"],
                    ["Diana", "28", "Paris"]
                ]
            }}
        ]}}
    ]
}

::


Styled Table

Custom column widths, header styling, and alternating row colors.

::pdf-example{pdf="/pdfs/examples/08_table_styled.pdf"}

{
    "page": {"size": "A4", "margins": "15mm"},
    "body": [
        {"row": {"cols": [
            {"span": 12, "elements": [
                {"type": "text", "content": "Styled Table", "style": {"size": 18, "bold": true}},
                {"type": "spacer", "height": "5mm"}
            ]}
        ]}},
        {"row": {"cols": [
            {"span": 12, "table": {
                "header": ["Product", "Category", "Qty", "Unit Price", "Total"],
                "rows": [
                    ["Laptop Pro 15", "Electronics", "2", "$1,299.00", "$2,598.00"],
                    ["Wireless Mouse", "Accessories", "10", "$29.99", "$299.90"],
                    ["USB-C Hub", "Accessories", "5", "$49.99", "$249.95"],
                    ["Monitor 27\"", "Electronics", "3", "$399.00", "$1,197.00"],
                    ["Keyboard", "Accessories", "10", "$79.99", "$799.90"],
                    ["Webcam HD", "Electronics", "4", "$89.99", "$359.96"]
                ],
                "columnWidths": [30, 20, 10, 20, 20],
                "headerStyle": {"bold": true, "color": "white", "background": "#1A237E"},
                "stripeColor": "#F5F5F5"
            }}
        ]}}
    ]
}

::


Tables in Columns

Place multiple tables side-by-side using the grid system.

::pdf-example{pdf="/pdfs/examples/09_table_in_columns.pdf"}

{
    "page": {"size": "A4", "margins": "15mm"},
    "body": [
        {"row": {"cols": [
            {"span": 12, "elements": [
                {"type": "text", "content": "Tables in Grid Columns", "style": {"size": 18, "bold": true}},
                {"type": "spacer", "height": "5mm"}
            ]}
        ]}},
        {"row": {"cols": [
            {"span": 6, "elements": [
                {"type": "text", "content": "Team A", "style": {"bold": true}},
                {"type": "spacer", "height": "2mm"},
                {"type": "table", "table": {
                    "header": ["Player", "Score"],
                    "rows": [
                        ["Alice", "95"],
                        ["Bob", "87"],
                        ["Charlie", "92"]
                    ],
                    "columnWidths": [60, 40]
                }}
            ]},
            {"span": 6, "elements": [
                {"type": "text", "content": "Team B", "style": {"bold": true}},
                {"type": "spacer", "height": "2mm"},
                {"type": "table", "table": {
                    "header": ["Player", "Score"],
                    "rows": [
                        ["Diana", "91"],
                        ["Eve", "88"],
                        ["Frank", "85"]
                    ],
                    "columnWidths": [60, 40]
                }}
            ]}
        ]}}
    ]
}

::


Table Vertical Alignment

Control vertical alignment of cell content: top (default), middle, or bottom.

::pdf-example{pdf="/pdfs/examples/25_table_vertical_align.pdf"}

{
    "page": {"size": "A4", "margins": "20mm"},
    "body": [
        {"row": {"cols": [
            {"span": 12, "elements": [
                {"type": "text", "content": "Table Vertical Align Demo", "style": {"size": 20, "bold": true}},
                {"type": "spacer", "height": "8mm"},
                {"type": "text", "content": "Default (Top) Alignment:", "style": {"bold": true}},
                {"type": "spacer", "height": "3mm"},
                {"type": "table", "table": {
                    "header": ["Short", "Tall Cell"],
                    "rows": [
                        ["A", "This cell has\nmuch more content\nthat spans\nmultiple lines"],
                        ["B", "Another tall\ncell with\nlong text"]
                    ],
                    "headerStyle": {"bold": true, "color": "white", "background": "#1565C0"}
                }},
                {"type": "spacer", "height": "8mm"},
                {"type": "text", "content": "Middle Alignment:", "style": {"bold": true}},
                {"type": "spacer", "height": "3mm"},
                {"type": "table", "table": {
                    "header": ["Short", "Tall Cell"],
                    "rows": [
                        ["A", "This cell has\nmuch more content\nthat spans\nmultiple lines"],
                        ["B", "Another tall\ncell with\nlong text"]
                    ],
                    "headerStyle": {"bold": true, "color": "white", "background": "#2E7D32"},
                    "cellVAlign": "middle"
                }},
                {"type": "spacer", "height": "8mm"},
                {"type": "text", "content": "Bottom Alignment:", "style": {"bold": true}},
                {"type": "spacer", "height": "3mm"},
                {"type": "table", "table": {
                    "header": ["Short", "Tall Cell"],
                    "rows": [
                        ["A", "This cell has\nmuch more content\nthat spans\nmultiple lines"],
                        ["B", "Another tall\ncell with\nlong text"]
                    ],
                    "headerStyle": {"bold": true, "color": "white", "background": "#E65100"},
                    "cellVAlign": "bottom"
                }}
            ]}
        ]}}
    ]
}

::

Something unclear or missing on this page?