3

I need to input Chinese characters in a document and I need to set the indent of the first line to 2 times width of current font to satisfy the Chinese habits, and the width of a Chinese character is not 1em or 1ex certainly.

So I try to use the LaTeX2e command \f@size to get the width of current font. I use \setlength{\parindent}{\f@size \p@}, it works well with the indent of only 1 time width of current font. However, when I set \setlength{\parindent}{2\f@size \p@}, the indent gets toooo large, just like the following image: The indent gets toooo large

And the effect of the indent of only 1 time width of current font is The 1-character indent

Also, I've tried use the \dimeval{} command, but it also doesn't work as expected. The MWE is

\documentclass{article}
\usepackage{indentfirst,zhlipsum,xeCJK}
\makeatletter
\setlength{\parindent}{\dimeval{2\f@size \p@}}
\makeatother

\begin{document} \zhlipsum[6] \end{document}

Axia
  • 514
  • 1
    The width is just 2em, 1em being exactly the width of one CJK character. So, you can just set \setlength{\parindent}{2em}. – Jasper Habicht Mar 16 '24 at 07:47
  • 2
    Note that, despite its name, 1em is not exactly the width of the capital letter M in most typefaces. Rather, it is the size of the current font. Thus, a space of 1em will always be as wide as the font is high resulting in a square space, regardless of the font or font size. And as CJK characters are typically designed to fit inside a square, their width is 1em. – Jasper Habicht Mar 16 '24 at 07:53
  • 2
    You could also use \setlength{\parindent}{\dimeval{\f@size \p@ * 2}} or \setlength{\parindent}{\dimexpr\f@size \p@ * 2\relax}. – Jasper Habicht Mar 16 '24 at 08:27

2 Answers2

4

Note that, despite its name, 1em is not exactly the width of the capital letter M in most typefaces. Rather, it is the size of the current font. Thus, a space of 1em will always be as wide as the font is high resulting in a square space, regardless of the font or font size. And as CJK characters are typically designed to fit inside a square, their width is 1em.

Therefore, what you are looking for is just \setlength{\parindent}{2em}:

\documentclass{article}
\usepackage{indentfirst, zhlipsum, xeCJK}
\setlength{\parindent}{2em}

\begin{document} \zhlipsum[6]

口口口口口口口口口口口口口口口口口口口口口口口口口口口口口口口口口口口

\end{document}

enter image description here

There might be some shifts as you are typesetting justified text. This means that the characters are spread a bit to fit exactly inside the line. Also, you can see that white space at the end of the line is adjusted in the case of punctuation marks. This as well can lead to small shifts in the position of single characters in a line. But nevertheless, the typographically correct width for the indentation of CJK paragraphs is 2em.


Adding to the question why your approach did not work, also see this Q&A. You can just test the output of the parsed dimension:

\documentclass{article}
\usepackage{indentfirst,zhlipsum,xeCJK}
\makeatletter
\setlength{\parindent}{\dimeval{2\f@size \p@}}
\makeatother

\begin{document} \the\parindent \end{document}

This yields 210pt, which is obviously not the intended outcome. But then, you can do:

\documentclass{article}
\usepackage{indentfirst,zhlipsum,xeCJK}
\makeatletter
\setlength{\parindent}{\dimeval{\f@size \p@ * 2}}
\makeatother

\begin{document} \the\parindent \end{document}

This results in 20pt, which, in this case, is the same as 2em, the width of two characters.

4

Typically you can just use 2em to set the \parindent. However, if you want to change the \CJKglue (glue between CJK characters) for some reason, you'd better use \ccwd from ctex bundle since it takes the glue into consideration.

For pdftex and xetex, the definition of \ccwd is

\box_new:N \l_ctex_tmp_box
\hbox_set:Nn \l_ctex_tmp_box { \CJKglue }
\dim_new:N \ccwd
\dim_set:Nn \ccwd { \box_wd:N \l_ctex_tmp_box + \f@size \p@ }

And test the following example:

\documentclass{article}
\usepackage{indentfirst,zhlipsum,xeCJK}
\xeCJKsetup{CJKglue = {\hskip 4pt plus 0.08\baselineskip}}
\makeatletter
\ExplSyntaxOn
\box_new:N \l_ctex_tmp_box
\hbox_set:Nn \l_ctex_tmp_box { \CJKglue }
\dim_new:N \ccwd
\dim_set:Nn \ccwd { \box_wd:N \l_ctex_tmp_box + \f@size \p@ }
\ExplSyntaxOff
\setlength{\parindent}{2\ccwd}
\makeatother

\begin{document} \zhlipsum[6] \end{document}

enter image description here

If you replace 2\ccwd with 2em, the effect is

enter image description here

As is shown above, the 1st CJK character in the 1st line isn't aligned with the 3rd CJK character in the 2nd line.

Stephen
  • 3,826