Growing evidence supports the importance of understanding tumor-immune spatial relationship in the tumor microenvironment in order to achieve precision cancer therapy.However, existing methods, based on oversimplistic cell-to-cell proximity, are largely confounded by immune cell density and are ineffective in capturing tumor-immune spatial patterns. Here we developed a novel computational algorithm, termed Tumor-Immune Partitioning and Clustering (TIPC), to offer an effective solution for spatially informed tumor subtyping. Our method could measure the extent of immune cell partitioning between tumor epithelial and stromal areas as well as the degree of immune cell clustering. Using a U.S. nation-wide colorectal cancer database, we showed that TIPC could determine tumor subtypes with unique tumor-immune spatial patterns that were significantly associated with patient survival and key tumor molecular features. We also demonstrated that TIPC was robust to parameter settings and readily applicable to different immune cell types. The capability of TIPC in delineating clinically relevant patient subtypes that encapsulate tumor-immune spatial relationship, immune density, and tumor morphology is expected to shed light on underlying immune mechanisms. Hence, TIPC can be a useful bioinformatics tool for effective characterization of the spatial composition of the tumor-immune microenvironment to inform precision immunotherapy.