We develop a theory of the anisotropic magnetoresistance (AMR) effects of arbitrary directions of current and magnetization for ferromagnets. Here, we use the electron scattering theory with the $s$--$s$ and $s$--$d$ scattering processes, where $s$ is the conduction electron state and $d$ is the localized d states. The resistivity due to electron scattering is expressed by the probability density of the d states of the current direction. The d states are numerically obtained by applying the exact diagonalization method to the Hamiltonian of the d states with the exchange field, crystal field, and spin--orbit interaction. Using the theory, we investigate the transverse AMR (TAMR) effect for strong ferromagnets with a crystal field of cubic or tetragonal symmetry. The cubic systems exhibit the fourfold symmetric TAMR effect, whereas the tetragonal systems show the twofold and fourfold symmetric TAMR effect. On the basis of the above results, we also comment on the experimental results of the TAMR effect for Fe$_4$N.