Capillary phase transitions of linear (from C(1) to C(12)) and branched (C(5) isomers) alkanes in single-walled carbon nanotubes have been investigated using the gauge-cell Monte Carlo simulation. The isotherm at a supercritical temperature increases monotonically with chemical potential and coincides with that from the traditional grand canonical Monte Carlo simulation, whereas the isotherm at a subcritical temperature exhibits a sigmoid van der Waals loop including stable, metastable, and unstable regions. Along this loop, the coexisting phases are determined using an Maxwell equal-area construction. A generic confinement effect is found that reduces the saturation chemical potential, lowers the critical temperature, increases the critical density, and shrinks the phase envelope. The effect is greater in a smaller diameter nanotube and is greater in a nanotube than in a nanoslit.