  Results are presented from the measurement by ATLAS of long-range
($|\Delta\eta|>2$)dihadron angular correlations in $\sqrt{s}=8$ and 13 TeV $pp$
collisions containing a $Z$ boson. The analysis is performed using 19.4
$\mathrm{fb}^{-1}$ of $\sqrt{s}=8$ TeV data recorded during Run 1 of the LHC
and 36.1 $\mathrm{fb}^{-1}$ of $\sqrt{s}=13$ TeV data recorded during Run 2.
Two-particle correlation functions are measured as a function of relative
azimuthal angle over the relative pseudorapidity range $2<|\Delta\eta|<5$ for
different intervals of charged-particle multiplicity and transverse momentum.
The measurements are corrected for the presence of background charged particles
generated by collisions that occur during one passage of two colliding proton
bunches in the LHC. Contributions to the two-particle correlation functions
from hard processes are removed using a template-fitting procedure. Sinusoidal
modulation in the correlation functions is observed and quantified by the
second Fourier coefficient of the correlation function, $v_{2,2}$, which in
turn is used to obtain the single-particle anisotropy coefficient $v_{2}$. The
$v_{2}$ values in the $Z$-tagged events, integrated over $0.5<p_{\mathrm{T}}<5$
GeV, are found to be independent of multiplicity and $\sqrt{s}$, and consistent
within uncertainties with previous measurements in inclusive $pp$ collisions.
As a function of charged-particle $p_{\mathrm{T}}$, the $Z$-tagged and
inclusive $v_{2}$ values are consistent within uncertainties for
$p_{\mathrm{T}}<3$ GeV.
