diff --git a/admin-lehrer/components/grid-editor/GridTable.tsx b/admin-lehrer/components/grid-editor/GridTable.tsx index e76c979..a5dfe82 100644 --- a/admin-lehrer/components/grid-editor/GridTable.tsx +++ b/admin-lehrer/components/grid-editor/GridTable.tsx @@ -52,13 +52,18 @@ export function GridTable({ // ---------------------------------------------------------------- // Compute column widths from OCR measurements // ---------------------------------------------------------------- - const zoneWidthPx = zone.bbox_px.w || layoutMetrics?.page_width_px || 1 - const scale = containerWidth > 0 ? (containerWidth - ROW_NUM_WIDTH) / zoneWidthPx : 1 - - // Column widths in original pixels, then scaled to container + // Use the actual total column span as reference width — NOT zone.bbox_px.w. + // When union columns are applied across content zones, column boundaries + // can extend beyond the zone's bbox, causing overflow if we scale by + // the smaller zone width. const [colWidthOverrides, setColWidthOverrides] = useState(null) const columnWidthsPx = zone.columns.map((col) => col.x_max_px - col.x_min_px) + const totalColWidthPx = columnWidthsPx.reduce((sum, w) => sum + w, 0) + const zoneWidthPx = totalColWidthPx > 0 + ? totalColWidthPx + : (zone.bbox_px.w || layoutMetrics?.page_width_px || 1) + const scale = containerWidth > 0 ? (containerWidth - ROW_NUM_WIDTH) / zoneWidthPx : 1 const effectiveColWidths = (colWidthOverrides ?? columnWidthsPx).map( (w) => Math.max(MIN_COL_WIDTH, w * scale),