Yeah that's a sticky one. I mean on one hand, even in today's military, you can't really be in a romantic relationship with someone in your direct command, but you can sorta with someone that's not really in your direct command or the same rank as yourself.. I think. I mean, I've known military couples, but usually they are from different parts of the unit. Like say a nurse dating a gunnery sergeant or something.
Of course when it comes to the commanders... that's the tricky part, because on that ship, the CO, XO and 2nd Officer ARE the higher ups on the ship and are in charge of the whole bloody ship.
But Riker and Troi have worked together for many many years and even IF Starfleet did have a problem with it, their records would speak for themselves, Will has given Troi orders that would have put her in harm's way many a time and both know the risks and all. So really, I suppose the assumption that she'd get special treatment simply because she's ridin' the Captain's mast... is hardly an issue, he's shown in the past that he probably expects her to prove herself, same as any officer.
That and well... let's face it sometimes Troi could get a bit ditzy from time to time.
Now with Chuckles and Janeway, he wasn't a "Real" officer anymore, granted in their ad hoc "Starfleet through and through crew" it may not have worked, but hell if they were going to really be stuck there for the rest of their lives or most of it, I wouldn't worry about "what is starfleet going to think?! I'm sleeping with my xo..." they were more worried about "holy shit Janeway! You've got a rogue starfleet officer, a Maquis no less as your XO... are you out of your fuckin' gourd!?!?" Who cared if they slept together?
Now with Picard... he really was one sorry bastard in that he was not only a Captain, but a Captain in charge of the Fleet Flagship. So his actions would be monitored so tightly, he can't breathe. I mean if he WANTED to have a gal from Astrophysics be his bed buddy and heck even known among the crew that "she's the captain's girlfriend", then Starfleet would come down on him like a ton of bricks. With Voyager, who gave two craps... it wasn't the flagship.