All cases are tested without Tidy enabled.
Wikitext 1 -- Looks good.
<div style="margin-left: 40%;"> <h1>Welcome!</h1> <table style="border: 0; width: 100%;"><tr> <td><ul><li>[[XX]]<li>[[XX]]<li>[[XX]]</ul></td> <td><ul><li>[[XX]]<li>[[XX]]<li>[[XX]]</ul></td> <td><ul><li>[[XX]]<li>[[XX]]<li>[[XX]]</ul></td> <td><ul><li>[[XX]]<li>[[XX]]<li>[[XX]]</ul></td> </tr></table> </div>
Wikitext 2 -- </div> will be escaped and <div> will be unclosed.
<div style="margin-left: 40%;"> <h1>Welcome!</h1> <table style="border: 0; width: 100%;"><tr> <td><ul><li>[[XX]]<li>[[XX]]<li>[[XX]]</ul> <td><ul><li>[[XX]]<li>[[XX]]<li>[[XX]]</ul> <td><ul><li>[[XX]]<li>[[XX]]<li>[[XX]]</ul> <td><ul><li>[[XX]]<li>[[XX]]<li>[[XX]]</ul> </table> </div>
</tr> and </td> are not compulsory here, in HTML (not XHTML).