If someone continues to feel lonely even in the presence of others, it is likely that the loneliness is a symptom of something greater than companionship. Call it and existential loneliness, but the point being that it is the psyches way of letting you know that something needs your attention.
Most people logically try to counter these feelings by keeping busy and spending more time with others. I think this is exactly why the feeling can continue. It needs you to stop, and listen. Really surrender to the feeling. Lean into it, and see what it really feels like in your body to be you and be lonely. Once you stop trying to "fix" it, you will often find that by just relaxing into it and giving it it's honor, you will have more clarity about what is really going on.
Just like our bodies feel pain, so that we know something is hurting, our emotional bodies do the same. It is so hard to sit with these feelings, but we have erroneously led ourselves to believe that we are supposed to avoid pain at all costs. Ironically, it is this pain that leads to joy, when it is given it's fair voice. Otherwise we delay and/or continue the pain.
As simplistic as I make it sound, I know that it is difficult and by no means trivial.