Considering the density wave of scalar and pseudoscalar condensates, we study the response of quark matter to a weak external magnetic field. In an external magnetic field, the energy spectrum of the lowest Landau level becomes asymmetric about zero, which is closely related to chiral anomaly, and gives rise to the spontaneous magnetization. This mechanism may be one of candidates for the origin of the strong magnetic field in pulsars and/or magnetars.