The entire capital gains from the sale of your residential house would be taxable in your hands. To the extent of capital gains made from sale, the entire gains should be invested to avoid tax liability ie minimum 20 lacs.
The law does not have any restriction on joint ownership and hence you can register the flat as joint owners. Than it would be advisable that instead of loan taken from relatives the amount is shown as their share of contribution towards property. The agreement to buy should clearly specify the mechanics of payments and share of funds contributed by each owner.
Where the amount is taken as loan by you and still you would like to have a joint ownership, the clubbing provision of income-tax law would apply. There is clubbing provision in Income-tax law, which provides that in case of income from a property in future where the entire funds are met by you, such income would be taxed in your hands ie any rental income or capital gains in future thou there are co-owners.
IN case of funds taken from spouse, if they are merely out of money given by you, then the income if any in future from the property will be taxable in your hands. However, if your spouse has independent earning, than she can have have her share in property jointly. Similarly, if your kids are earning, then the proportion of contribution made by them can be their share in property.