No, you can't offset capital gains by margin interest.
Margin interest is investment interest expense. Deductible on Sch A. So you need to itemize deductions. Investment interest expense also has limitations on the amount. (limited to NET investment income)
See Publication 550
https://www.irs.gov/publications/p550/ch03.html#en_US_2016_publink100010207