  Stars form inside molecular cloud filaments from the competition of
gravitational forces with turbulence and magnetic fields. The exact orientation
of these filaments with the magnetic fields depends on the strength of these
fields, the gravitational potential, and the line-of-sight (LOS) relative to
the mean field. To disentangle these effects we employ three-dimensional
magnetohydrodynamical numerical simulations that explore a wide range of
initial turbulent and magnetic states, i.e., sub-Alfv\'enic to super-Alfv\'enic
turbulence, with and without gravity. We use histogram of relative orientation
(HRO) and the associated projected Rayleigh statistics (PRS) to study the
orientation of density and, in order to compare with observations, the
integrated density relative to the magnetic field. We find that in
sub-Alfv\'enic systems the initial coherence of the magnetic is maintained
inside the cloud and filaments form perpendicular to the field. This trend is
not observed in super-Alfv\'enic models, where the lines are dragged by gravity
and turbulence and filaments are mainly aligned to the field. The PRS analysis
of integrated maps shows that LOS effects are important only for sub-Alfv\'enic
clouds. When the LOS is perpendicular to the initial field orientation most of
the filaments are perpendicular to the projected magnetic field. The inclusion
of gravity increases the number of dense structures perpendicular to the
magnetic field, reflected as lower values of the PRS for denser regions,
regardless of whether the model is sub- or super-Alfv\'enic. The comparison of
our results with observed molecular clouds reveal that most are compatible with
sub-Alfv\'enic models.
