如果可能的话,我想绘制一些接近文件夹dir
图形的东西作为node
对象tikzpicture
:
有关的:https://tex.stackexchange.com/a/174673/127048 这里有一个 tikz 解决方案,但我无法取出文件夹内的纸张。
答案1
这是实现此目的的方法。基本概念是与之前描述的相同,但现在用文件夹绘图:
- 左下方的节点文件夹,
line width=3pt
- 右上角,改为
\node [dashed]
且线宽更小 - 只是为了演示如何使用它
\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{tikz}
\begin{document}
% ~~~ pictures ~~~~~~~~~
\tikzset{
folder/.pic={
% ~~~ back part ~~~~~~~~~~
\draw [fill=green!70!blue, rounded corners] (-1.43,-1.05) -- (-1.43,1.04) -- (-0.77,1.04) -- (-0.77,0.68) -- (0.94,0.68) -- (0.94,0.0) -- cycle;
% ~~~ front part ~~~~~~~~~
\draw [fill=green!80!, rounded corners] (-1.43,-1.05) -- (-1.03,0.37) -- (1.29,.37) -- (0.90,-1.05) -- cycle;
}
}
% ~~~ demo ~~~~~~~~~~~~~~~~
\begin{tikzpicture}% [line width=3pt]
% ~~~ a simple way to put a drawing as a node ~~~~~~~~~~~~
\node at (0,-2) {\tikz{\pic [line width=3pt] at (0,0) {folder};}};
\node [dashed, rotate=20] at (4,1) {\tikz{\pic [line width=1pt] at (0,0) {folder};}};
\end{tikzpicture}
\end{document}
附言:关于缩放效果的一些注释。当对象变得太小时,Tikz 将难以满足需求。示例:
\pics
调用line width=1pt
\pic
套rounded corners=5pt
- 上层文件夹仅使用
,scale=.5]
- 下部使用
,scale=.5,transform shape]
您可以看到,两张缩放图片的伪影相似但不完全相同。对于给定的坐标,似乎存在rounded corners=3pt
在不可见和可见效果之间切换的限制。
原因是 Tikz 尝试在给定的坐标处以给定的半径绘制圆角。如果半径较小或高度的坐标差较大,它就会成功。
\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{tikz}
\begin{document}
% ~~~ pictures ~~~~~~~~~
\tikzset{
folder/.pic={
% ~~~ back part ~~~~~~~~~~
\draw [fill=green!70!blue, rounded corners=5pt] (-1.43,-1.05) -- (-1.43,1.04) -- (-0.77,1.04) -- (-0.77,0.68) -- (0.94,0.68) -- (0.94,0.0) -- cycle;
% ~~~ front part ~~~~~~~~~
\draw [fill=green!80!, rounded corners] (-1.43,-1.05) -- (-1.03,0.37) -- (1.29,.37) -- (0.90,-1.05) -- cycle;
}
}
% ~~~ demo ~~~~~~~~~~~~~~~~
\begin{tikzpicture}% [line width=3pt]
% ~~~ a simple way to put a drawing as a node ~~~~~~~~~~~~
\node at (0,3) {\tikz{\pic [line width=1pt,scale=.5] at (0,0) {folder};}};
\node at (0,0) {\tikz{\pic [line width=1pt] at (0,0) {folder};}};
\node at (0,-3) {\tikz{\pic [line width=1pt,scale=.5,transform shape] at (0,0) {folder};}};
\node [dashed, rotate=20] at (4,1) {\tikz{\pic [line width=1pt] at (0,0) {folder};}};
\end{tikzpicture}
\end{document}
答案2
这是解决方案的一部分,即可以实现的一种方法:
- 放置节点
\tikz{ ...}
将呼叫作为“文本”- 参见下面截图中的红色绘图
% ~~~ a simple way to put a drawing as a node ~~~~~
\node [rotate=-30,red] at (0,-9) {\tikz{\pic [line width=7pt] at (0,0) {symb};}};
为了简单起见,我扩展了我的最新解决方案对于您发布的另一个问题:检查\node
最后的最后陈述。如您所见:
- 您可以将大多数选项传递给
\node [...]
- 然而,至少
line width
需要传递给\pic
要定义自己的节点和形状,请参阅手册中的第 106 章。但我想,我的方法更容易理解和应用。
\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{tikz}
\begin{document}
% ~~~ pictures ~~~~~~~~~
\tikzset{
symb/.pic={
\draw (1.5,3.25) -- (-2.65,3.25) -- (-2.65,-3.3) -- (2.85,-3.35) -- (2.85,1.85) -- cycle;
\draw (-.45,.8) -- (-1.45,-.25) -- (-.55,-1.3);
\draw ( .45,.8) -- ( 1.45,-.25) -- ( .55,-1.3);
}
}
\tikzset{
pers/.pic={
\draw (1.5,3.25) -- (-2.65,3.25) -- (-2.65,-3.3) -- (2.85,-3.35) -- (2.85,1.85) -- cycle;
\draw [fill=black,draw=white] (1.05,1.95) -- (-1.95,2) -- (-1.95,-2) --
(-0.95, -2) arc [start angle=180,end angle=90,radius=1cm] --
++(0,0) arc [start angle=270,end angle=-90,radius=1cm] --
++ (0,0) arc [start angle=90,end angle=0,radius=1cm]
-- (2.05,-2) -- (2.05,1) -- cycle;
}
}
% ~~~ demo ~~~~~~~~~~~~~~~~
\begin{tikzpicture}[line width=3pt]
\pic at (0,0) {symb};
\pic at (6,0) {pers};
\pic at (12,-9) {pers};
% ~~~ a simple way to put a drawing as a node ~~~~~~~~~~~~
\node [rotate=-30,red] at (0,-9) {\tikz{\pic [line width=7pt] at (0,0) {symb};}};
\end{tikzpicture}
\end{document}