On the other hand, you tend to get energy -> liquid carbon fuel -> consumer, where once the fuel is liquid it's cheap to move around without much further loss, whereas with electricity you tend to get generator -> AC to DC -> transmission -> AC to DC -> lithium ion battery. Each step is individually more efficient, but the whole is not necessarily obviously worse than liquid fuels.
Electricity does have a lot more optimization opportunity, though, whereas those liquid fuel processes are pretty much at their optimum already. A local solar panel DC'ing straight into your car's batteries is going to be pretty good compared to the "generic" pipeline I gave you above. (On the other hand, it can go the other way, too; if your electricity notionally passed through something like a gravity storage step, you lost more there too.) Although from what I've gathered from looking at solar setups, most local solar setups won't actually do that, so it's an optimization yet to be done rather than something all roof-mounted solar panels already do.