TeX - LaTeX Asked on August 14, 2021
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.
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.
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}
Answered by AndréC on August 14, 2021
Please use XeLaTeX or LuaLaTeX!
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}
Answered by Alan Xiang on August 14, 2021
A XeLaTeX approach, note that this is a pseudo vertical typesetting.
documentclass[tikz]{standalone}
usepackage[UTF8]{ctex}
tikzset{
pseudo vertical/.style={
% 1ccwd is the width of one Chinese character, see user manual of ctex pkg
text width=1ccwd,
% reduce line spacing and allow linebreak before Chinese period punct (。)
% c.f. user manual of xeCJK pkg
font=linespread{1}selectfontxeCJKDeclareCharClass{CJK}{`。}
}
}
begin{document}
begin{tikzpicture}
node[draw, inner sep=2pt, pseudo vertical] at (0,0) {文章内容。};
end{tikzpicture}
end{document}
Answered by muzimuzhi Z on August 14, 2021
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.
Compile with xelatexlualatex.
MWE
documentclass[12pt]{article}
usepackage{tikz}
usetikzlibrary{positioning}
usepackage{xcolor}
usepackage{fontspec}
setmainfont{Noto Serif}
newfontfacezhfont[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.
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.35emhbox{#1}}
newcommand*CJKmove{punctstyle{plain}% do not modify the spacing between punctuations
letCJKsymbolCJKmovesymbol
letCJKpunctsymbolCJKsymbol}
newcommandsampletext{『文章内容』。}
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:
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.35emhbox{#1}}
newcommand*CJKmove{punctstyle{plain}% do not modify the spacing between punctuations
letCJKsymbolCJKmovesymbol
letCJKpunctsymbolCJKsymbol}
newcommandsampletext{『文章内容』。}
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}
Answered by Cicada on August 14, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP