After studying verbatim. sty, we found that the verbatim environment uses ttfamily fonts by default, so we only need to redefine
\ Verbatim @ font macro enables verbatim to use rmfamily or sffamily fonts by default through \ setromanfont or
\ Setsansfont: Set the font family to Chinese.
\ Documentclass [a4paper] {Article}
\ Usepackage {fontspec, xunicode, xltxtra, verbatim}
\ Setsansfont [boldfont = {"[simhei. TTF]"}] {"[simsun. TTC]"}
\ Setromanfon [boldfont = {"[simhei. TTF]"}] {"[simsun. TTC]"}
% You can also use the font name directly when setting the font. The following three methods are equivalent:
% \ Setromanfont [boldfont = {}] {}
% \ Setromanfont [boldfont = {simhei}] {simsun}
% \ Setromanfont [boldfont = {"[simhei. TTF]"}] {"[simsun. TTC]"}
%, But the first method is not recommended. If you use the font of a Chinese name
% Roman and sans fonts are set to the same font. For example, you can set both romanfont and sanfont to ""
% Will cause compilation errors. But there are no problems with the other two methods. Maybe it is a bug in the fontspec package. Push
% Recommend the third method to directly specify the font file name.
\ Begin {document}
Can you see some CJK characters in the Verbatim?
\ Makeatletter
\ Def \ verbatim @ font {\ sffamily \ small} % if Roman fonfamily is used, change sffamily to rmfamily
\ Makeatother
\ Begin {verbatim}
Some ASCII characters!
You can see Chinese characters!
\ End {verbatim}
\ End {document}
PS: This article was first published by myself in the water and wood Tsinghua Tex edition.