我想渲染一个类似于流程图的图表,但箭头从一个框中的符号指向另一个框中的符号(而不是从一个整个框指向另一个整个框的箭头)。我想更改代码以渲染下面的图像(请原谅它的丑陋):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{equation} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (get_c) [equation] {$C \leftarrow A + B$};
\node (get_d) [equation, below of=get_c] {$CX - Y \rightarrow D$};
\node (get_x) [equation, below of=get_d] {$X \leftarrow F + G$};
\draw [arrow] (get_c) -- (get_d);
\draw [arrow] (get_x) -- (get_d);
\end{tikzpicture}
\end{document}
使用上面的代码我得到的结果是:
答案1
您可以使用矩阵来访问方程中的表达式,并将一些表达式放置{}
在正确的位置,&
就像在具有相同用途的普通数组中一样。calc
可用于相对对齐。我不知道您是否希望所有节点都终止于相同的水平位置,所以我添加了两个选项。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{calc,fit,matrix,positioning}
\begin{document}
\begin{tikzpicture}[node distance=2cm,
equation/.style={rectangle, rounded corners, minimum width=3.5cm, minimum
height=1cm,text centered, draw=black},
marrow/.style={thick,-stealth},
tmat/.style={matrix of math nodes,column sep=0pt,anchor=west,
nodes={minimum width=0pt,minimum height=0pt,anchor=center,inner xsep=0pt}}]
\node [tmat] (get_c) {C&{}\leftarrow A + B\\};
\node (get_d) [below=of get_c.west,tmat] {C&X&{} - Y \rightarrow D\\};
\path let \p1=($(get_d-1-2.west)-(get_d-1-1.west)$) in
node (get_x) [below=of get_d.west,tmat,xshift=\x1]
{X&{} \leftarrow F + G\\};
\draw[marrow] (get_c-1-1) -- (get_d-1-1);
\draw[marrow] (get_x-1-1) -- (get_d-1-2);
\path foreach \X in {c,d,x} {node[fit=(get_\X),equation]{}};
\begin{scope}[xshift=6cm]
\node [tmat] (get_c) {C&{}\leftarrow A + B\\};
\node (get_d) [below=of get_c.west,tmat] {C&X&{} - Y \rightarrow D\\};
\path let \p1=($(get_d-1-2.west)-(get_d-1-1.west)$) in
node (get_x) [below=of get_d.west,tmat,xshift=\x1]
{X&{} \leftarrow F + G\\};
\draw[marrow] (get_c-1-1) -- (get_d-1-1);
\draw[marrow] (get_x-1-1) -- (get_d-1-2);
\path node[fit=(get_c)(get_d)(get_x)](F){}
foreach \X in {c,d,x} {node[fit=(get_\X-|F.west)(get_\X-|F.east),equation]{}};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
对于复杂的事情你可以使用Tikz 包 另外,我强烈建议使用以下编辑器马查创建复杂的图像、表格、脚本、 3D 图像等。
因此,需要采取以下步骤:
- 免费打开编辑器。
- 按照下面的示例图创建所需的模型
- 导出到 LaTeX
将所需的包添加到您的文档中
\usepackage{physics} \usepackage{amsmath} \usepackage{tikz} \usepackage{mathdots} \usepackage{yhmath} \usepackage{cancel} \usepackage{color} \usepackage{siunitx} \usepackage{array} \usepackage{multirow} \usepackage{amssymb} \usepackage{gensymb} \usepackage{tabularx} \usepackage{booktabs} \usetikzlibrary{fadings} \usetikzlibrary{patterns} \usetikzlibrary{shadows.blur} \usetikzlibrary{shapes}
\begin{document}
在和之间添加内容脚本\end{document}
完整代码示例:
\documentclass[12pt, letterpaper]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{physics}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{mathdots}
\usepackage{yhmath}
\usepackage{cancel}
\usepackage{color}
\usepackage{siunitx}
\usepackage{array}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{gensymb}
\usepackage{tabularx}
\usepackage{booktabs}
\usetikzlibrary{fadings}
\usetikzlibrary{patterns}
\usetikzlibrary{shadows.blur}
\usetikzlibrary{shapes}
\title{Title1}
\author{Author1}
\date{May 2020}
\begin{document}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300
%Straight Lines [id:da4873436163497318]
\draw (169,102) -- (169,160) ;
\draw [shift={(169,162)}, rotate = 270] [color={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.75] (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29) ;
%Straight Lines [id:da7827018032544013]
\draw (282,103) -- (282,161) ;
\draw [shift={(282,163)}, rotate = 270] [color={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.75] (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29) ;
% Text Node
\draw (57,46.4) node [anchor=north west][inner sep=0.75pt] {$\frac{a}{b} +\sqrt[3]{a+b} +\int ^{a}_{b} dx+\overbrace{a-b}^{n+1} +\wideparen{ABC} +\widehat{ABC} +\Uparrow H_{2} 0\Uparrow $};
% Text Node
\draw (117,170.4) node [anchor=north west][inner sep=0.75pt] {$\frac{a}{b} +\sqrt[3]{a+b} +\int ^{a}_{b} dx+\overbrace{a-b}^{n+1} +\wideparen{ABC}$};
\end{tikzpicture}
\end{document}