Layered ternary T-Al-C ceramics containing early transition metal Sc, Zr, and Hf, crystallize with the TnAl3Cn+2 formula, while others containing neighbor elements Ti, V, Cr, Nb, Mo, W, and Ta yield the Tn+1AlCn formula. Ternary TnAl3Cn+2 ceramics are structurally characterized by NaCl-type TC slabs being separated by Al4C3-type AlC layers. In the present study, we suggest that the ability of forming the TnAl3Cn+2 carbide could be traced back to the structure mismatches between the TC, Al4C3 and TnAl3Cn+2 compounds. Ternary carbides following the TnAl3Cn+2 formula experience small lattice mismatches and strain energies. Moreover, the discrepancy between crystal structures of TnAl3Cn+2 and Tn+1AlCn is interpreted by lattice mismatch and the produced strain energy for the ternary T-Al-C ceramics. We also present close relationships between the atomic radii of transition metal and lattice mismatch, as well as the strain energy. The proposed method is not only helpful to explain the trend in crystal structure of T-Al-C based ceramics, but may be also general to predict the crystal structure of layered compounds constructed by alternatively stacked structural units.