如何在 tikz 中创建数字二

如何在 tikz 中创建数字二

我正在尝试使用 tikz 创建数字二。下面的代码很接近,尽管左下角有一个奇怪的间隙。

在此处输入图片描述

\documentclass[tikz,border=3mm]{standalone}
    
\begin{document} 
\begin{tikzpicture} 
\draw [white] (0,-0.5) -- (0,0.5) -- (0.6,0.5); 
\draw[ultra thick]    (0,0.25) to[out=45,in=45,looseness=2.5]  (0,-0.45);   
\draw[ultra thick](0,-0.45) -- (0.5,-0.45);    
\path (0.7,0); 
\end{tikzpicture} 
\end{document}

关于如何让它看起来更像这样的任何建议:

在此处输入图片描述

谢谢。

答案1

将两条draw[ultra thick]线放入一个语句中会产生更像您所追求的结果:

\documentclass[tikz,border=3mm]{standalone}

\begin{document}
\begin{tikzpicture}
\draw [white] (0,-0.5) -- (0,0.5) -- (0.6,0.5);
\draw[ultra thick]    (0,0.25) to[out=45,in=45,looseness=2.5]  (0,-0.45) -- (0.5,-0.45);
\path (0.7,0);
\end{tikzpicture}
\end{document}

不过,它的底部有一个相当尖锐的角,这可能不是你想要的。

你看起来有间隙的原因在于你绘制的路径的末端。我可能在细节上有点错误,但这里的原理基本上是正确的。路径以一个正方形(本质上是笔形)结束,该正方形以提供的坐标为中心,并旋转到行进方向。两个正方形的末端没有旋转到相同的方向,因此重叠并不完美,留下了你看到的间隙。

对于我提供的版本,它是一条路径(而不是两条,而您的版本是两条),因此末端没有“重叠间隙”。 tikz 中可能存在用于更改末端的设置,您可以尝试使用这些设置来获得更符合您喜好的效果。 您还可以将“笔类型”更改为除正方形以外的其他类型(圆形效果很好)。 这可以通过 来完成draw[line cap=round],因此:

\documentclass[tikz,border=3mm]{standalone}
    
\begin{document} 
\begin{tikzpicture} 
\draw [white] (0,-0.5) -- (0,0.5) -- (0.6,0.5); 
\draw[ultra thick, line cap=round]    (0,0.25) to[out=45,in=45,looseness=2.5]  (0,-0.45);   
\draw[ultra thick, line cap=round](0,-0.45) -- (0.5,-0.45);    
\path (0.7,0); 
\end{tikzpicture} 
\end{document}

可能会产生更像您所追求的东西。

相关内容