在 tikz 流程图中放置箭头

在 tikz 流程图中放置箭头

我正在尝试使用 tikz 绘制流程图。下面是我的尝试。我希望带有上标“a”的垂直箭头与带有上标“n”的水平箭头连接,并更靠近节点“步骤 3”的中间。你能告诉我该怎么做吗?

\documentclass[a4paper, 11pt]{article}
\usepackage[a4paper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}



\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{clrscode}
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{latexsym}
\usepackage{lmodern}
\usepackage{mathtools}
\usepackage{mdframed}
\usepackage{pgf}
\usepackage{tcolorbox}
\usepackage{tikz}
\usepackage{tikzpeople}
\usepackage[absolute,overlay]{textpos}
\usepackage{xcolor}



\usetikzlibrary{arrows}
\usetikzlibrary{positioning} 
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{shapes.geometric}

\tikzstyle{process} = [rectangle, minimum width=5cm, text width=5cm, minimum             height=1cm, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{name} = [rectangle, minimum width=5cm, text width=5cm, minimum     height=1cm, draw=black]

\DeclareGraphicsExtensions{.pdf,.png,.jpg, .tif}


\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
  \fancyfoot[LE,RO]{\thepage}
  \renewcommand{\familydefault}{\sfdefault}


\newcommand{\legendre}[2]{\genfrac{(}{)}{}{}{#1}{#2}}
\newcommand{\jacobi}[2]{\genfrac{(}{)}{}{}{#1}{#2}}
\newcommand{\congruent}[3]{$#1 \equiv #2 \text{ } \left( \text{mod } #3             \right)$}
\newcommand{\ZNZ}[1][n]{\mathbb{Z}/{#1}\mathbb{Z}}
\newcommand{\ZNZX}[1][n]{(\mathbb{Z}/{#1}\mathbb{Z})^\times}
\newcommand{\QR}[1][n]{\mathcal{QR}_{#1}}
\newcommand{\QNR}[1][n]{\mathcal{QNR}_{#1}}
\newcommand{\QNRP}{\mathcal{QNR}_n^{+1}}
\newcommand{\JNP}{\mathcal{J}_n^{+1}}
\newcommand{\JNM}{\mathcal{J}_n^{-1}}



\begin{document}
    \begin{tikzpicture}[node distance = 1cm]
        \node[name](alice){\textbf{Alice}};
        \node[process, below = of alice](step1){\textbf{Step 1:} Pick two     distinct large Blum primes $p$ and $q$ and set $n \coloneqq pq$.};


\end{tikzpicture}




\end{document}

答案1

根据我的回答 对于您之前的问题:只需将宏添加joinbox选项中。

\documentclass[a4paper, 11pt]{article}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
               chains,
               positioning}

\tikzset{
box/.style = {rectangle, draw,
              text width=5cm,
              minimum height=1cm},
arr/.style = {thick,-Stealth},
        }


\begin{document}
    \begin{tikzpicture}[
node distance = 1cm,
  start chain = going below
                        ]
    \begin{scope}[every node/.style = {box, on chain, join=by arr}] % <---
\node   (alice) {\textbf{Alice}};
\node   (step1) {\textbf{Step 1:} Pick two distinct large Blum primes 
                 $p$ and $q$ and set $n \coloneqq pq$.};
    \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

但是,你可以使用\draw命令单独绘制箭头:

\documentclass[a4paper, 11pt]{article}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
               chains,
               positioning}

\tikzset{
box/.style = {rectangle, draw,
              text width=5cm,
              minimum height=1cm},
arr/.style = {thick,-Stealth},
        }


\begin{document}
    \begin{tikzpicture}[
node distance = 1cm,
  start chain = going below
                        ]
    \begin{scope}[every node/.style = {box, on chain}] 
\node   (alice) {\textbf{Alice}};
\node   (step1) {\textbf{Step 1:} Pick two distinct large Blum primes 
                 $p$ and $q$ and set $n \coloneqq pq$.};
    \end{scope}
\draw[arr] (alice) -- (step1); % <---
\end{tikzpicture}
\end{document}

答案2

如果 中的所有节点都tikzpicture具有相同的样式,即使用相同的键,则无需为此定义样式。相反,只需说 即可nodes={<keys>}

\documentclass[a4paper, 11pt]{article}
\usepackage[a4paper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[node distance=1cm,
  nodes={rectangle,minimum width=5cm,text width=5cm,minimum height=1cm,draw=black}]
 \node(alice){\textbf{Alice}};
 \node[below=of alice](step1){\textbf{Step 1:} Pick two distinct large Blum
 primes $p$ and $q$ and set $n \coloneqq p\,q$.};
 \draw[thick,-stealth] (alice) -- (step1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容