使用 TikZ 创建结合 svg 图像和文本的自定义单词

使用 TikZ 创建结合 svg 图像和文本的自定义单词

我正在尝试创建一个自定义词,f-hole,其中f我使用小提琴 f-hole 的实际轮廓来代替:

在此处输入图片描述

我有一个.svg要制作成符号的轮廓文件,并使用这个答案我设法使用\usetikzlibrary{svg.path}它将其包含在 中tikzpicture。然后我手动调整了大小和位置,使其位于文本旁边-hole。但是,我无法使其与文本的基线对齐,也无法使标点符号围绕它工作(在单词之前和之后)。

在此处输入图片描述

此外,当我更改字体大小时,我的解决方案无法很好地缩放(我需要它至少能footnotesize与之配合使用)。有什么建议可以改善这种情况吗?我需要一个 pdfLaTeX 解决方案。huge

在此处输入图片描述

代码

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{newtxtext}
\usepackage{tikz}
\usetikzlibrary{svg.path}

\tikzset{
  fhole/.pic={
    \fill [scale=0.045] svg{m141.50504652572636,8.750154755020048 l12.88491,15.0039 c-6.33974,5.397 -6.91986,11.7233 -3.91811,17.7654 c2.79858,4.7279 9.39378,6.1777 14.58215,3.3698 c14.90229,-8.6016 2.97205,-29.2657 -8.32413,-35.8434 c-12.46952,-7.671 -23.48465,-2.9727 -32.06999,2.2816 c-32.57131,21.0958 -31.29905,53.0495 -36.53204,111.7787 l-3.80143,2.2686 l3.46803,2.8209 c-1.81268,50.3552 -7.19548,108.8638 -47.31312,118.9301 l-13.70647,-17.533 c6.63203,-1.8678000000000003 11.01697,-7.1683 12.24781,-13.0208 c1.58418,-12.036 -9.34214,-23.7985 -23.61721,-18.9647 c-14.27507,4.8337 -12.70367,27.7181 -1.47322,39.9927 c11.23043,12.2746 28.2174,15.8516 42.3734,10.8362 c41.92159,-16.3793 51.61678,-67.3469 52.89911,-111.1003 l3.68819,-2.1338 l-3.4807,-3.4122 c2.6751,-40.5983 -4.97189,-105.0606 32.09282,-123.0397 z};
  }
}

\newcommand\fhole{\begin{tikzpicture}
     \path (0,0) pic [yscale=-1] {fhole};
     \node at (0.64,-0.17) {-hole};
  \end{tikzpicture}}

\begin{document}
The violin \fhole.

\footnotesize The footnotesize violin \fhole.

\huge The huge violin \fhole.
\end{document}

答案1

可以使用该包scalerel将图形缩放到当前字体大小的“f”大小。字距根据@Emma 的建议进行调整。

编辑: \mbox添加以防止换行连字符并 \hspace{0pt}插入以允许换行连字符。

在此处输入图片描述

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{newtxtext}
\usepackage{tikz}
\usetikzlibrary{svg.path}

\tikzset{
  fhole/.pic={
    \fill svg{m141.50504652572636,8.750154755020048 l12.88491,15.0039 c-6.33974,5.397 -6.91986,11.7233 -3.91811,17.7654 c2.79858,4.7279 9.39378,6.1777 14.58215,3.3698 c14.90229,-8.6016 2.97205,-29.2657 -8.32413,-35.8434 c-12.46952,-7.671 -23.48465,-2.9727 -32.06999,2.2816 c-32.57131,21.0958 -31.29905,53.0495 -36.53204,111.7787 l-3.80143,2.2686 l3.46803,2.8209 c-1.81268,50.3552 -7.19548,108.8638 -47.31312,118.9301 l-13.70647,-17.533 c6.63203,-1.8678000000000003 11.01697,-7.1683 12.24781,-13.0208 c1.58418,-12.036 -9.34214,-23.7985 -23.61721,-18.9647 c-14.27507,4.8337 -12.70367,27.7181 -1.47322,39.9927 c11.23043,12.2746 28.2174,15.8516 42.3734,10.8362 c41.92159,-16.3793 51.61678,-67.3469 52.89911,-111.1003 l3.68819,-2.1338 l-3.4807,-3.4122 c2.6751,-40.5983 -4.97189,-105.0606 32.09282,-123.0397 z};
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{scalerel}
\newcommand\fhole{\mbox{\scalerel*{\tikz{\path (0,0) pic [yscale=-1] {fhole};}}{f}\hspace{-0.135em}-}\hspace{0pt}hole}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
The violin \fhole.

\footnotesize The footnotesize violin \fhole.

\huge The huge violin \fhole.

xxxxxx xxxxxx The huge violin \fhole.
\end{document}

答案2

如果您不清楚确切的形状,您可以使用积分符号生成类似的形状:

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{newtxtext}
\usepackage{graphicx}

\usepackage{wasysym}
\newcommand\fhole{\rotatebox{-10}{\kern-0.2em$\varint$}\kern-0.2em-hole}


\begin{document}

The normalsize violin \fhole.

\footnotesize The footnotesize violin \fhole.

\huge The huge violin \fhole.

\end{document}

在此处输入图片描述

相关内容