James W. Lewis, the subject of a three-month nationwide manhunt, was arrested in the New York City Public Library today and was taken into custody on charges that he attempted to extort $1 million from the makers of Tylenol.

Lewis was sitting at a long reference table in the library's reading room, apparently assembling a list of names and addresses of newspapers, when FBI agents walked in.

Lewis has been writing to The Chicago Tribune to say that he is innocent of the seven Tylenol murders in Chicago. The FBI, certain that he was checking the Tribune to see if his letters had been printed, staked out the Tribune's newsstand outlets in Manhattan, but could not locate Lewis. Then they flooded the public libraries with his picture.

After a tip from a library employe called in at noon today, Lewis was surrounded by "several" FBI agents and arrested at 2 p.m. Lewis did not resist, according to FBI special agent Thomas Sheer.

Lewis was unarmed and admitted his identity immediately. He was removed to the U.S. District Court in lower Manhattan and arraigned on charges of extortion and unlawful flight. Lewis was ordered held on $5 million bond, and a hearing was set for Dec. 23.

FBI spokesmen, at a news conference here today, could not say where Lewis had been living at the time of his arrest. They also said they did not know the whereabouts of Lewis' wife, but were renewing a request for her to call police and turn herself in.

Lewis and his wife, Leann, had been spotted in New York about a month ago living in a $95-per-week room in a hotel on Lexington Avenue. Investigators said they had apparently been living there since several days before the Tylenol killings began, and had been seen frequently enough to make it unlikely that they had returned to Chicago during the time when the cyanide-tainted Tylenol capsules were being placed on drugstore shelves.

Lewis is charged only in connection with the attempted extortion, not the Tylenol killings.

Former neighbors of the couple in Chicago told police and reporters three months ago that one of Lewis' almost daily habits was to go to the local library and pore over the business sections of newspapers.

The couple first arrived in Chicago at the end of 1981, 10 months before the seven Tylenol murders took place, Chicago investigators say.

They drove up in a beat-up 1969 American Motors station wagon, police said, and began calling themselves Robert and Nancy Richardson. Lewis was wanted at the time on Kansas City charges that he allegedly used a tax service to bilk his elderly customers out of land, and also with unlawful flight to avoid prosecution.

Those arrest warrants still stand in addition to the later charges.

In Chicago last winter, the two moved into a shabby rooming house. There they lived for 10 months, neighbors said, with Lewis staying home and spinning tales and clipping newspapers during the day, while Mrs. Lewis went to work at a travel agency.

The travel agency was the link that brought the Lewises officially into the Tylenol killings case.

In September, one week after the last of the seven deaths in Chicago, a handwritten extortion note was opened in the New Jersey headquarters of Johnson & Johnson, parent firm of the company that makes Tylenol.

The letter said $1 million must be deposited in an account at the Continental Illinois Bank and Trust Co., "if you want to stop the killing."

The bank account belonged to the owner of the now-defunct Lakeside Travel Agency, a man who had not long before fired Lewis' wife.

She was a clerk-accountant in the agency and was fired when the owner said he believed she was taking company stationery for personal use, Chicago police said.

The extortion letter was signed with the businessman's name and was written on stationery apparently removed from his office. But police charged that they found Lewis' fingerprints on the letter, and said they found the writing to be similar to a sample of Lewis'.

Though Illinois Attorney General Tyrone Fahner, running for election and investigating the Tylenol crime at the same time, said the Lewises were prime suspects in the Tylenol killings, other investigators disagreed.

Chicago Police Superintendent Richard J. Brzeczek said there was no evidence to tie Lewis to the killings.

Most police officials, who noted the clumsiness of an extortion attempt in which it would have been virtually impossible for the extortionist to collect money from the businessman's bank account, said that the motive probably did not involve any collection of cash.

Officials said they believe the motive was to create a hoax designed to embarrass the businessman.

The idea that the Tylenol extortion note was a hoax also fit descriptions of those who had known Lewis in Chicago. The schemes, said Thomas Kline, building manager at the rooming house, were of many different kinds--some for fun, some for imagined profits, but some to get revenge as well.

Those involving revenge, Kline said, included one in which Lewis claimed to have mixed up the wiring of an electrician's house, and another in which he was supposed to have gotten back at a landlord by dropping an aerosol can near the building's boiler in the summer. The can was intended to explode when the boiler was turned on months later, Kline said.