Magnesium, potassium headaches with supplements

Patient: I have cirrhosis and have had it now for 25+ years. I was just checked out and given a clean bill of health. I do though deal with its problems. I deal with heart palpitations. I was told this occurs in many cirrhosis patients because of a low magnesium. In the past I’ve dealt with various issues like low vitamin D etc. I bought magnesium 250mg, I also bought Folic Acid, which I used quite often in the hospital years back. I also got potassium 595mg. Problem is once I started the headaches started. I’ve read everywhere on magnesium and headaches. If I’ve fount anything it talks about how it cures headaches not causes them. Is it because I took these supplements all at once? Is it because its magnesium oxide pills? Is it a combo? I reintroduced Folic Acid, no issues. I have since went to magnesium via diet spinach, nuts, cereals etc. Seems to be helping as my heart palpitations have drastically reduced. Only problem is that can be a very costly diet, not that I’m not willing to make it part of my regiment. Is there a magnesium supplement I can take that won’t have that effect? Is it the magnesium at all or another supplement I listed? I’ve tried a half dose no help still headaches. Thanks

Symptoms: Headaches. Cirrhosis, heart palpitations?