diff --git a/doc/src/sgml/errcodes.sgml b/doc/src/sgml/errcodes.sgml
index 16cb6c7..2388daf 100644
--- a/doc/src/sgml/errcodes.sgml
+++ b/doc/src/sgml/errcodes.sgml
@@ -53,24 +53,8 @@
 <table id="errcodes-table">
  <title><productname>PostgreSQL</productname> Error Codes</title>
 
- <tgroup cols="2">
-  <colspec colnum="1" colname="errorcode">
-  <colspec colnum="2" colname="condname">
-  <spanspec namest="errorcode" nameend="condname" spanname="span12">
+  &errcodes-table;
 
-  <thead>
-   <row>
-    <entry>Error Code</entry>
-    <entry>Condition Name</entry>
-   </row>
-  </thead>
-
-  <tbody>
-
-    &errcodes-table;
-
-  </tbody>
- </tgroup>
 </table>
 
 
diff --git a/doc/src/sgml/generate-errcodes-table.pl b/doc/src/sgml/generate-errcodes-table.pl
index b9c14d3..91cda36 100644
--- a/doc/src/sgml/generate-errcodes-table.pl
+++ b/doc/src/sgml/generate-errcodes-table.pl
@@ -6,11 +6,51 @@
 use warnings;
 use strict;
 
+sub start_tgroup($) {
+	my $sname = shift;
+
+	print <<'EOF';
+
+
+ <tgroup cols="2">
+  <colspec colnum="1" colname="errorcode">
+  <colspec colnum="2" colname="condname">
+  <spanspec namest="errorcode" nameend="condname" spanname="span12">
+
+  <thead>
+    <row>
+      <entry spanname="span12">
+EOF
+
+	print "        $sname</entry>\n";
+
+	print <<'EOF';
+   </row>
+   <row>
+    <entry><phrase role="errcodes_errorcode">Error Code</phrase></entry>
+    <entry><phrase role="errcodes_condname">Condition Name</phrase></entry>
+   </row>
+  </thead>
+
+  <tbody>
+EOF
+}
+
+sub stop_tgroup() {
+
+	print <<'EOF';
+  </tbody>
+ </tgroup>
+EOF
+
+}
+
 print
   "<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n";
 
 open my $errcodes, $ARGV[0] or die;
 
+my $in_sect = 0;
 while (<$errcodes>)
 {
 	chomp;
@@ -32,11 +72,12 @@ while (<$errcodes>)
 		# Wrap PostgreSQL in <productname/>
 		s/PostgreSQL/<productname>PostgreSQL<\/>/g;
 
-		print "\n\n";
-		print "<row>\n";
-		print "<entry spanname=\"span12\">";
-		print "<emphasis role=\"bold\">$_</></entry>\n";
-		print "</row>\n";
+		if ($in_sect)
+		{
+			stop_tgroup;
+		}
+		start_tgroup($_);
+		$in_sect = 1;
 
 		next;
 	}
@@ -56,4 +97,6 @@ while (<$errcodes>)
 	print "</row>\n";
 }
 
+stop_tgroup();
+
 close $errcodes;
diff --git a/doc/src/sgml/stylesheet.css b/doc/src/sgml/stylesheet.css
index 0fd0f01..4ad67fe 100644
--- a/doc/src/sgml/stylesheet.css
+++ b/doc/src/sgml/stylesheet.css
@@ -94,3 +94,7 @@ PRE.LITERALLAYOUT, .SCREEN, .SYNOPSIS, .PROGRAMLISTING {
 VAR		{ font-family: monospace; font-style: italic; }
 /* Konqueror's standard style for ACRONYM is italic. */
 ACRONYM		{ font-style: inherit; }
+
+/* tgroup-ed table of error codes */
+th.errcodes_errorcode { width:  7em; }
+th.errcodes_condname  { width: 50em; }
diff --git a/doc/src/sgml/stylesheet.dsl b/doc/src/sgml/stylesheet.dsl
index 29e885d..1c4a2e6 100644
--- a/doc/src/sgml/stylesheet.dsl
+++ b/doc/src/sgml/stylesheet.dsl
@@ -199,6 +199,7 @@
 (define use-output-dir          #t)
 (define %output-dir%            "html")
 (define html-index-filename     "../HTML.index")
+(define %phrase-propagates-style% #t)
 
 
 ;; Only build HTML.index or the actual HTML output, not both.  Saves a

