Soy! Anytime I have tofu or soymilk, I have gas for 2 or more days and I mean bad gas pains, like after a C-section can't pass it kind of gas pains. My allergist told me it's a common problem and to try cutting back on soy, keeping a journal, etc. It was my culprit so now I try to avoid it when I can.
I have very few problems with beans, unless they're very spicy, but moreso with one of my favorite dishes, oven-roasted Brussel sprouts. I just know to take Bean-o (before you eat) or if I forget and it's noticeable, take a Gas-X afterwards. Gas-X also makes a before-meal capsule now. It's not chewable like Bean-o, but it's very small and you swallow it with a drink before you eat. Works just as well for me.
Unless I eat a lot of garlic, my gas problem is mostly noisy but otherwise, undetectable, lol. If I do get it, it tends to be once I lay down for the night, even if I ate many hours earlier.