I am trying to typeset text including CJK ideographs in a verbatim environment. Because I want to indent my verbatim text slightly, I am using the fancyvrb package. Here's a MWE:



\setCJKmonofont{Noto Sans CJK JP}

Code like this\ldots
auto x = "林";

However I find there's an extra space character in the output, immediately between the opening double-quote and the ideograph.


It does seem to be a space character and not just excessive kerning, as it copies-and-pastes from the PDF as a space character. Can anyone see how to get rid of it? In case it's relevant, I'm using XeLaTeX version 3.14159265-2.6-0.99996.

It doesn't happen with LaTeX's built-in verbatim environment, but I don't know a way of altering the margins of that. I'm not wedded to using fancyvrb, if I can set the left margin of the verbatim environment some other way.

1 Answer 1


I'm having the same problem as you. It's because xeCJK is inserting glue (a whitespace by default) between english and CJK characters.

Solution 1:


Be careful that this is a global setup, it will affect the whole document, not only the verbatim environment.

Solution 2:

Wrap verbatim env inside {\CJKsetecglue{} ...your normal code... }, so it only takes effect locally.

    auto x = "林";
  • In the end I went with a compromise between your two solutions, and used a \renewenvironment{verbatim} to do the \CJKsetecglue{} automatically along the lines of this solution. I didn't want to do it unconditionally (per your first solution) because that glue is needed in ordinary text (e.g. "Set x to contain the glyph 林").
    – richard
    Commented Jun 20, 2017 at 16:03
  • Also, now I know what to search for, this question is essentially the same problem.
    – richard
    Commented Jun 20, 2017 at 16:04
  • I too know what to search for after reading xeCJK document. Other than \renewenvironment you can also use \AtBeginEnvironment{verbatim}{\CJKsetecglue{}}
    – duyue
    Commented Jun 21, 2017 at 3:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .