TikZ绘制带圆角路径时起始处出现多余线条如何解决
解决TikZ带圆角路径起始处的多余线条问题
问题根源是第一个线段的长度小于设置的圆角半径:你设置的圆角半径是5mm(约0.5cm),但(9,2)到(9.2,1.7)的直线距离仅约0.36cm,TikZ处理这种短线段的圆角时会生成异常线条。
给出三种可行解决方法:
- 调整第一个线段的长度,使其大于等于圆角半径,保证圆角正常渲染:
\documentclass{beamer} \usepackage{tikz} \usetikzlibrary{arrows} \tikzset{>=latex} \begin{document} \begin{frame} \begin{tikzpicture} \draw[->, rounded corners = 5mm] (9,2) -- (9.5,1.5) -- (1.7,1.7) -- (1, 1); \end{tikzpicture} \end{frame} \end{document}
- 保留原坐标,对第一个转折处禁用圆角,通过局部选项
[sharp corners]实现:
\documentclass{beamer} \usepackage{tikz} \usetikzlibrary{arrows} \tikzset{>=latex} \begin{document} \begin{frame} \begin{tikzpicture} \draw[->, rounded corners = 5mm] (9,2) -- [sharp corners] (9.2,1.7) -- (1.7,1.7) -- (1, 1); \end{tikzpicture} \end{frame} \end{document}
- 减小圆角半径,使其小于第一个线段的长度,比如改为2mm:
\documentclass{beamer} \usepackage{tikz} \usetikzlibrary{arrows} \tikzset{>=latex} \begin{document} \begin{frame} \begin{tikzpicture} \draw[->, rounded corners = 2mm] (9,2) -- (9.2,1.7) -- (1.7,1.7) -- (1, 1); \end{tikzpicture} \end{frame} \end{document}
内容的提问来源于stack exchange,提问作者user13317
相关产品推荐
相关产品推荐

