diff --git a/unpacked/jax/output/CommonHTML/autoload/mtable.js b/unpacked/jax/output/CommonHTML/autoload/mtable.js
index 0b3f5fa5a..606f0866e 100644
--- a/unpacked/jax/output/CommonHTML/autoload/mtable.js
+++ b/unpacked/jax/output/CommonHTML/autoload/mtable.js
@@ -450,7 +450,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
}); box.appendChild(table);
var labels = HTML.Element("mjx-stack");
table.style.display = "inline-table"; if (!table.style.width) table.style.width = "auto";
- labels.style.verticalAlign = table.style.verticalAlign = "top";
+ labels.style.verticalAlign = "top";
node.style.verticalAlign = "";
if (shift) table.style[margin] = CHTML.Em(shift);
//
diff --git a/unpacked/jax/output/CommonHTML/jax.js b/unpacked/jax/output/CommonHTML/jax.js
index f03958425..8dcd112ca 100644
--- a/unpacked/jax/output/CommonHTML/jax.js
+++ b/unpacked/jax/output/CommonHTML/jax.js
@@ -574,9 +574,17 @@
var node = HTML.addElement(span,"mjx-chtml");
this.idPostfix = "-zoom"; jax.root.toCommonHTML(node); this.idPostfix = "";
//
+ // Adjust margins to prevent overlaps at the edges
+ //
+ var style = node.style, bbox = jax.root.CHTML;
+ if (bbox.t > bbox.h) style.marginTop = CHTML.Em(bbox.t-Math.max(bbox.h,CHTML.FONTDATA.lineH));
+ if (bbox.b > bbox.d) style.marginBottom = CHTML.Em(bbox.b-Math.max(bbox.d,CHTML.FONTDATA.lineD));
+ if (bbox.l < 0) style.paddingLeft = CHTML.Em(-bbox.l);
+ if (bbox.r > bbox.w) style.marginRight = CHTML.Em(bbox.r-bbox.w);
+ //
// Get height and width of zoomed math and original math
//
- node.style.position = "absolute";
+ style.position = "absolute";
var zW = node.offsetWidth, zH = node.offsetHeight,
mH = math.firstChild.offsetHeight, mW = math.firstChild.offsetWidth;
node.style.position = "";