Forum


Replies: 2   Views: 86
Make checkbox only take up as much space as it needs

Posted by admin  · 30-11-2024 - 10:46

Hello,

Please note that in this case the spacing is generated by the paragraph.

If each checkbox and text are added in a paragraph, you can use spacing styles to get a smaller spacing:

$docx->addText(
    [
        $checkboxFragment1,
        [
            'text' => ' alternative 1',
            'fontSize' => 10
        ],
    ],
    [
        'spacingBottom' => 0,
        'spacingTop' => 0,
    ]
);

$docx->addText(
    [
        $checkboxFragment2,
        [
            'text' => ' alternative 2',
            'fontSize' => 10
        ],
    ],
    [
        'spacingBottom' => 0,
        'spacingTop' => 0,
    ]
);

Or add line breaks in the same paragraph:

$docx->addText(
    [
        $checkboxFragment1,
        [
            'text' => ' alternative 1' . "\n",
            'fontSize' => 10,
        ],
        $checkboxFragment2,
        [
            'text' => ' alternative 2' . "\n",
            'fontSize' => 10,
        ],
    ],
    [
        'parseLineBreaks' => true,
    ]
);

Regards.