我尝试在文本中的某些字母上方放置箭头形状。我尝试使用及其配对来补偿tikzpicture
单词中间的额外空间。execute at begin picture
end
效果不太好,有没有更好的方法?
\documentclass{minimal}
\makeatletter
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.arrows}
\newcommand\toneUp[1]{%
\def\mychar{#1}%
\begin{tikzpicture}[
execute at begin picture={
\pgfmathparse{0.5*(1.6mm-\widthof{\mychar})}
\hspace*{-\pgfmathresult mm}
},
execute at end picture={
\pgfmathparse{0.5*(1.6mm-\widthof{\mychar})}
\hspace*{-\pgfmathresult mm}
}]
\node[inner sep=0pt, outer sep=0pt] (mychar) {\mychar};
\node[single arrow, minimum height=5mm, minimum width=7mm, single arrow head extend=3mm, single arrow head indent=1mm, scale=0.3, red, fill=red, rotate=90, above=0.3mm of mychar.north, anchor=west] {};
\end{tikzpicture}
}
\setlength{\parindent}{0pt}
\makeatother
\begin{document}
ārop\toneUp{i}tehi\\
paṇṇ\toneUp{ā}kār\toneUp{a}\\
bh\toneUp{ū}te
\end{document}
答案1
编辑:箭头更好,但字距调整并不完全完美,因为\mychar
在这个节点上是单独绘制的。
您可以使用overlay
选项从 tikzpicture 的自动边界框计算中删除箭头。
您可以使用em
或ex
尺寸来自动使箭头的尺寸适应当前字体尺寸。
\documentclass{minimal}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.arrows}
\newcommand\toneUp[1]{%
\def\mychar{#1}%
\begin{tikzpicture}[inner sep=0,outer sep=0]
\node (mychar) {\mychar};
\node[
overlay,
single arrow,
inner sep=.05em,
minimum height=.25em,
minimum width=.35em,
single arrow head extend=.15em,
single arrow head indent=.05em,
red,
fill=red,
rotate=90,
above=0.3mm of mychar.north,
anchor=west] {};
\end{tikzpicture}%
}
\setlength{\parindent}{0pt}
\begin{document}
ārop\toneUp{i}tehi
paṇṇ\toneUp{ā}kār\toneUp{a}
bh\toneUp{ū}te
\end{document}
答案2
我没有正确安装字体,但您需要取消由于箭头而导致的边界框更新。因此,您可以使用pgfinterruptpicture
允许您避免边界框更新的环境。
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Pagella}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.arrows}
\newcommand\toneUp[1]{%
\begin{tikzpicture}
\node[inner sep=0pt, outer sep=0pt] (mychar) {#1};
\begin{pgfinterruptpicture}
\node[single arrow, minimum height=5mm,
minimum width=7mm, single arrow head extend=3mm,
single arrow head indent=1mm, scale=0.3, red, fill=red,
rotate=90, above=0.3mm of mychar.north, anchor=west] {};
\end{pgfinterruptpicture}
\end{tikzpicture}%
}
\setlength{\parindent}{0pt}
\begin{document}
ārop\toneUp{i}tehi\\
paṇṇ\toneUp{ā}kār\toneUp{a}\\
bh\toneUp{ū}te
\end{document}