Tikz - 两个箭头指向同一高度的节点

Tikz - 两个箭头指向同一高度的节点

所以我对 Tikz 还比较陌生,到目前为止我所做的大部分工作都是从一些论坛复制粘贴的。但现在我遇到了一个问题,我无法完全解决。

我在另外两个块之间有一个矩形,我希望从两个外部块到内部块的箭头处于同一级别,同时指向中间块的中间。这是我目前的尝试:

目前的尝试如下

以下是代码:

\tikzstyle{block} = [draw, rectangle,minimum width=3cm]
\tikzstyle{list}=[rectangle split,rectangle split parts=2,draw,minimum width=3cm]

\begin{tikzpicture}[auto, >=latex', font=\rmfamily]

\node [block] (methods) {Methods};
\node [list, below left= 0.5cm and 1cm of methods,align=left] (approx) {Approximation 
\nodepart{second} FORM \\ SORM \\ \ldots};
\node [list, below right= 0.5cm and 1cm of methods,align=left] (sim) {Simulation 
\nodepart{second} MCS \\ SuS \\ IS \\  \ldots};
\node[block, dashed, below= 2 of methods] (ls) {LS}; 

\draw [->] (methods) -| node {} (sim);
\draw [->] (methods) -| node {} (approx);
\draw [->, dashed] (approx) -- node {} (ls);
\draw [->, dashed] (sim) -- node {} (ls);
\end{tikzpicture}

答案1

首先,记住最好给出一个完整的平均能量损失避免成员自己添加您使用的所有包和库。

其次,不要使用tikzstylebut tikzset,因为前者现在已经被弃用了。你也应该使用最新的arrows.meta库而不是旧的库arrows。但无论如何。

这里你需要的是使用锚点。为了让两个箭头从相同的高度开始,你可以从([yshift=-12mm]approx.north east)右侧块的相同高度开始(参见下面的代码)。

两支箭从同一高度射出

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

\usetikzlibrary{automata,shapes,arrows,positioning}

\begin{document}



\tikzset{block/.style={draw, rectangle,minimum width=3cm},
        list/.style={rectangle split,rectangle split parts=2,draw,minimum width=3cm}}

\begin{tikzpicture}[auto, >=latex', font=\rmfamily]

    \node [block] (methods) {Methods};
    \node [list, below left= 0.5cm and 1cm of methods,align=left] (approx) {Approximation 
    \nodepart{second} FORM \\ SORM \\ \ldots};
    \node [list, below right= 0.5cm and 1cm of methods,align=left] (sim) {Simulation 
    \nodepart{second} MCS \\ SuS \\ IS \\  \ldots};
    \node[block, dashed, below= 2 of methods] (ls) {LS}; 
    
    \draw [->] (methods) -| node {} (sim);
    \draw [->] (methods) -| node {} (approx);
    \draw [->, dashed] ([yshift=-12mm]approx.north east) -- node {} (ls.west);
    \draw [->, dashed] ([yshift=-12mm]sim.north west) -- node {} (ls.east);
\end{tikzpicture}

\end{document}

答案2

这很容易做到,只需一个简单的命令tabular即可pstricks– 更具体地说,使用\psDefBoxNodes以下命令pst-node

    \documentclass{article}
    \usepackage{dashbox}
    \usepackage{pst-node}

    \begin{document}

    \begin{pspicture}
    \centering \setlength{\tabcolsep}{2em}
    \psset{arrows=->}
    \begin{tabular}{ccc}
     & \psDefBoxNodes{M}{\framebox{\quad Methods\quad}} \\[1cm]
    \psDefBoxNodes{A}{ \begin{tabular}[b]{|c|}
     \hline
     Approximation \\ \hline
     FORM \\
     SORM \\
     $ \dots $ \\ \hline
    \end{tabular}} &
    \psDefBoxNodes{LS}{\dashbox{\qquad LS\qquad}}
    & \psDefBoxNodes{S}{\begin{tabular}[b]{|c|}
     \hline
     \quad Simulation\quad \\ \hline
     SuS \\
     IS \\
     $ \dots $ \\ \hline
    \end{tabular}}
    %connections
    \ncangle[angleA=180, angleB=90]{M:Cl}{A:tC}\ncangle[angleB=90]{M:Cr}{S:tC}
    \psset{linestyle=dashed}
    \ncline{A:Cr}{LS:tl}\ncline{S:Cl}{LS:tr}
    \end{tabular}
    \end{pspicture}

    \end{document} 

在此处输入图片描述

答案3

虚线框的位置是否很重要?如果不重要,您可能会喜欢以下解决方案(这实际上是 @SebGlav 的精彩回答 (+1) 的小变体):

在此处输入图片描述

% TeX - pdfLaTeX
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata,
                positioning,
                shapes}

\begin{document}
    \begin{tikzpicture}[
            > = Latex,
node distance = 5mm and 10mm,
 block/.style = {draw, minimum width=3cm},
  list/.style = {rectangle split, rectangle split parts=2,
                 draw, minimum width=3cm, align=left}
                        ]
\node [block] (methods) {Methods};
\node [list, below left=of methods] (approx) 
        {Approximation
         \nodepart{second} FORM \\ SORM \\ \ldots};
\node [list, below right= of methods] (sim) 
        {Simulation
         \nodepart{second} MCS \\ SuS \\ IS \\  \ldots};
\node[block, dashed, right = of approx.two east] (ls) {LS};
%
\draw [->] (methods) -| (sim);
\draw [->] (methods) -| node {} (approx);
\draw [->, dashed] (approx.two east) --(ls);
\draw [->, dashed] (approx.two east -| sim.west) -- (ls);
    \end{tikzpicture}
\end{document} 

相关内容