structural:scholar_edition
Literature and poetry

While working for the central court, Zhang Heng had access to a variety of written materials located in the Archives of the Eastern Pavilion. Zhang read many of the great works of history in his day and claimed he had found ten instances where the Records of the Grand Historian by Sima Qian (145–90 BC) and the Book of Han by Ban Gu (AD 32–92) differed from other ancient texts that were available to him. His account was preserved and recorded in the 5th-century text of the Book of Later Han by Fan Ye (398–445). His rhapsodies and other literary works displayed a deep knowledge of classic texts, Chinese philosophy, and histories. He also compiled a commentary on the Taixuan (太玄, "Great Mystery") by the Daoist author Yang Xiong (53 BC–AD 18).

Xiao Tong (501–531), a crown prince of the Liang dynasty (502–557), immortalized several of Zhang's works in his literary anthology Selections of Refined Literature. Zhang's fu rhapsodies include "Western Metropolis Rhapsody" (Xī jīng fù 西京賦), "Eastern Metropolis Rhapsody" (Dōng jīng fù 東京賦), "Southern Capital Rhapsody" (Nán dū fù 南都賦), "Rhapsody on Contemplating the Mystery" (Sī xuán fù 思玄賦), and Return to the Field. The latter fuses Daoist ideas with Confucianism and was a precursor to later Chinese metaphysical nature poetry, according to Liu Wu-chi. A set of four short lyric poems entitled Lyric Poems on Four Sorrows (Sì chóu shī 四愁詩), is also included with Zhang's preface. This set constitutes some of the earliest heptasyllabic shi Chinese poetry written. While still in Luoyang, Zhang became inspired to write his "Western Metropolis Rhapsody" and "Eastern Metropolis Rhapsody", which were based on the "Rhapsody on the Two Capitals" by the historian Ban Gu. Zhang's work was similar to Ban's, although the latter fully praised the contemporaneous Eastern Han regime while Zhang provided a warning that it could suffer the same fate as the Western Han if it too declined into a state of decadence and moral depravity. These two works satirized and criticized what he saw as the excessive luxury of the upper classes. Zhang's "Southern Capital Rhapsody" commemorated his home city of Nanyang, home of the restorer of the Han dynasty, Guangwu.

In Zhang Heng's poem "Four Sorrows", he laments that he is unable to woo a beautiful woman due to the impediment of mountains, snows and rivers. Scholars Rafe de Crespigny and David R. Knechtges claim that Zhang wrote this as an innuendo hinting at his inability to keep in contact with the emperor, hindered by unworthy rivals and petty men. This poem is one of the first in China to have seven words per line. His "Four Sorrows" reads:

In another poem of his called "Stabilizing the Passions" (Dìng qíng fù 定情賦)—preserved in a Tang dynasty (618–907) encyclopedia, but referred to earlier by Tao Qian (365–427) in praise of Zhang's lyrical minimalism—Zhang displays his admiration for an attractive and exemplary woman. This simpler type of fu poem influenced later works by the prominent official and scholar Cai Yong (132–192). Zhang wrote:

Zhang's long lyrical poems also revealed a great amount of information on urban layout and basic geography. His rhapsody "Sir Based-On-Nothing" provides details on terrain, palaces, hunting parks, markets, and prominent buildings of Chang'an, the Western Han capital. Exemplifying his attention to detail, his rhapsody on Nanyang described gardens filled with spring garlic, summer bamboo shoots, autumn leeks, winter rape-turnips, perilla, evodia, and purple ginger. Along with Sima Xiangru (179–117 BC), Zhang listed a variety of animals and hunting game inhabiting the park, which were divided in the northern and southern portions of the park according to where the animals had originally come from: northern or southern China. Somewhat similar to the description of Sima Xiangru, Zhang described the Western Han emperors and their entourage enjoying boat outings, water plays, fishing, and displays of archery targeting birds and other animals with stringed arrows from the tops of tall towers along Chang'an's Kunming Lake. The focus of Zhang's writing on specific places and their terrain, society, people, and their customs could also be seen as early attempts of ethnographic categorization. In his poem "Xijing fu", Zhang shows that he was aware of the new foreign religion of Buddhism, introduced via the Silk Road, as well as the legend of the birth of Buddha with the vision of the white elephant bringing about conception. In his "Western Metropolis Rhapsody" (西京賦), Zhang described court entertainments such as juedi (角抵), a form of theatrical wrestling accompanied by music in which participants butted heads with bull horn masks.

With his "Responding to Criticism" (Ying jian 應間), a work modeled on Yang Xiong's "Justification Against Ridicule", Zhang was an early writer and proponent of the Chinese literary genre shelun, or hypothetical discourse. Authors of this genre created a written dialogue between themselves and an imaginary person (or a real person of their entourage or association); the latter poses questions to the author on how to lead a successful life. He also used it as a means to criticize himself for failing to obtain high office, but coming to the conclusion that the true gentleman displays virtue instead of greed for power. In this work, Dominik Declercq asserts that the person urging Zhang to advance his career in a time of government corruption most likely represented the eunuchs or Empress Liang 's (116–150) powerful relatives in the Liang clan. Declercq states that these two groups would have been "anxious to know whether this famous scholar could be lured over to their side", but Zhang flatly rejected such an alignment by declaring in this politically charged piece of literature that his gentlemanly quest for virtue trumped any desire of his for power.

Zhang wrote about the various love affairs of emperors dissatisfied with the imperial harem, going out into the city incognito to seek out prostitutes and sing-song girls. This was seen as a general criticism of the Eastern Han emperors and their imperial favorites, guised in the criticism of earlier Western Han emperors. Besides criticizing the Western Han emperors for lavish decadence, Zhang also pointed out that their behavior and ceremonies did not properly conform with the Chinese cyclical beliefs in yin and yang. In a poem criticizing the previous Western Han dynasty, Zhang wrote: