Index: editor/dialog/fck_table.html
===================================================================
--- editor/dialog/fck_table.html	(revision 3888)
+++ editor/dialog/fck_table.html	(working copy)
@@ -155,28 +155,6 @@
 	SetAttribute( table, 'cellSpacing'	, GetE('txtCellSpacing').value ) ;
 	SetAttribute( table, 'summary'		, GetE('txtSummary').value ) ;
 
-	var eCaption = oEditor.FCKDomTools.GetFirstChild( table, 'CAPTION' ) ;
-
-	if ( document.getElementById('txtCaption').value != '')
-	{
-		if ( !eCaption )
-		{
-			eCaption = oDoc.createElement( 'CAPTION' ) ;
-			table.insertBefore( eCaption, table.firstChild ) ;
-		}
-
-		eCaption.innerHTML = document.getElementById('txtCaption').value ;
-	}
-	else if ( bExists && eCaption )
-	{
-		// TODO: It causes an IE internal error if using removeChild or
-		// table.deleteCaption() (see #505).
-		if ( oEditor.FCKBrowserInfo.IsIE )
-			eCaption.innerHTML = '' ;
-		else
-			eCaption.parentNode.removeChild( eCaption ) ;
-	}
-
 	var headers = GetE('selHeaders').value ;
 	if ( bExists )
 	{
@@ -307,6 +285,28 @@
 		oEditor.FCK.InsertElement( table ) ;
 	}
 
+	var eCaption = oEditor.FCKDomTools.GetFirstChild( table, 'CAPTION' ) ;
+
+	if ( document.getElementById('txtCaption').value != '' )
+	{
+		if ( !eCaption )
+		{
+			eCaption = oDoc.createElement( 'CAPTION' ) ;
+			table.insertBefore( eCaption, table.firstChild ) ;
+		}
+
+		eCaption.innerHTML = document.getElementById('txtCaption').value ;
+	}
+	else if ( bExists && eCaption )
+	{
+		// TODO: It causes an IE internal error if using removeChild or
+		// table.deleteCaption() (see #505).
+		if ( oEditor.FCKBrowserInfo.IsIE )
+			eCaption.innerHTML = '' ;
+		else
+			eCaption.parentNode.removeChild( eCaption ) ;
+	}
+
 	return true ;
 }
 
Index: _whatsnew.html
===================================================================
--- _whatsnew.html	(revision 3888)
+++ _whatsnew.html	(working copy)
@@ -75,6 +75,8 @@
 			custom connector tried to use the "url" attribute for files it was always reencoded.</li>
 		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1537">#1537</a>] Fixed extra
 			&lt;p&gt; tag added before pasted contents from Paste From Word dialog.</li>
+		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/2874">#2874</a>] Fixed wrong position
+			of caption tag in tables with table headers.</li>
 	</ul>
 	<p>
 		<a href="_whatsnew_history.html">See previous versions history</a></p>

