Tikz:样式文件中带有和不带有箭头的边缘

Tikz:样式文件中带有和不带有箭头的边缘

我怎样才能编写样式文件以便可以组合箭头且无箭头边缘?

这是一个简单的例子。我想画一条从 O1 到 A1 的虚线,没有箭头。

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{shapes,decorations,arrows,calc,arrows.meta,fit,positioning}
\tikzset{
    -Latex,auto,node distance =1 cm and 1 cm,semithick,
    state/.style ={ellipse, draw, minimum width = 0.7 cm},
    point/.style = {circle, draw, inner sep=0.04cm,fill,node contents={}},
    bidirected/.style={Latex-Latex,dashed},
    connected/.style={dashed}, %how can I change this line to make connected without arrow?
    el/.style = {inner sep=2pt, align=left, sloped}
}


\begin{document}
\begin{tikzpicture}
\node [state](O1) at (0,0) {$O_1$};
\node[state](A1) at (2,0) {$A_1$};
\node[state](O2) at (4,0){$O_2$};
\path (O1) [connected] edge (A1);
\path (A1) edge (O2);
\end{tikzpicture}

\end{document}

答案1

问题的答案

如何才能从边缘移除箭头?

添加-到边缘/样式的选项。

因此我-connected样式中添加了一个以获得

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows.meta}
\tikzset{
    auto,node distance =1 cm and 1 cm,semithick,
    state/.style ={ellipse, draw, minimum width = 0.7 cm},
    bidirected/.style={Latex-Latex,dashed},
    connected/.style={dashed,-},% <- add a - to suppress the arrows
}
\begin{document}
\begin{tikzpicture}[auto,nodes={state},-Latex]
\path (0,0) node (O1)   {$O_1$}  
    ++ (2,0) node(A1) {$A_1$}++ (2,0) node(O2) {$O_2$}
    (O1) edge[connected]  (A1) (A1) edge (O2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我会按如下方式写出你的 MWE:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,
                shapes}
\tikzset{
     semithick,
                > = Latex,
     state/.style = {ellipse, draw, minimum width = 5mm},
bidirected/.style = {<->, dashed},  % not used in this MWE
 connected/.style = {dashed}, 
}


\begin{document}
    \begin{tikzpicture}
\node[state](O1) at (0,0) {$O_1$};
\node[state](A1) at (2,0) {$A_1$};
\node[state](O2) at (4,0){$O_2$};
\path   (O1) edge[connected] (A1)
      % (O1) edge[dashed] (A1)  % gives the same result as above line
                                % using it you not need style "connected"  
        (A1) edge[->] (O2);
    \end{tikzpicture}
\end{document}

注意:我删除了除之外的所有未使用的库和定义的样式bidirected

在此处输入图片描述

相关内容