Question

I have created a table in xsl-fo like this:

<fo:block margin-top="0.4cm">
                        <fo:table border-collapse="collapse">
                            <fo:table-column column-width="15%"
                                column-number="1" />
                            <fo:table-column column-width="16%"
                                column-number="2" />
                            <fo:table-column column-width="53%"
                                column-number="3" />
                            <fo:table-column column-width="16%"
                                column-number="4" />

                            <fo:table-header>
                                <fo:table-row>
                                    <fo:table-cell padding="2px" font-size="7px">
                                        <fo:block text-align="center" font-weight="bold">Column1
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="2px" font-size="7px">
                                        <fo:block text-align="center" font-weight="bold">Column2
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="2px" font-size="7px">
                                        <fo:block text-align="left" font-weight="bold">Column3
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding="2px" font-size="7px">
                                        <fo:block text-align="center" font-weight="bold">Column4
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </fo:table-header>

                            <fo:table-body font-size="9px">


                                    <fo:table-row>
                                        <fo:table-cell padding="2px" border="0.5pt solid #cfcfcf">
                                            <fo:block text-align="center">
                                                12345678910111213
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell padding="2px" border="0.5pt solid #cfcfcf">
                                            <fo:block text-align="center">
                                                some text
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell padding="2px" border="0.5pt solid #cfcfcf">
                                            <fo:block text-align="left">
                                                some text
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell padding="2px" border="0.5pt solid #cfcfcf">
                                            <fo:block text-align="right">
                                                some text
                                            </fo:block>
                                        </fo:table-cell>
                                    </fo:table-row>

                                </xsl:for-each>
                            </fo:table-body>
                        </fo:table>
                    </fo:block>
                    <fo:block padding-top="40px">
                    some text
                    </fo:block>
                </fo:block>

The String "12345678910111213" in Column1 is written over the borders of its table-cell.

How can I force a line break in the table-cells of this column after a specific number of characters in the String?

Was it helpful?

Solution

By injecting a zero-width space &#x200b; at the desired location.

This technique is very useful for indicating multiple possible break locations for a contiguous string, even if the room is big enough to accommodate the entire string, because the zero-width spaces are invisible. If, however, a break is needed, the rendering knows to break the string at a space, and a zero-width space is treated as a space.

In the classroom I use the example of a URI string, where adding a zero-width space after every / will render as a regular URI (without visible spaces) and yet will break at the desired points if necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top