Triaxial fluxgate magnetometer is a basic instrument in the measurement of magnetic field, but the horizontal coordinate plane of such a magnetometer is not always precisely parallel to the plane of its horizontally placed base. So it leads to some measurement errors. In order to solve this problem, a method of conjugate gradient optimization is applied to find the horizontal error angles which can be used to calibrate the errors. The feasibility of the method is testified by simulation. An experiment is done to calculate the horizontal error angles of a triaxial fluxgate magnetometer. The performance of the sensor improves greatly after the horizontal error calibration.