diff --git includes/theme.inc includes/theme.inc
index f6b45f4..6a1502c 100644
--- includes/theme.inc
+++ includes/theme.inc
@@ -1663,6 +1663,11 @@ function theme_table($variables) {
     }
   }
 
+  // Add the 'empty' row message if available.
+  if (!count($rows) && $empty) {
+    $rows[] = array(array('data' => $empty, 'colspan' => count($header), 'class' => array('empty', 'message')));
+  }
+
   // Format the table header:
   if (count($header)) {
     $ts = tablesort_init($header);
@@ -1680,11 +1685,6 @@ function theme_table($variables) {
     $ts = array();
   }
 
-  // Add the 'empty' row message if available.
-  if (!count($rows) && $empty) {
-    $rows[] = array(array('data' => $empty, 'colspan' => count($header), 'class' => array('empty', 'message')));
-  }
-
   // Format the table rows:
   if (count($rows)) {
     $output .= "<tbody>\n";
diff --git modules/simpletest/tests/theme.test modules/simpletest/tests/theme.test
index ff7610d..6dc5734 100644
--- modules/simpletest/tests/theme.test
+++ modules/simpletest/tests/theme.test
@@ -95,6 +95,17 @@ class ThemeTableUnitTest extends DrupalWebTestCase {
     $this->assertNoRaw('sticky-enabled',  t('Table does not have a class of sticky-enabled because $sticky = FALSE.'));
     drupal_static_reset('drupal_add_js');
   }
+
+  /**
+   * Tests that the table header is printed even if there are no rows. And that
+   * the empty text is displayed correctly.
+   */
+  function testThemeTableWithEmptyMessage() {
+    $header = array(t('Header 1'), t('Header 2'));
+    $this->content = theme('table', array('header' => $header, 'rows' => array(), 'empty' => t('No strings available.')));
+    $this->assertRaw('<tr class="odd"><td colspan="2" class="empty message">No strings available.</td>', t('Correct colspan was set on empty message.'));
+    $this->assertRaw('<thead><tr><th>Header 1</th>', t('Table header was printed.'));
+  }
 }
 
 /**
