${NaHCO}_3$ makes the stomach alkaline and triggers the production of more acid. ${Mg}({OH})_2$ and ${Al}({OH})_3$ being insoluble, are better than ${NaHCO}_3$ and do not increase the ${pH}$.
However, These treatments control only symptoms and not the cause. Cimetidine and ranitidine prevent the interaction of histamine with the receptors present in the stomach wall. This results in the release of lesser amount of acid.