Itext7 - 嵌套 Table 未在单元格内对齐

Itext7 - Nested Table not aligning within Cell

我正在尝试创建一个带有嵌套 table 的 table,该 table 与其单元格的右边缘对齐,但尽管将 HorizontalAlignment 添加到包含 Cell.

Table billingTable = new Table(2).useAllAvailableWidth();
Cell billedPartyCell = new Cell().setBorder(Border.NO_BORDER).setWidth(UnitValue.createPercentValue(50));
Cell billingInfoCell = new Cell().setBorder(Border.NO_BORDER).setWidth(UnitValue.createPercentValue(50))
        .setHorizontalAlignment(HorizontalAlignment.RIGHT); // <- not having any effect

// invoice table is the smaller (darker grey) table inside billingCell
Table invoiceTable = new Table(2).setBorder(Border.NO_BORDER).setBackgroundColor(COLOR_MID_GREY);

// redacted for brevity

billingInfoCell.setBackgroundColor(COLOR_LT_GREY);
billingInfoCell.add(invoiceTable);

billingTable.setMarginTop(SPACING_MARGIN);
billingTable.addCell(billedPartyCell).addCell(billingInfoCell);

灰色阴影显示 table 和细胞实际所在的位置:

正在生产什么:

我追求的是:

所以基本上,我想问的是我是否遗漏了一些可以将嵌套 table 正确对齐到右侧的东西。

修复非常简单 - 您应该将水平对齐 属性 应用到要添加到单元格中的子元素(在本例中,应用到 table),而不是单元格本身。

您可以使用以下行来完成:

invoiceTable.setHorizontalAlignment(HorizontalAlignment.RIGHT);