我是 Ti 的新用户钾Z 有一个非常简单的问题,我在网上找不到答案。我正在连接线段tikzpicture
,但角点似乎丢失了,导致线条粗而出现缺口(放大时也是如此)。下面给出了一个非常短的代码段:
\begin{tikzpicture}[black,line width = 2pt,scale = 1.0]
\draw (0,0) -- (1,0);
\draw (1,0) -- (1,1);
\draw (1,1) -- (2,1);
\end{tikzpicture}
由于我需要绘制图形的方式,我无法将多个点连接成一个循环。所以我需要某种方式将点添加到“凹口”以产生尖角。在我看来,我应该能够添加小的矩形节点,但我不确定确切的语法,因此节点的大小与线条的宽度相同。感谢您的任何建议。
答案1
使用该line cap
选项指定行如何“结束”(p.167,pgfmanual,v3.01a)。
\documentclass[tikz,border=1mm]{standalone}
\begin{document}
\begin{tikzpicture}[line width=2pt]
\draw (0,0) -- (1,0);
\draw (1,0) -- (1,1);
\draw (1,1) -- (2,1);
\node[right] at (2,.5) {line cap=butt (default)};
\end{tikzpicture}
\begin{tikzpicture}[line width=2pt,line cap=rect]
\draw (0,0) -- (1,0);
\draw (1,0) -- (1,1);
\draw (1,1) -- (2,1);
\node[right] at (2,.5) {line cap=rect};
\end{tikzpicture}
\begin{tikzpicture}[line width=2pt,line cap=round]
\draw (0,0) -- (1,0);
\draw (1,0) -- (1,1);
\draw (1,1) -- (2,1);
\node[right] at (2,.5) {line cap=round};
\end{tikzpicture}
\end{document}
答案2
如果要获得正确的线连接,则需要一次性绘制轮廓。否则 Ti钾Z 知道应该连接这些线吗?但是,有时几乎不可避免地要用几个命令来绘制一个东西,例如当不同的延伸在宏中拼凑在一起时。然后可以作弊并添加一个适当的“箭头”。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[black,line width = 2pt,scale = 1.0]
\draw (0,0) -- (1,0);
\draw (1,0) -- (1,1);
\draw (1,1) -- (2,1);
\node at (1,1.5) {original};
\begin{scope}[xshift=2.5cm]
\draw (0,0) -- (1,0) -- (1,1) -- (2,1);
\node at (1,1.5) {one stretch};
\end{scope}
\begin{scope}[xshift=5cm,line join=round]
\draw (0,0) -- (1,0) -- (1,1) -- (2,1);
\node[align=center] at (1,1.5) {one stretch\\ \texttt{line join=round}};
\end{scope}
\begin{scope}[xshift=7.5cm]
\draw[{Round Cap[]}-{Round Cap[]},shorten >=-1pt,shorten <=-1pt] (0,0) -- (1,0);
\draw[{Round Cap[]}-{Round Cap[]},shorten >=-1pt,shorten <=-1pt] (1,0) -- (1,1);
\draw[{Round Cap[]}-{Round Cap[]},shorten >=-1pt,shorten <=-1pt] (1,1) -- (2,1);
\node at (1,1.5) {cheating};
\end{scope}
\end{tikzpicture}
\end{document}
更新:回复您下面的评论:对于您的多格骨牌,我建议将两端的线条长度增加一半,请参见右侧的“作弊”示例。
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[black,line width = 2pt,scale = 1.0]
\draw (0,0) -- (1,0);
\draw (1,0) -- (1,1);
\draw (1,1) -- (2,1);
\node at (1,1.5) {original};
\begin{scope}[xshift=2.5cm]
\draw (0,0) -- (1,0) -- (1,1) -- (2,1);
\node at (1,1.5) {one stretch};
\end{scope}
\begin{scope}[xshift=5cm]
\draw[shorten >=-1pt,shorten <=-1pt] (0,0) -- (1,0);
\draw[shorten >=-1pt,shorten <=-1pt] (1,0) -- (1,1);
\draw[shorten >=-1pt,shorten <=-1pt] (1,1) -- (2,1);
\node at (1,1.5) {cheating};
\end{scope}
\end{tikzpicture}
\end{document}