diff -urp --strip-trailing-cr ../drupal-6.x-dev/misc/tableheader.js ./misc/tableheader.js
--- ../drupal-6.x-dev/misc/tableheader.js	2007-10-02 09:09:51.000000000 +0200
+++ ./misc/tableheader.js	2007-12-15 06:17:51.000000000 +0100
@@ -34,26 +34,38 @@ Drupal.behaviors.tableHeader = function 
         'marginLeft': '-'+ $(this).css('paddingLeft'),
         'marginRight': '-'+ $(this).css('paddingRight'),
         'paddingLeft': $(this).css('paddingLeft'),
+        'paddingRight': $(this).css('paddingRight'),
         'paddingTop': $(this).css('paddingTop'),
         'paddingBottom': $(this).css('paddingBottom'),
         'z-index': ++z
       })[0];
       cells.push(div);
 
-      // Adjust width to fit cell/table.
-      var ref = this;
+      // Adjust width/height to fit cell/table.
+      var paddingH = parseInt($(div).css('paddingLeft')) + parseInt($(div).css('paddingRight'));
+      var paddingV = parseInt($(div).css('paddingTop')) + parseInt($(div).css('paddingBottom'));
+      var cellWidth = $(this).width() - paddingH;
       if (!i++) {
-        // The first cell is as wide as the table to prevent gaps.
-        ref = table;
+
+        // The first cell is as wide as the table to prevent gaps, minus half the cell size
+        // to avoid overflows in case of tricky margins/paddings. Its content gets another
+        // floated wrapper to ensure correct position regardless alignment.
+        $(div).wrapInner('<div style="float: left; margin: 0; padding: 0;"></div>');
+        $(div).children().width(Math.max(0, cellWidth));
+        cellWidth = $(table).width() - (cellWidth / 2);
         div.wide = true;
+
       }
-      $(div).width(Math.max(0, $(ref).width() - parseInt($(div).css('paddingLeft'))));
+      $(div).width(Math.max(0, cellWidth));
+      $(div).height(Math.max(0, $(this).height() - paddingV));
 
       // Get position and store.
       div.cell = this;
       div.table = table;
       div.stickyMax = height;
       div.stickyPosition = $(this).offset().top;
+      div.paddingH = paddingH;
+      div.paddingV = paddingV;
     });
     $(this).addClass('tableHeader-processed');
   });
@@ -95,12 +107,14 @@ Drupal.behaviors.tableHeader = function 
         this.stickyMax = this.table.savedHeight;
 
         // Reflow the cell.
-        var ref = this.cell;
+        var cellWidth = $(this.cell).width() - this.paddingH;
         if (this.wide) {
-          // Resize the first cell to fit the table.
-          ref = this.table;
+          // Resize the first cell to fit the table, avoiding overflows.
+          $(this).children().width(Math.max(0, cellWidth));
+          cellWidth = $(this.table).width() - (cellWidth / 2);
         }
-        $(this).width(Math.max(0, $(ref).width() - parseInt($(this).css('paddingLeft'))));
+        $(this).width(Math.max(0, cellWidth));
+        $(this).height(Math.max(0, $(this.cell).height() - this.paddingV));
       });
 
       // Reset timer
