Possible coexistence of superconductivity and magnetism in layered compounds