如何在 Tikz 绘图节点中添加文本字段?

如何在 Tikz 绘图节点中添加文本字段?

给出以下TextField命令:

\newcommand{\TF}[2][15em]{\TextField[borderwidth=0.1pt,
                                 width=#1,
                                 height=1.25em,
                                 charsize=10pt,
                                 backgroundcolor=blue!  
                                 50!gray!20,
                                 color=blue!44!                                         
                                 black,
                                 bordercolor=red!20,
                                 name=#2
                                ]{}}

我想将它嵌入下Tikz图中的红色和蓝色矩形中:

\documentclass{article}
\usepackage{tikz, tikz-3dplot}
\usetikzlibrary{calc} 
\usepackage{fouriernc}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\pgfmathsetmacro{\b}{0.1}
\pgfmathsetmacro{\c}{1-\b}
\newcommand{\pentagon}[6]{
\filldraw[fill=gray,draw=black] 
($\c*(#1)+\b*(#2)$)--
($\c*(#1)+\b*(#3)$)--
($\c*(#1)+\b*(#4)$)--
($\c*(#1)+\b*(#5)$)--
($\c*(#1)+\b*(#6)$)--cycle;
}
\newcommand{\hexagon}[4]{
\draw[#4]
($\c*(#1)+\b*(#2)$)--
($\b*(#1)+\c*(#2)$)--
($\c*(#2)+\b*(#3)$)--
($\b*(#2)+\c*(#3)$)--
($\c*(#3)+\b*(#1)$)--
($\b*(#3)+\c*(#1)$)--cycle;
}
\begin{document}
\tdplotsetmaincoords{65}{100}
\begin{tikzpicture}[tdplot_main_coords,scale=1,line join=round, overlay]
\pgfmathsetmacro\a{1}
\pgfmathsetmacro{\phi}{\a*(1+sqrt(5))/2}
\path 
coordinate(A) at (0+4,\phi+2,\a)
coordinate(B) at (0+4,\phi+2,-\a)
coordinate(C) at (0+4,-\phi+2,\a)
coordinate(D) at (0+4,-\phi+2,-\a)
coordinate(E) at (\a+4,0+2,\phi)
coordinate(F) at (\a+4,0+2,-\phi)
coordinate(G) at (-\a+4,0+2,\phi)
coordinate(H) at (-\a+4,0+2,-\phi)
coordinate(I) at (\phi+4,\a+2,0)
coordinate(J) at (\phi+4,-\a+2,0)
coordinate(K) at (-\phi+4,\a+2,0)
coordinate(L) at (-\phi+4,-\a+2,0);
coordinate(TF) at (-\phi+4,\a+2,0);
%MORE POINTS
\draw[red,ultra thick,rounded corners] (2.1,0.1) rectangle (4,3.46);
\draw[blue,ultra thick,rounded corners] (4.2,3) rectangle (7,1.65);
%G-CEAKL "TOP" 
\hexagon{G}{C}{E}{draw opacity = 0.2}
\hexagon{G}{E}{A}{draw opacity = 0.2}
\hexagon{G}{A}{K}{draw opacity = 0.2}
\hexagon{G}{K}{L}{draw opacity = 0.2}
\hexagon{G}{L}{C}{draw opacity = 0.2}
%F-IJDHB "BOTTOM"
\hexagon{F}{I}{J}{draw opacity = 0.2}
\hexagon{F}{J}{D}{draw opacity = 0.2}
\hexagon{F}{D}{H}{draw opacity = 0.2}
\hexagon{F}{H}{B}{draw opacity = 0.2}
\hexagon{F}{B}{I}{draw opacity = 0.2}
%CJEIABKHLD "STRIP"
\hexagon{C}{J}{E}{draw opacity = 0.2}
\hexagon{J}{E}{I}{draw opacity = 0.2}
\hexagon{E}{I}{A}{draw opacity = 0.2}
\hexagon{I}{A}{B}{draw opacity = 0.2}
\hexagon{A}{B}{K}{draw opacity = 0.2}
\hexagon{B}{K}{H}{draw opacity = 0.2}
\hexagon{K}{H}{L}{draw opacity = 0.2}
\hexagon{H}{L}{D}{draw opacity = 0.2}
\hexagon{L}{D}{C}{draw opacity = 0.2}
\hexagon{D}{C}{J}{draw opacity = 0.2}
)
\end{tikzpicture} 
\end{document}

当然,矩形的颜色对于最终结果并不重要。

PS 我不知道如何编译这里给出的示例,请告诉我如何做

答案1

\TF[width]{name}只需在需要的地方使用文本框即可。

\documentclass{article}
\usepackage{tikz, tikz-3dplot}
\usetikzlibrary{calc} 
\usepackage{fouriernc}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}

\usepackage{hyperref}

\newcommand{\TF}[2][15em]{\TextField[borderwidth=0.1pt,
                                     width=#1,
                                     height=2em,
                                     charsize=10pt,
                                     backgroundcolor=blue!50!gray!20,
                                     color=blue!33!black,
                                     bordercolor=red!20,
                                     name=#2
                                    ]{}}



\pgfmathsetmacro{\b}{0.1}
\pgfmathsetmacro{\c}{1-\b}
\newcommand{\pentagon}[6]{
\filldraw[fill=gray,draw=black] 
($\c*(#1)+\b*(#2)$)--
($\c*(#1)+\b*(#3)$)--
($\c*(#1)+\b*(#4)$)--
($\c*(#1)+\b*(#5)$)--
($\c*(#1)+\b*(#6)$)--cycle;
}
\newcommand{\hexagon}[4]{
\draw[#4]
($\c*(#1)+\b*(#2)$)--
($\b*(#1)+\c*(#2)$)--
($\c*(#2)+\b*(#3)$)--
($\b*(#2)+\c*(#3)$)--
($\c*(#3)+\b*(#1)$)--
($\b*(#3)+\c*(#1)$)--cycle;
}
\begin{document}
\tdplotsetmaincoords{65}{100}
\begin{tikzpicture}[tdplot_main_coords,scale=1,line join=round, overlay]
\pgfmathsetmacro\a{1}
\pgfmathsetmacro{\phi}{\a*(1+sqrt(5))/2}
\path 
coordinate(A) at (0+4,\phi+2,\a)
coordinate(B) at (0+4,\phi+2,-\a)
coordinate(C) at (0+4,-\phi+2,\a)
coordinate(D) at (0+4,-\phi+2,-\a)
coordinate(E) at (\a+4,0+2,\phi)
coordinate(F) at (\a+4,0+2,-\phi)
coordinate(G) at (-\a+4,0+2,\phi)
coordinate(H) at (-\a+4,0+2,-\phi)
coordinate(I) at (\phi+4,\a+2,0)
coordinate(J) at (\phi+4,-\a+2,0)
coordinate(K) at (-\phi+4,\a+2,0)
coordinate(L) at (-\phi+4,-\a+2,0);
coordinate(TF) at (-\phi+4,\a+2,0);
%MORE POINTS
% \draw[red,ultra thick,rounded corners] (2.1,0.1) rectangle (4,3.46); 
% \draw[blue,ultra thick,rounded corners] (4.2,3) rectangle (7,1.65);%
%TEXT BOXES
\coordinate (M) at ($(E)!0.5!(H)$);
\node[above] at (M) {\TF[8em]{top}};%
\node[below] at (M) {\TF[5em]{bot}};
%G-CEAKL "TOP" 
\hexagon{G}{C}{E}{draw opacity = 0.2}
\hexagon{G}{E}{A}{draw opacity = 0.2}
\hexagon{G}{A}{K}{draw opacity = 0.2}
\hexagon{G}{K}{L}{draw opacity = 0.2}
\hexagon{G}{L}{C}{draw opacity = 0.2}
%F-IJDHB "BOTTOM"
\hexagon{F}{I}{J}{draw opacity = 0.2}
\hexagon{F}{J}{D}{draw opacity = 0.2}
\hexagon{F}{D}{H}{draw opacity = 0.2}
\hexagon{F}{H}{B}{draw opacity = 0.2}
\hexagon{F}{B}{I}{draw opacity = 0.2}
%CJEIABKHLD "STRIP"
\hexagon{C}{J}{E}{draw opacity = 0.2}
\hexagon{J}{E}{I}{draw opacity = 0.2}
\hexagon{E}{I}{A}{draw opacity = 0.2}
\hexagon{I}{A}{B}{draw opacity = 0.2}
\hexagon{A}{B}{K}{draw opacity = 0.2}
\hexagon{B}{K}{H}{draw opacity = 0.2}
\hexagon{K}{H}{L}{draw opacity = 0.2}
\hexagon{H}{L}{D}{draw opacity = 0.2}
\hexagon{L}{D}{C}{draw opacity = 0.2}
\hexagon{D}{C}{J}{draw opacity = 0.2}
)
\end{tikzpicture} 
\end{document}

得到如下结果:

编译后的图像

PS Overleaf 是一个不错的起点。

相关内容