避免粗虛線中的「裁剪」點

避免粗虛線中的「裁剪」點

繪製粗虛線時如何避免「裁剪」點?微量元素:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{figure}
    \begin{tikzpicture}
        \draw[thick,dotted] (0,0) -- (1,0);
    \end{tikzpicture}
\end{figure}

\end{document}

結果不太美觀:

在此輸入影像描述

答案1

dash expand off選項可能對您有用。

來自 TikZ 和 PGF手動的

/tikz/dash expand off

使off虛線圖案的一部分可擴展,以便拉伸。僅當存在單一on欄位off並且需要decorations庫時,這才有效。現在,必須在破折號圖案選項之後在應該生效的路徑上指定此選項,因為必須dash pattern在套用它的點知道該選項。

在此輸入影像描述

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations}
    
\begin{document}

\begin{tikzpicture}
  \draw [dotted,dash expand off] (0,0.1) -- (1.02,0.1);
  \draw [dotted,dash expand off] (0,0) -- (1,0);
\end{tikzpicture}

\end{document}

答案2

您可以根據線條的長度使用自訂虛線圖案。這是一個沒有自動計算的簡單範例:

客製化虛線圖案

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{figure}
    \begin{tikzpicture}
        \draw[line width=0.5mm,dash pattern={on 0.5mm off 0.5mm}] (0,0) -- (1,0);
    \end{tikzpicture}
\end{figure}

\end{document}

相關內容