我有兴趣创建一个符号大小的 tikz 绘图,其中有一个矩形,其宽度为符号的一半(高度为符号的一半),并且有一个箭头从矩形的中间右侧伸出,指向右侧(箭头应该相当小)。我尝试在这里做类似的事情(A 符号用于大小比较),但效果不太好:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 0mm,
box/.style = {% definition of rectangle as node
draw, line width=0.35mm,
text width=11pt, minimum height=11pt, align=left,
inner sep=1mm, outer sep=0pt}
]
\node (box1) [label=above:{}] {};
\node (B) [draw, right=of box1] {};
\draw [->] (box1) -- (B);
\end{tikzpicture}
A
\end{document}
如何使正方形的宽度变为其大小的一半?
如何让箭头离开矩形的右侧?
如何在矩形右侧创建一个“空”节点,以便我可以向其绘制箭头?
如何使箭头变小?
答案1
或许就像这样...
\documentclass[varwidth,border=5]{standalone}
\usepackage{tikz}
\def\abx{\tikz[x=0.75em,y=0.75em,baseline=0]\fill[even odd rule]
(0,0)--(.5,0)--(.5,.45)--(.75,.45)--(.75,.25)--(1,.5)--(.75,.75)--
(.75,.55)--(.5,.55)--(.5,1)--(0,1)--cycle(.1,.1)rectangle(.4,.9);}
\hbadness=10000
\begin{document}
\foreach \f in {\scriptsize,\footnotesize,\small,\normalsize,\large,\huge}{%
\noindent\hbox to1.125in{\texttt{\expandafter\string\f:}}
\f xX \abx\ yY \\[.5ex]}
\end{document}
答案2
我不完全理解你的问题,你指的是什么符号?我在这里回答了你的问题,如果尺寸不适合你的需要,只需缩放或重新调整对象的大小:
\draw (0,0) rectangle (1,2);
\draw [->] (1,1)--+(1,0);
- 空节点是不好的做法,而是使用
\coordinate (name) at (1,1);
它会导致\draw [->] (name)--+(1,0);
- 使用库
arrows.meta
(看看这个关联)你可以用这种方式缩放箭头的大小\draw [-{>[scale=0.7]}] (name)--+(1,0);
定义一个pic
可以让你放置预定义形状(如“邮票”)的 可能会很有用。我定义了一个名为 的图片mybox
:
\documentclass[tikz,convert]{standalone}
\usetikzlibrary{arrows.meta}
\tikzset{mybox/.pic={
\draw (-0.5,-1) rectangle (.5,1);
\draw [-{>[scale=0.5]}] (0.5,0)--+(0.5,0);
}
}
\begin{document}
\begin{tikzpicture}[>=Stealth]
\pic at (0,0) {mybox};
\draw (1,1) arc (135:45:3) pic [red,pos=0.3,scale=0.5,sloped] {mybox};
\end{tikzpicture}
\end{document}
答案3
我不确定你为什么希望使用 TikZ。但是,既然你这样做了,这里有一种方法可以解决它:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\newcounter{mybox}
\newlength\myboxminheight
\settoheight\myboxminheight{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
\tikzset{%
pics/my box/.style={%
code={%
\stepcounter{mybox}%
\tikzset{%
>/.tip={Triangle[length=2.5pt,width=2.5pt]},
outer sep=0pt,
every node/.append style={draw},
make my box/.cd,
#1,
/tikz/.cd,
make my box/my box look,
}
\node (box\themybox) [make my box/my box look, label=above:{\myboxlabel}, inner sep=\myboxisep, minimum height=\myboxminht-\myboxlinewidth, minimum width=.5*\myboxminht-.5*\myboxlinewidth] at (0,0) {};
\draw [->, make my box/my box look, line width=\myboxlinewidth,] (box\themybox.east) -- +(\myboxextarrow,0);
}
},
make my box/.search also={/tikz},
make my box/.cd,
line width/.store in=\myboxlinewidth,
minimum height/.store in=\myboxminht,
inner sep/.store in=\myboxisep,
label/.store in=\myboxlabel,
extend arrow/.store in=\myboxextarrow,
look/.code={\tikzset{make my box/my box look/.append style={#1}}},
line width=.35mm,
minimum height=\myboxminheight,
inner sep=0pt,
label={},
extend arrow=5pt,
my box look/.style={draw, line width=\myboxlinewidth},
}
\newcommand\mybox[1][]{%
\tikz{\pic {my box={#1}};}}
\begin{document}
X \mybox{} \mybox[label={My Box}] \mybox[look={text=red, draw=blue}, extend arrow=25pt, minimum height=20pt, inner sep=2mm, line width=2.5pt, label={My Other Box}, >/.tip={Stealth[]}]
\end{document}
请注意,字形框可能包含绘制字母上方的空间,并且并非所有大写字母近距离看起来都高度相同。因此,您需要根据您的偏好、字体配置和需求进行调整。
答案4
这是一个解决方案pstricks
:
\documentclass{article}
\usepackage{pst-node}
\usepackage{auto-pst-pdf} \newcommand\mysymbol{\begin{pspicture}%
\fnode[linewidth=0.4pt, linecolor=blue, framesize=3.5pt 7pt, dimen=middle](0,3pt){R}
\uput{2.5ex}[r](R){\pnode{W}}\ncline[arrows=->, linecolor = red, linewidth=0.6pt, linejoin=1, nodesepA=0.5pt, arrowinset=0.15,arrowsize=2pt]{R}{W} \end{pspicture}}%
\begin{document}
A\enspace\mysymbol
\end{document}