![如何在树/图表中书写孟加拉语文本?](https://linux22.com/image/434010/%E5%A6%82%E4%BD%95%E5%9C%A8%E6%A0%91%2F%E5%9B%BE%E8%A1%A8%E4%B8%AD%E4%B9%A6%E5%86%99%E5%AD%9F%E5%8A%A0%E6%8B%89%E8%AF%AD%E6%96%87%E6%9C%AC%EF%BC%9F.png)
梅威瑟:
\documentclass[tikz,border=2pt,multi]{standalone}
\usepackage{forest,array}
\usetikzlibrary{shadows}
\newcolumntype{C}[1]{>{\centering}p{#1}}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{bengali}
% Replace this with whatever font you're using
\newfontfamily\bengalifont[Script=Bengali]{Akaash}
\begin{document}
\begin{forest}
for tree={
if level=0{align=center}{% allow multi-line text and set alignment
align={@{}C{25mm}@{}},
},
draw,
font=\sffamily\bfseries,
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5mm) -| (.child anchor)\forestoption{edge label};
},
parent anchor=south,
child anchor=north,
l sep=10mm,
tier/.wrap pgfmath arg={tier #1}{level()},
edge={ultra thick, rounded corners=2pt},
ultra thick,
inner color=gray!5,
outer color=gray!20,
rounded corners=2pt,
drop shadow,
}
[\textbengali{বাংলা ট্রি}
[B1]
[B2
[C1]
[C2]
]
[B3]
[B4]
]
\end{forest}
\end{document}
得出:
我想 :
答案1
它与字体有关,正如日志中的错误消息所示。
该文档没有定义 sans 字体,因此使用默认的 sans 字体,并且没有孟加拉语,因此森林的命令font=\sffamily\bfseries
具有预期的结果。
Akaash 字体是一种无衬线字体;它有拉丁文和孟加拉文字母;它没有粗体,但可以伪造粗体。这三点很有用。
因此,如果希望保留 Akaash 字体,有两种解决方案可供选择:(A)将 Akaash 设为文档的 sans 字体并继续使用font=\sffamily\bfseries
:
\setsansfont{Akaash}[Script=Bengali,AutoFakeBold=4.0]
或者,(B)通过多语方法在森林中使用 Akaash,并将森林字体命令更改为font=\bengalifont\bfseries
:
\newfontfamily\bengalifont[AutoFakeBold=4.0,Script=Bengali]{Akaash}
在这两种情况下,都需要假粗体选项。
(A)将 Akaash 设置为文档的 sans 字体并为其定义假粗体。
平均能量损失
\documentclass[tikz,border=2pt,multi]{standalone}
\usepackage{forest,array}
\usetikzlibrary{shadows}
\newcolumntype{C}[1]{>{\centering}p{#1}}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{bengali}
\setmainfont{Noto Serif}
\setsansfont{Akaash}[Script=Bengali,AutoFakeBold=4.0,Renderer=HarfBuzz]%HarfBuzz for lualatex.
% Replace this with whatever font you're using
\newfontfamily\bengalifont[Script=Bengali,Renderer=HarfBuzz]{Akaash}%HarfBuzz for lualatex.
\begin{document}
\begin{forest}
for tree={
if level=0{align=center}{% allow multi-line text and set alignment
align={@{}C{25mm}@{}},
},
draw,
font=\sffamily\bfseries\color{blue},
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5mm) -| (.child anchor)\forestoption{edge label};
},
parent anchor=south,
child anchor=north,
l sep=10mm,
tier/.wrap pgfmath arg={tier #1}{level()},
edge={ultra thick, rounded corners=2pt},
ultra thick,
inner color=gray!5,
outer color=gray!20,
rounded corners=2pt,
drop shadow,
}
[\textbengali{বাংলা ট্রি}
[B1]
[B2
[C1]
[C2]
]
[B3]
[B4]
]
\end{forest}
\end{document}
(B)保留文档中未定义字体,但对树木使用粗体 Akaash 字体。
平均能量损失
\documentclass[tikz,border=2pt,multi]{standalone}
\usepackage{forest,array}
\usetikzlibrary{shadows}
\newcolumntype{C}[1]{>{\centering}p{#1}}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{bengali}
\setmainfont{Noto Serif}
%\setsansfont{Akaash}[Script=Bengali,AutoFakeBold=4.0,Renderer=HarfBuzz]%HarfBuzz for lualatex.
% Replace this with whatever font you're using
\newfontfamily\bengalifont[AutoFakeBold=4.0,Script=Bengali,Renderer=HarfBuzz]{Akaash}%HarfBuzz for lualatex.
\begin{document}
\begin{forest}
for tree={
if level=0{align=center}{% allow multi-line text and set alignment
align={@{}C{25mm}@{}},
},
draw,
font=\bengalifont\bfseries\color{red},
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5mm) -| (.child anchor)\forestoption{edge label};
},
parent anchor=south,
child anchor=north,
l sep=10mm,
tier/.wrap pgfmath arg={tier #1}{level()},
edge={ultra thick, rounded corners=2pt},
ultra thick,
inner color=gray!5,
outer color=gray!20,
rounded corners=2pt,
drop shadow,
}
[\textbengali{বাংলা ট্রি}
[B1]
[B2
[C1]
[C2]
]
[B3]
[B4]
]
\end{forest}
\end{document}