3

I want to create a node with Chinese text written in vertical direction. Of course, I don't want the characters to be rotated! Is that possible?

MWE:

\documentclass[tikz]{standalone}
\usepackage[UTF8]{ctex}

\begin{document}

\begin{tikzpicture} \node[draw,inner sep=2pt] at (0,0) {文章内容。}; \end{tikzpicture}

\end{document}

EDIT: I am using PdfLaTeX and I need only a couple of short vertical text nodes that will fit into a single column.

Pygmalion
  • 6,387
  • 4
  • 34
  • 68

4 Answers4

4

Please use XeLaTeX or LuaLaTeX!

output

\documentclass{article}
\usepackage{tikz}
\usepackage{fontspec}
\usepackage{expl3}
\setmainfont{FandolSong-Regular.otf}

\begin{document}

\ExplSyntaxOn

\cs_new:Npn __map_function #1 { \tl_put_right:Nn \l_tmpa_tl {\noindent #1 \par} }

\cs_new:Npn __map_function_centering #1 { \tl_put_right:Nn \l_tmpa_tl {\centering #1 \par} }

\newcommand{\verticaltext}[1]{ \str_set:Nn \l_tmpa_str {#1} \tl_clear:N \l_tmpa_tl \str_map_function:NN \l_tmpa_str __map_function \tl_use:N \l_tmpa_tl }

\newcommand{\verticalcentertext}[1]{ \str_set:Nn \l_tmpa_str {#1} \tl_clear:N \l_tmpa_tl \str_map_function:NN \l_tmpa_str __map_function_centering \tl_use:N \l_tmpa_tl }

\ExplSyntaxOff

\begin{tikzpicture} \node[draw,inner sep=2pt,text width=7mm] at (0,0) {\verticaltext{文章内容。}}; \node[draw,inner sep=2pt,text width=7mm] at (1,0) {\verticaltext{abcde}}; \node[draw,inner sep=2pt,text width=7mm] at (2,0) {\verticalcentertext{文章内容。}}; \node[draw,inner sep=2pt,text width=7mm] at (3,0) {\verticalcentertext{abcde}}; \end{tikzpicture}

\end{document}

Alan Xiang
  • 5,227
  • I have 10000 lines of LaTeX that compile well in MikTeX. Could it be done in MikTeX? – Pygmalion Jul 30 '20 at 14:31
  • @Pygmalion MikTeX, just like TexLive are TeX distributions, which both contain XeTeX, LuaTeX (various TeX engines). Usually most CJK documents are compiled with XeTeX and LuaTeX, because they have native Unicode support. PDFLaTeX, however, doesn't support this feature. You can try running the code snippet above to see if results can be reproduced correctly. If you are using PDFLaTeX, maybe you can consider switching to XeTeX/LuaTeX. – Alan Xiang Jul 30 '20 at 14:40
  • @Pygmalion If you are using PDFLaTeX, and the need of vertical text is small, I think you can do it manually by entering \noindent 文 \par \noindent 章 \par... , which would be fairly easy to generate if you know other programming languages. – Alan Xiang Jul 30 '20 at 14:44
  • Yes, I am using PdfLaTeX and I am kind of reluctant to switch to XeLaTeX for only a few vertical nodes. However \noident \par combination does not work. – Pygmalion Jul 30 '20 at 16:02
  • Another question: with XeLaTeX I could actually use any font. That would be a big plus. – Pygmalion Jul 30 '20 at 16:26
  • @Pygmalion Did you set text width? It is necessary to specify a width for line breaks inside nodes to work. – Alan Xiang Jul 30 '20 at 16:41
  • @Pygmalion XeLaTeX allows one to load any OpenType/TrueType fonts. – Alan Xiang Jul 30 '20 at 16:46
  • @Pygmalion Note that \centering 文 \par \centering 章 \par gives horizontally centered text. – Alan Xiang Jul 30 '20 at 16:48
4

A XeLaTeX approach, note that this is a pseudo vertical typesetting.

\documentclass[tikz]{standalone}
\usepackage[UTF8]{ctex}

\tikzset{ pseudo vertical/.style={ % 1\ccwd is the width of one Chinese character, see user manual of ctex pkg text width=1\ccwd, % reduce line spacing and allow linebreak before Chinese period punct (。) % c.f. user manual of xeCJK pkg font=\linespread{1}\selectfont\xeCJKDeclareCharClass{CJK}{`。} } }

\begin{document} \begin{tikzpicture} \node[draw, inner sep=2pt, pseudo vertical] at (0,0) {文章内容。}; \end{tikzpicture} \end{document}

enter image description here

muzimuzhi Z
  • 26,474
  • I tested this with PdfLaTeX and it actually works apart for the point. Maybe I can avoid points altogether. – Pygmalion Jul 30 '20 at 16:23
  • @Pygmalion I'm on macOS, and ctex doesn't support pdflatex on macOS (since the upstream package CJK relies on Chinese system fonts available on Windows only). Sorry I cannot test the pdflatex approach for you. – muzimuzhi Z Jul 30 '20 at 16:52
3

I can't read or write Chinese, then I don't know if this is the right way to write it.

I just specified a width to the text text width=1.5em so that each character is displayed one under the other.

enter image description here

\documentclass[tikz]{standalone}
\usepackage[UTF8]{ctex}

\begin{document}

\begin{tikzpicture} \node[draw,inner sep=2pt,text width=1.5em] at (0,0) {文章内容。}; \end{tikzpicture}

\end{document}

AndréC
  • 24,137
2

You can use system fonts, like the Noto series. That way you are not tied to particular font packages for specific systems.

This variation of an answer uses tikz positioning, so useful for short texts.

vert zh

Compile with xelatex\lualatex.

MWE

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{xcolor}

\usepackage{fontspec} \setmainfont{Noto Serif} \newfontface\zhfont[Scale=2.5,Colour=blue]{Noto Serif SC} \usepackage{lipsum}

\begin{document} \ \marginpar{ \begin{tikzpicture}[inner sep=3pt,node distance=0mm,font={\zhfont}] \node (a) {文}; \node (b) [below=of a] {章}; \node (c) [below=of b] {内}; \node (d) [below=of c] {容}; \node (e) [below=of d] {。}; \end{tikzpicture}} \lipsum[2]\lipsum[2] \end{document}


Addendum:

Alternatively, question Vertical Chinese text with XeTeX provides a 'rotate the glyphs' solution for fonts with the feature. The minipage box they are in is also rotated, so the characters come out vertical.

vertical

This could be adapted to tikz.

MWE

\documentclass{article}

\usepackage{graphicx} % for \rotatebox

\usepackage{xeCJK} \newfontlanguage{Chinese}{CHN} \setCJKmainfont{Noto Serif CJK SC} \setCJKfamilyfont{songvert}[RawFeature={vertical;+vert},Script=CJK,Language=Chinese,Vertical=RotatedGlyphs]{Noto Serif SC} \setmainfont{Noto Serif}

\newcommand\CJKmovesymbol[1]{\raise.35em\hbox{#1}} \newcommand\CJKmove{\punctstyle{plain}% do not modify the spacing between punctuations \let\CJKsymbol\CJKmovesymbol \let\CJKpunctsymbol\CJKsymbol}

\newcommand\sampletext{『文章内容』。}

\begin{document}

\sampletext\ This is some sample text. \begin{center} \rotatebox{-90}{\fbox{\begin{minipage}{10em} \CJKfamily{songvert}\CJKmove \sampletext \ \sampletext \ \sampletext \ \sampletext \ \end{minipage}}} \end{center} \sampletext\ This is some sample text.

\end{document}


A tikz node inline, containing rotated glyphs and their box:

vertical inline

MWE

\documentclass{article}
\usepackage{xcolor}

\usepackage{graphicx} % for \rotatebox \usepackage{tikz}

\usepackage{xeCJK} \newfontlanguage{Chinese}{CHN} \setCJKmainfont{Noto Serif CJK SC} \setCJKfamilyfont{songvert}[RawFeature={vertical;+vert},Script=CJK,Language=Chinese,Vertical=RotatedGlyphs]{Noto Serif SC} \setmainfont{Noto Serif}

\newcommand\CJKmovesymbol[1]{\raise.35em\hbox{#1}} \newcommand\CJKmove{\punctstyle{plain}% do not modify the spacing between punctuations \let\CJKsymbol\CJKmovesymbol \let\CJKpunctsymbol\CJKsymbol}

\newcommand\sampletext{『文章内容』。}

\begin{document}

\sampletext\ This is some sample text. \tikz \node {\rotatebox{-90}{\colorbox{red!4}{ \CJKfamily{songvert}\CJKmove \sampletext}}}; \sampletext\ This is some sample text.

\end{document}

Cicada
  • 10,129