TikZ 中 Asymptote 的点类似物

TikZ 中 Asymptote 的点类似物

我一直试图dot在 TikZ 中复制 Asymptote 的风格,其外径等于表示给定或当前笔的dotfactor * linewidth(p)位置,默认情况下是。pdotfactor6

这个例子有什么问题?它根本无法编译?

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\usepackage{float}
\usepackage{tikz}
\usepackage{pgfkeys}

\begin{document}

\tikzset{
    dot/.style={circle,fill,minimum size=6*\pgfkeysvalueof{/tikz/line width}}
}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2]
        \coordinate [dot,label=left:$A$] (A) at (1, 0);
        \coordinate [dot,label=below:$B$] (B) at (8, 3);
        \draw (A) -- (B);
    \end{tikzpicture}
\end{figure}

\end{document}

答案1

线宽存储在 中\pgflinewidth

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{float}
\usepackage{tikz}

\begin{document}

\tikzset{
    dot/.style={circle,fill,inner sep=6*\pgflinewidth/2}
}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2]
        \coordinate [dot,label=left:$A$] (A) at (1, 0);
        \coordinate [dot,label=below:$B$] (B) at (5, 2);
        \draw (A) -- (B);
        \draw[very thick] (1,-1) coordinate[dot,label=left:$A'$] (A')
        -- (5,1) coordinate[dot,label=below:$B'$] (B');
    \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

dotfactor将其添加到游戏中很容易。

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

\tikzset{
    dot/.style={circle,fill,minimum
    size=\pgfkeysvalueof{/tikz/dotfactor}*\pgflinewidth-\pgflinewidth,inner sep=0pt,outer sep=0pt,
    draw},
    dotfactor/.initial=6
}
\begin{document}
    \begin{tikzpicture}[scale=2]
        \coordinate [dot,label=left:$A$] (A) at (0, 0);
        \coordinate [dot,label=below:$B$] (B) at (4, 2);
        \draw (A) -- (B);
        \draw[very thick] (0,-1) coordinate[dot,label=left:$A'$] (A')
        -- (4,1) coordinate[dot,label=below:$B'$] (B');
        \draw[very thick,dotfactor=4] (0,-2) coordinate[dot,label=left:$A''$] (A'')
        -- (4,0) coordinate[dot,label=below:$B''$] (B'');
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑:在下面的答案中更改为minimum width。它还会绘制点(这就是为什么有-\pgflinewidth),以避免出现间隙。

相关内容