LONDON — Queen Elizabeth II welcomed President Trump to Buckingham Palace on Monday with an honor guard and royal artillery salute, while Mr. Trump carried on an ugly dispute with the mayor of London, whom he called a “stone cold loser” and said was doing a terrible job of running Britain’s capital city.

The juxtaposition of high pageantry and low name-calling, on the first day of Mr. Trump’s state visit to Britain, captured yet again the odd swath that this president cuts on the world stage: impulsive and erratic, delighted by a lavish welcome but preoccupied by petty feuds or events back home.

It also showcased the deep ambivalence Mr. Trump’s visit has elicited. The British public mostly rejects Mr. Trump and his policies, but the governing elite recognizes the need to reinforce the alliance with the United States as it negotiates Britain’s exit from the European Union.