Tikz,箭头格式

Tikz,箭头格式

考虑下面的图片: 在此处输入图片描述

以及底部的代码。我对左边的结果很满意;现在我已经开始使用二合字母,我需要箭头;我正在尝试获得对我来说最好的风格。我想实现以下目标:

  1. 箭头与子弹应有 1pt 的间距,但箭头尾部不应有间隙,当然正常边缘也不应有间隙
  2. [完成] 头部应该像下面这个样子(而不是像我尝试的那样是三角形): pgfplots:自定义轴箭头
  3. [完成] 并且标准头部不应该出现
  4. 由于我用python生成了图片,箭头的格式应该封装在样式中,正如我对具有样式的节点所做的那样bullet,请参阅我的尝试myarrow

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{subcaption}

\begin{document}

\begin{figure}[hbt]
\begin{subfigure}[b]{0.49000\textwidth}
\centering
\begin{tikzpicture}[bullet/.style={circle, fill,minimum size=4pt,inner sep=0pt, outer sep=0pt}]\useasboundingbox (-2,-2)rectangle(2,2);\node[bullet] at (2.00000,0.00000) (0) {};
\node[bullet] at (1.00000,1.73205) (1) {};
\node[bullet] at (-1.00000,1.73205) (2) {};
\node[bullet] at (-2.00000,0.00000) (3) {};
\node[bullet] at (-1.00000,-1.73205) (4) {};
\node[bullet] at (1.00000,-1.73205) (5) {};
\draw (0) -- (1); \draw (1) -- (2); \draw (2) -- (3); \draw (3) -- (4); \draw (4) -- (5); \draw (5) -- (0); \end{tikzpicture}\caption{}
\end{subfigure}
\begin{subfigure}[b]{0.49000\textwidth}
\centering
\begin{tikzpicture}
[bullet/.style={circle, fill,minimum size=4pt,inner sep=0pt, outer sep=0pt}]
[myarrow/.style={-{Stealth[length=2mm, width=2mm]}}]
\useasboundingbox (-2,-2)rectangle(2,2);\node[bullet] at (2.00000,0.00000) (0) {};
\node[bullet] at (1.00000,1.73205) (1) {};
\node[bullet] at (-1.00000,1.73205) (2) {};
\node[bullet] at (-2.00000,0.00000) (3) {};
\node[bullet] at (-1.00000,-1.73205) (4) {};
\node[bullet] at (1.00000,-1.73205) (5) {};
\draw (0) -- (1); \draw (1) -- (2); \draw (2) -- (3); \draw (3) -- (4); \draw[myarrow] (4) -- (5); \draw[-{Stealth[length=2mm, width=2mm]}] (5) -- (0); \end{tikzpicture}\caption{}
\end{subfigure}
\caption{}
\end{figure}

\end{document}

答案1

您应该myarrow/.style在第一个方括号内包含以定义样式。在样式中,您可以使用选项指定箭头尖端与节点的距离,sep=1pt如下例所示。

如果myarrow要在多个环境中使用该样式tikzpicture,则可以在序言中定义该样式,而\tikzset{myarrow/.style={...}}不是在每个单独的环境的可选参数中定义它。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{subcaption}

 % Definition of myarrow style to be used in multiple tikzpictures
 % \tikzset{myarrow/.style={-{Stealth[length=2mm, width=2mm, sep=1pt]}}} 

\begin{document}

\begin{figure}[hbt]
\begin{subfigure}[b]{0.49000\textwidth}
\centering
\begin{tikzpicture}[bullet/.style={circle, fill,minimum size=4pt,inner sep=0pt, outer sep=0pt}]\useasboundingbox (-2,-2)rectangle(2,2);\node[bullet] at (2.00000,0.00000) (0) {};
\node[bullet] at (1.00000,1.73205) (1) {};
\node[bullet] at (-1.00000,1.73205) (2) {};
\node[bullet] at (-2.00000,0.00000) (3) {};
\node[bullet] at (-1.00000,-1.73205) (4) {};
\node[bullet] at (1.00000,-1.73205) (5) {};
\draw (0) -- (1); \draw (1) -- (2); \draw (2) -- (3); \draw (3) -- (4); \draw (4) -- (5); \draw (5) -- (0); \end{tikzpicture}\caption{}
\end{subfigure}
\begin{subfigure}[b]{0.49000\textwidth}
\centering
\begin{tikzpicture}
[bullet/.style={circle, fill,minimum size=4pt,inner sep=0pt, outer sep=0pt},
 myarrow/.style={-{Stealth[length=2mm, width=2mm, sep=1pt]}}]
\useasboundingbox (-2,-2)rectangle(2,2);\node[bullet] at (2.00000,0.00000) (0) {};
\node[bullet] at (1.00000,1.73205) (1) {};
\node[bullet] at (-1.00000,1.73205) (2) {};
\node[bullet] at (-2.00000,0.00000) (3) {};
\node[bullet] at (-1.00000,-1.73205) (4) {};
\node[bullet] at (1.00000,-1.73205) (5) {};
\draw (0) -- (1); \draw (1) -- (2); \draw (2) -- (3); \draw (3) -- (4); \draw[myarrow] (4) -- (5); \draw[myarrow] (5) -- (0); \end{tikzpicture}\caption{}
\end{subfigure}
\caption{}
\end{figure}

\end{document}

结果输出

答案2

用于regular polygon确定项目符号的坐标(dot在下面的 MWE 中命名)和用于在子图 b 中绘制线条的循环。箭头和节点形状的样式对于两张图片都是通用的。箭头定义为

arr/.style = {-{Stealth[length=2mm, width=2mm]},shorten >=1pt},

梅威瑟:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                shapes.geometric}
\usepackage{subcaption}


\begin{document}

\begin{figure}[hbt]
\tikzset{
    dot/.style = {circle, fill, inner sep=2pt},
    arr/.style = {-{Stealth[length=2mm, width=2mm]},shorten >=1pt},
    HEX/.style = {regular polygon, regular polygon sides=6,
                  minimum size=33mm, rotate=-60,
                  node contents={}}
        }
\begin{subfigure}[b]{0.49\textwidth}
\centering
    \begin{tikzpicture}
\node (n0) [HEX,draw];
\foreach \i in {1,...,6}
\node[dot] at (n0.corner \i) {};
    \end{tikzpicture}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.49\textwidth}
\centering
\begin{tikzpicture}
\node (n0) [HEX];
\foreach \i in {1,...,6}
\node (n\i) [dot] at (n0.corner \i) {};
\foreach \i [count=\j from 2] in {1,...,4}
    \draw (n0.corner \i) -- (n0.corner \j);
\draw[arr] (n5) -- (n6);
\draw[arr] (n6) -- (n1);
    \end{tikzpicture}
\caption{}
\end{subfigure}
    \caption{}
\end{figure}

\end{document}

在此处输入图片描述

答案3

您可以使用缩短 > 作为选项或样式。 在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \i in {0,...,5}
\fill (60*\i:2) circle(2pt) coordinate (A\i); 

\draw (A0)--(A1)--(A2)--(A3)--(A4);
\draw[-stealth, shorten >=3pt] (A4)--(A5);
\draw[-stealth, shorten >=3pt] (A5)--(A0);
\end{tikzpicture}

\begin{tikzpicture}[myarr/.style={-stealth, shorten >=3pt}]
\foreach \i in {0,...,5}
\fill (60*\i:2) circle(2pt) coordinate (A\i); 

\draw (A0)--(A1)--(A2)--(A3)--(A4);
\draw[myarr] (A4)--(A5);
\draw[myarr] (A5)--(A0);
\end{tikzpicture}
\end{document}

相关内容