Margaery is first mentioned in A Game of Thrones, when Renly Baratheon shows Eddard Stark and later King Robert Baratheon her picture and asks them whether she looks like Lyanna Stark. Margaery appears in A Clash of Kings, where we learn she has wed Renly Baratheon, a union that signifies her family's support for Renly's claim to the Iron Throne. After Renly's assassination, the Tyrells switch allegiance and Margaery is instead offered to wed King Joffrey Baratheon. In A Storm of Swords Margaery takes up residence in the palace at King's Landing, and she gains much love from the local people through the charitable activities of herself and her bannermen. Margaery forms an amiable relationship with the King's ex-fiancee Sansa Stark  and through Sansa she learns much about Joffrey's true nature. Margaery, alongside her grandmother Olenna Redwyne, plot to have Sansa wed to Willas Tyrell, however the details of their plot are revealed to the Lannisters and Sansa is instead wed to Tyrion Lannister. Margaery weds King Joffrey but he is murdered on their wedding night. In A Feast for Crows Margaery marries Joffrey's younger brother, Tommen Baratheon. Margaery remains popular with the people of King's Landing and encourages Tommen to engage in some leadership activities, however her ideas are stymied by Cersei Lannister. Margaery's position is of some consternation to Cersei, who sees her as a threat to the power grip she has over Westeros. Cersei schemes to dispose of Margaery and so accuses her of adultery and treason. On these charges Margaery is imprisoned by the Faith. However Cersei's plans backfire and she herself is incarcerated. In A Dance with Dragons Margaery is released from her prison into the custody of Lord Randyll Tarly of Horn Hill, where she awaits a trial by judges of the Faith.