Secretary of State Alexander Haig was in a fine moods at a White House state dinner last night, mulling Middle East peace and joking that Ronald Reagan and Jimmy Carter spent their time together yesterday talking about one of Haig's favorite subjects.

" Reagan wanted to know whether I'd behaved on my trip," Haig said, referring to his recent travels to Egypt.

Had he?

"No," Haig replied. "It's impossible."

In fact, at the dinner for King Juan Carlos and Queen Sofia of Spain, Reagan wouldn't say specifically what he and Carter had talked about. "We just discussed the whole thing on foreign policy," he said, "but we agreed not to be quoted. It was very warm and very friendly."

Not everyone reacted to Carter that way. "Boy, it was a ghost of Christmas past," said one White House official. "When he walked out of that West Wing . . ."

So went the evening's social-political talk, chatter that evaporates into the events of the next day. But the official toasts were for history, and sounded like it.

"In a world that seems to be drowning under a wave of authoritarianism," the president said in his after-dinner toast, "Spain shines as a beacon of hope."

The rhetoric was lofty, but it grew out of a working meeting the two leaders had earlier in the day. Juan Carlos, a strong voice for what Reagan called "a masterpiece of democracy," had told the president he hopes to proceed quickly into NATO and the European Common Market. He also said he has close relations with Jordan and Saudi Arabia, a situation one administration official suggested was positive for Middle East peace.

"I don't know what we can do," Juan Carlos told a reporter after dinner. "All friendly countries have to help each other."

On the subject of American arms in the Middle East, Haig said, "we have to do what we must -- invest in peace by staying strong. You know, that's a good quote. I used that in World War II."

The evening began in a fall chill. People poked their faces through the iron fence surrounding the White House, wondering what king was coming to feast. Photographers piled onto platforms outside the South Portico, shutter fingers poised. The red carpet was literally rolled out.

Where was the king?

Ten minutes late. At 7:05 p.m., his limousine slid silently up the driveway. The military guards raised bayonets along his path. He emerged, took the first lady's hand, then kissed it with a subtlety learned by great practice. Nancy Reagan wore a black and gold Adolfo dress with puffy, complicated sleeves. Queen Sofia had on a powder-blue and silver dress that sparkled in the flashbulbs. When they turned toward the White House, Nancy Reagan put her arm gently around the queen's waist.

Meanwhile, back on the other side of the White House, things were warming up. Guests began arriving at the Diplomatic Entrance, the one you can barely make out if you peer from the sidewalk just outside the South Lawn. As a harpist played, golfer Lee Trevino, author Allen Drury, actress Cyd Charisse and editor Malcolm Forbes floated through.

Forbes, editor of the business magazine of the same name, offered this assessment of Reagan's economic situation: "So far, he's ahead, but he's got a few things he's got to work on. He's by no means out of the woods." Then Forbes, perhaps remembering the manners of a good guest, quickly added, "Or far into trouble, either."

Guests from the White House were the lions of the current jungle. In fact, the big three -- Edwin Meese, James Baker and Michael Deaver -- arrived almost en masse.

Meese was first. "What did the president and Jimmy Carter talk about today?" a reporter yelled.

"Oh, they talked about Carter's trip to Egypt," said Meese, also mentioning that AWACS was an issue.

Anything else?

"That's about enough," Meese replied.

Then along came Deaver.

"What did the president and Jimmy Carter talk about?"

"Ha, ha, ha, ha, ha, ha, ha," Deaver said.

And finally, Baker. Same question; no answer. He just winked.

Bringing up the rear was Sen. Howard Baker (R-Tenn.). Asked about Carter's recent support for AWACS, Baker replied: "We need support on the Democratic side. I think it should make a significant difference."

Other guests included designer Adolfo, CIA director William Casey, New York philanthropist Enid Haupt, Washington Post Co. chairman of the board Katharine Graham, dancer Edward Villella, former Supreme Court justice Potter Stewart and CBS reporter Mike Wallace.

There was also a large contingent of the Reagans' California friends and political supporters, most of them not household names in Washington. For instance, there was Berger Benson, there in his capacity as Mike Deaver's best friend. "I'm an almost famous person," he said.

Here is what everybody ate, in order, and as described by the White House:

Cold Colombia River salmon en gele'e, dill sauce; supreme chicken Ve'ronique, wild rice amandine, braised endive; bibb lettuce salad, gourmandaise cheese with walnuts; fantaisie of pear sorbet in a basket, apricot slices.

After dinner, singer Ella Fitzgerald performed George Gershwin songs in the East Room.

Then there was dancing in the Great Hall. The king and queen stayed for several numbers, which is unusual. More often, the guest of honor sprints off to Blair House.

But the king and queen danced for almost half an hour. At one point, when Juan Carlos was dancing with Patricia Haig, East Wing staff director Peter McCoy went over to the couple and started waving his arms. Juan Carlos looked at McCoy, motioning that he was content.

"I was just trying to get people to change partners and enjoy themselves," said McCoy.

Afterward, the Reagans slipped upstairs, but apparently not to bed. "Bed?" said McCoy. "There's about an hour of briefing papers."

The following were guests at President and Mrs. Reagan's dinner last night for Spain's King Juan Carlos and Queen Sofia.

Jose Pedro Perez Llorca, foreign minister, and Mrs. Perez Llorca

The marquis of Mondejar, head of the king's household, and the marchioness

Ramon F. Soignie, director general of the cabinet of the foreign ministry

Jose LLado, ambassador of Spain, and Mrs. Llado

Lt. Gen. Joaquin Valenzuela, head of the king's military household

Gen. Sabino F. Campo, secretary general of the king's household

Manuel de Prado, ambassador and president, Instituto de Cooperacion Iberoamericana

Manuel Alabart, ambassador and chief of protocol

Lt. Col. Agustin Munoz-Grandes, aide-de-camp to the king

Jaime de Pinies, permanent representative of Spain to the United Nations, and Mrs. de Pinies

Richard V. Allen, assistant to the president for national security affairs, and Mrs. Allen

Sardinia Adolfo, designer, New York City

Leonore Annenberg, chief of protocol, and Walter H. Annenberg

Sen. Howard H. Baker (R-Tenn.), and Mrs. Baker

James A. Baker III, chief of staff and assistant to the president, and Mrs. Baker

Berger Benson, San Mateo, Calif., and Mrs. Benson

William E. Brock III, United States trade representative, and Mrs. Brock

Rep. James T. Broyhill (R-N.C.), and Mrs. Broyhill

Jesse M. Calhoon, president, National Marine Engineers' Beneficial Association, and Mrs. Calhoon

William J. Casey, CIA director, and Mrs. Casey

H.E. Chiles, Fort Worth, Tex., and Mrs. Chiles

William P. Clark, deputy secretary of state, and Mrs. Clark

James Codding, Santa Rosa, Calif., and Mrs. Codding

Michael K. Deaver, deputy chief of staff and assistant to the president, and Mrs. Deaver

Armand S. Deutsch, Beverly Hills, Calif.

Allen S. Drury, author, New York City

Sen. David Durenberger (R-Minn.), and Mrs. Durenberger

Ella Fitzgerald, Beverly Hills, Calif.

Malcolm S. Forbes, New York City, and Mrs. Forbes

Saul Friedman, Knight-Ridder newspapers, and Mrs. Friedman

Robert S. Fryer, Los Angeles, Calif.

Katharine Graham, chairman of the board, The Washington Post Co.

Robert Keith Gray, chairman, Gray and Co., Washington, D.C.

Alexander M. Haig Jr., secretary of state, and Mrs. Haig

Mrs. Enid A. Haupt, New York, N.Y.

Rep. Frank Horton (R-N.Y.), and Mrs. Horton

Sen. Walter D. Huddleston (D-Ky.), and Mrs. Huddleston

Richard J.V. Johnson, president, Houston Chronicle, and Mrs. Johnson

Dr. Juan Linz, Yale Univeristy, and Mrs. Linz

Tony Martin and Cyd Charisse, Beverly Hills, Calif.

Joel McCrea, Camarillo, Calif., and Mrs. McCrea

Edwin Meese III, counselor to the president, and Mrs. Meese

Rep. Clarence E. Miller (R-Ohio), and Mrs. Miller

Paul C. Mills, president, Santa Barbara Museum of Art, Santa Barbara, Calif., and Mrs. Mills

Robert A. Mosbacher, chairman, Mosbacher Production Co., Houston, Tex.

Ramon Pedro, EFE News Agency

Rep. Jim Santini (D-Nev.)

Sen. Alan K. Simpson (R-Wyo.), and Mrs. Simpson

Justice Potter Stewart and Mrs. Stewart

George W. Strake Jr., secretary of the state of Texas, and Mrs. Strake

Jay Stream, San Luis Obispo, Calif., and Mrs. Stream

Frederick E. Tetzelli, president, Spain-United States Chamber of Commerce, and Mrs. Tetzelli

Terence A. Todman, American ambassador to Spain, and Mrs. Todman

L.G. Trevino, Dallas, Tex., and Mrs. Trevino

Edward J. Villella, New York City, and Mrs. Villela

Mike Wallace, CBS News, New York City, and Mrs. Wallace

Charles Z. Wick, director, International Communications Agency, and Mrs. Wick