diff --git a/mercurial/templates/gitweb/helptopics.tmpl b/mercurial/templates/gitweb/helptopics.tmpl
--- a/mercurial/templates/gitweb/helptopics.tmpl
+++ b/mercurial/templates/gitweb/helptopics.tmpl
@@ -30,11 +30,16 @@ help
 <tr><td colspan="2"><h2><a name="main" href="#topics">Topics</a></h2></td></tr>
 {topics % helpentry}
 
+{if(earlycommands, '
 <tr><td colspan="2"><h2><a name="main" href="#main">Main Commands</a></h2></td></tr>
 {earlycommands % helpentry}
+')}
 
+{if(othercommands, '
 <tr><td colspan="2"><h2><a name="other" href="#other">Other Commands</a></h2></td></tr>
 {othercommands % helpentry}
+')}
+
 </table>
 
 {footer}
diff --git a/mercurial/templates/monoblue/helptopics.tmpl b/mercurial/templates/monoblue/helptopics.tmpl
--- a/mercurial/templates/monoblue/helptopics.tmpl
+++ b/mercurial/templates/monoblue/helptopics.tmpl
@@ -35,11 +35,15 @@
     <tr><td colspan="2"><h2><a name="main" href="#topics">Topics</a></h2></td></tr>
     {topics % helpentry}
 
+    {if(earlycommands, '
     <tr><td colspan="2"><h2><a name="main" href="#main">Main Commands</a></h2></td></tr>
     {earlycommands % helpentry}
+    ')}
 
+    {if(othercommands, '
     <tr><td colspan="2"><h2><a name="other" href="#other">Other Commands</a></h2></td></tr>
     {othercommands % helpentry}
+    ')}
     </table>
 
 {footer}
diff --git a/mercurial/templates/paper/helptopics.tmpl b/mercurial/templates/paper/helptopics.tmpl
--- a/mercurial/templates/paper/helptopics.tmpl
+++ b/mercurial/templates/paper/helptopics.tmpl
@@ -32,11 +32,16 @@
 <tr><td colspan="2"><h2><a name="main" href="#topics">Topics</a></h2></td></tr>
 {topics % helpentry}
 
+{if(earlycommands, '
 <tr><td colspan="2"><h2><a name="main" href="#main">Main Commands</a></h2></td></tr>
 {earlycommands % helpentry}
+')}
 
+{if(othercommands, '
 <tr><td colspan="2"><h2><a name="other" href="#other">Other Commands</a></h2></td></tr>
 {othercommands % helpentry}
+')}
+
 </table>
 </div>
 </div>
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1787,6 +1787,7 @@ Dish up an empty repo; serve it cold.
   This is the topic to test omit indicating.
   </td></tr>
   
+  
   <tr><td colspan="2"><h2><a name="main" href="#main">Main Commands</a></h2></td></tr>
   
   <tr><td>
@@ -1909,6 +1910,8 @@ Dish up an empty repo; serve it cold.
   update working directory (or switch revisions)
   </td></tr>
   
+  
+  
   <tr><td colspan="2"><h2><a name="other" href="#other">Other Commands</a></h2></td></tr>
   
   <tr><td>
@@ -2149,6 +2152,8 @@ Dish up an empty repo; serve it cold.
   </td><td>
   output version and copyright information
   </td></tr>
+  
+  
   </table>
   </div>
   </div>