我已经在LaTeX中创建了此图像:
\usetikzlibrary{math}
\begin{tikzpicture}[scale=.7]
\tikzmath{ \w = 6; \h =4; \x = 2; }
\draw [fill=gray!30,thick] (-\w/2,-\h/2) rectangle (\w/2,\h/2);
\draw [->,thick] (\w/2, 0) -- (\w/2+\x,0);
\draw [->,thick] (-\w/2-\x, 0) -- (-\w/2,0);
\node [left] at (-\w/2-\x,0) {Input};
\node [right] at (\w/2+\x, 0) {Output};
\node [align=left,font=\ttfamily] at (0,0) {\small function(...) \{\\...\\\}};
\end{tikzpicture}
我要实现的目标如下:
如您所见,输入箭头必须指向文本function (...)
中括号内的内容。输出箭头必须从中间行的末尾开始。
一切都归结为在文本内部定义点或坐标。我如何告诉tikz在文本function (<HERE>)
内精确地创建坐标?
我希望能够在那些位置写点东西:
\node [align=left,font=\ttfamily] at (0,0) {\small function(<HERE>) \{\\...<HERE>\\\}};
如何?
答案 0 :(得分:1)
这正是tikzmark
软件包的用途:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{math}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{tikzpicture}[scale=.7,overlay, remember picture]
\tikzmath{ \w = 6; \h =4; \x = 2; }
\draw [fill=gray!30,thick] (-\w/2,-\h/2) rectangle (\w/2,\h/2);
\draw [->,thick] (\w/2, 0) -- (\w/2+\x,0);
\draw [->,thick] (-\w/2-\x, 0) -- (-\w/2,0);
\node [left] at (-\w/2-\x,0) {Input};
\node [right] at (\w/2+\x, 0) {Output};
\node [align=left,font=\ttfamily] at (0,0) {\small function(..\tikzmark{foo}.) \{\\...\\\}};
\draw[blue,-latex] (-3*\w/4,0) -| (-3*\w/4,0.3*\h) -| (pic cs:foo) ;
\end{tikzpicture}
\end{document}
编辑:
对我来说,该代码可使用以下软件包版本与texlive2019中的pdflatex一起正常工作:
*File List*
article.cls 2018/09/03 v1.4i Standard LaTeX document class
size10.clo 2018/09/03 v1.4i Standard LaTeX file (size option)
tikz.sty 2019/05/09 v3.1.3 (3.1.3)
pgf.sty 2019/05/09 v3.1.3 (3.1.3)
pgfrcs.sty 2019/05/09 v3.1.3 (3.1.3)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty 2019/05/09 v3.1.3 (3.1.3)
graphicx.sty 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
keyval.sty 2014/10/28 v1.15 key=value parser (DPC)
graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
trig.sty 2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg 2016/06/04 v1.11 sample graphics configuration
pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
pgfsys.sty 2019/05/09 v3.1.3 (3.1.3)
pgfsys.code.tex
pgfsyssoftpath.code.tex 2019/05/09 v3.1.3 (3.1.3)
pgfsysprotocol.code.tex 2019/05/09 v3.1.3 (3.1.3)
xcolor.sty 2016/05/11 v2.12 LaTeX color extensions (UK)
color.cfg 2016/01/02 v1.6 sample color configuration
pgfcore.code.tex
pgfcomp-version-0-65.sty 2019/05/09 v3.1.3 (3.1.3)
pgfcomp-version-1-18.sty 2019/05/09 v3.1.3 (3.1.3)
pgffor.sty 2019/05/09 v3.1.3 (3.1.3)
pgfkeys.sty
pgfkeys.code.tex
pgfmath.sty
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
expl3.sty 2019-05-09 L3 programming layer (loader)
expl3-code.tex 2019-05-09 L3 programming layer
l3pdfmode.def 2019-04-06 v L3 Experimental driver: PDF mode
l3keys2e.sty 2019-05-03 LaTeX2e option processing using LaTeX3 keys
xparse.sty 2019-05-03 L3 Experimental document command parser
supp-pdf.mkii
epstopdf-base.sty 2016/05/15 v2.6 Base part for package epstopdf
infwarerr.sty 2016/05/16 v1.4 Providing info/warning/error messages (HO)
grfext.sty 2016/05/16 v1.2 Manage graphics extensions (HO)
kvdefinekeys.sty 2016/05/16 v1.4 Define keys (HO)
ltxcmds.sty 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
kvoptions.sty 2016/05/16 v3.12 Key value format for package options (HO)
kvsetkeys.sty 2016/05/16 v1.17 Key value parser (HO)
etexcmds.sty 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty 2016/05/16 v1.4 Provides the ifluatex switch (HO)
pdftexcmds.sty 2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO)
ifpdf.sty 2018/09/07 v3.3 Provides the ifpdf switch
epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
***********