更新

更新

我有以下图片:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{tkz-fct}
\usetikzlibrary{arrows, decorations.pathreplacing}

\tikzstyle{line}=[very thick, black]
\tikzstyle{point}=[thick,fill=gray,gray]

\begin{document}
\begin{preview}
\begin{tikzpicture}
       \tkzInit [xmin=0,xmax=21,ymin=0,ymax=7]
        \begin{scriptsize}
            \tkzGrid[color = gray!30!white]
            \tkzAxeXY
        \end{scriptsize}
        \draw[line] (1,4) -- (6,1);
        \draw[line] (2,1) -- (5,4);
        \draw[line] (3,1) -- (6,4);
        \draw[line] (4,1) -- (8,5);
        \draw[line] (3,4) -- (9,3);
        \draw[line] (7,2) -- (9,3);
        \draw[line] (6,7) -- (9,1);

        \draw[line] (11,1) -- (16,5);
        \draw[line] (13,2) -- (14,2);
        \draw[line] (14,1) -- (14,2);
        \draw[line] (14,3) -- (15,2);
        \draw[line] (15,4) -- (15,3);
        \draw[line] (13,4) -- (13,3);

        \draw[line] (17,3) -- (21,3);
        \draw[line] (19,1) -- (19,5);

        \draw[point] (1,4) circle (2pt);

\end{tikzpicture}
\end{preview}
\end{document}

看起来像这样:

在此处输入图片描述

我想在每条线的末端都画一个十字。我可以手动画,就像我在circle末端画的 (see (1|4)) 一样,但我想画一个十字。我该怎么做?

(我怎样才能使 tikz 风格point看起来像一个十字架?)

答案1

笔记:

  • 我已经用宏上的scriptsize选项替换了环境(甚至不存在)。font=\scriptsize\tkzAxeXY
  • 我使用过该standalone课程。

纯 TikZ你有几种可能性:

  1. cross out形状库中的 为shapes.misc您提供了删除节点的可能性。通常这用于在文本上可视化某些内容(像这样),但使用选项minimum heightminimum width加上零,inner sep我们得到了一个明确的十字。线宽设置(thick)也可以识别。

    point/.style={
        thick,
        draw=gray,
        cross out,
        inner sep=0pt,
        minimum width=4pt,
        minimum height=4pt,
    },
    

    point现在可以手动应用此节点:

    \node[point] at (1,4) {};
    

    或自动使用特殊样式to path(如下line):

    to path={% works only with "to" and not "--"
        -- (\tikztotarget) node[at start,point] {} node [at end,point] {} \tikztonodes
    }
    
  2. plot路径TikZ 提供了与之前完全一样的功能,但有很多额外的“标记”。其pline风格与之前的风格类似line。它还包含以下every plot选项:

    pline/.style={% plot line
        every plot/.style={
            mark=x,
            mark options={
                gray,
                thick,
            },
            mark size=4pt,
        },
        very thick,
        black,
    },
    

代碼(形狀)

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tkz-fct}
\usetikzlibrary{shapes.misc}

\tikzset{
    line/.style={
        very thick,
        black,
        to path={% works only with "to" and not "--"
            -- (\tikztotarget) node[at start,point] {} node [at end,point] {} \tikztonodes
        }
    },
    point/.style={
        thick,
        draw=gray,
        cross out,
        inner sep=0pt,
        minimum width=4pt,
        minimum height=4pt,
    },
}

\begin{document}
\begin{tikzpicture}
    \tkzInit [xmin=0,xmax=21,ymin=0,ymax=7]

    \tkzGrid[color = gray!30!white]
    \tkzAxeXY[font=\scriptsize]

    \draw[line] (1,4) -- (6,1);
    \draw[line] (2,1) to (5,4)
                (3,1) to (6,4)
                (4,1) to (8,5)
                (3,4) to (9,3)
                (7,2) to (9,3)
                (6,7) to (9,1);

    \draw[line] (11,1) to (16,5)
                (13,2) to (14,2)
                (14,1) to (14,2)
                (14,3) to (15,2)
                (15,4) to (15,3)
                (13,4) to (13,3);

    \draw[line] (17,3) to (21,3)
                (19,1) to (19,5);

    \path[every node/.style={point}]
         node at (1,4) {}
         node at (6,1) {};
\end{tikzpicture}
\end{document}

输出(形状)

在此处输入图片描述

代码(情节)

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

\usepackage{tkz-fct}

\tikzset{
    pline/.style={% plot line
        every plot/.style={
            mark=x,
            mark options={
                gray,
                thick,
            },
            mark size=4pt,
        },
        very thick,
        black,
    },
}

\begin{document}
\begin{tikzpicture}
    \tkzInit [xmin=0,xmax=21,ymin=0,ymax=7]
    \tkzGrid[color = gray!30!white]
    \tkzAxeXY[font=\scriptsize]
    \draw[pline] plot coordinates {(1,4) (6,1)}
                 plot coordinates {(2,1) (5,4)}
                 plot coordinates {(3,1) (6,4)}
                 plot coordinates {(4,1) (8,5)}
                 plot coordinates {(3,4) (9,3)}
                 plot coordinates {(7,2) (9,3)}
                 plot coordinates {(6,7) (9,1)};

    \draw[pline] plot coordinates {(11,1) (16,5)}
                 plot coordinates {(13,2) (14,2)}
                 plot coordinates {(14,1) (14,2)}
                 plot coordinates {(14,3) (15,2)}
                 plot coordinates {(15,4) (15,3)}
                 plot coordinates {(13,4) (13,3)};

    \draw[pline] plot coordinates {(17,3) (21,3)}
                 plot coordinates {(19,1) (19,5)};
\end{tikzpicture}
\end{document}

输出(图)

在此处输入图片描述

答案2

一个不同的想法,定义一个新的箭头形状,例如X(感谢 Qrrbrbirlbel 注意到这\pgarrowrightextend{0pt}是必要的):

\documentclass{article}
\usepackage{tikz}
\makeatletter
\pgfarrowsdeclare{X}{X}
{
  \pgfutil@tempdima=0.3pt%
  \advance\pgfutil@tempdima by.25\pgflinewidth%
  \pgfutil@tempdimb=5.5\pgfutil@tempdima\advance\pgfutil@tempdimb by.5\pgflinewidth%
  \pgfarrowsleftextend{+-\pgfutil@tempdimb}
  \pgfarrowsrightextend{0pt}
}
{
  \pgfutil@tempdima=0.3pt%
  \advance\pgfutil@tempdima by.25\pgflinewidth%
  \pgfsetdash{}{+0pt}
  \pgfsetroundcap
  \pgfsetmiterjoin
  \pgfpathmoveto{\pgfqpoint{-5.5\pgfutil@tempdima}{-6\pgfutil@tempdima}}
  \pgfpathlineto{\pgfqpoint{5.5\pgfutil@tempdima}{6\pgfutil@tempdima}}
  \pgfpathmoveto{\pgfqpoint{-5.5\pgfutil@tempdima}{6\pgfutil@tempdima}}
  \pgfpathlineto{\pgfqpoint{5.5\pgfutil@tempdima}{-6\pgfutil@tempdima}}
  \pgfusepathqstroke 
}
\makeatother

\begin{document}
\tikz{
 \draw[X-X] (0,0) -- (2,1);
 \draw[X-X] (0,2) -- (1,0);
}
\end{document}

结果

使用箭头形状而不是节点形状会使 X 根据所画线的斜率旋转。这可能是一个优点,也可能是一个问题,取决于你想要什么。

更新

一个更简单的解决方案,使用相同的想法,是组合两个现有的箭头,而不是定义一个新的。 以下代码将产生与上述代码完全相同的结果(笔记此代码已从第一个版本修改。现在它确保 X 位于指定的端点):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\pgfarrowsdeclarecombine[-12*(0.3pt+.25\pgflinewidth)-\pgflinewidth]
{X}{X}{angle 90 reversed}{angle 90 reversed}{angle 90}{angle 90}

\begin{document}
\tikz{
 \draw[X-X] (0,0) -- (2,1);
 \draw[X-X] (0,2) -- (1,0);
}
\end{document}

答案3

这只是 PSTricks 的另一个答案。

输入:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\addtopsstyle{gridstyle}{gridlabels=0}
\begin{document}
\begin{pspicture}[showgrid](4,3)
    \pstGeonode[
        PointName=none,
        PointSymbol={x,none,x},
        dotscale=2]
    (0,0){A}
    (1,3){B}
    (4,1){C}
    \psline(A)(B)(C)
\end{pspicture}
\end{document}

输出:

在此处输入图片描述

相关内容