我想用 Tikz 画一些类似的东西(见下文)。除了线条和折角的东西。也就是说,我想用图层效果绘制三个节点...
到目前为止我已经尝试过:
\documentclass[a4paper,openright,twoside,11pt]{memoir}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[font=\sffamily]
\tikzstyle{doc}=[%
minimum height=4em,
minimum width=3em,
draw
]
\node[] (smthng) {};
\node[doc] (doc) [below = of smthng] {docs};
\node[doc] (doc2) [below = of smthng,yshift=4pt,xshift=4pt] {};
\node[doc] (doc3) [below = of smthng,yshift=-4pt,xshift=-4pt] {};
\end{tikzpicture}
\caption{My docs.}
\end{figure}
\end{document}
生成结果为:
现在我想让节点doc2
部分被 隐藏doc
;doc
部分被 隐藏doc3
。我该如何实现?
[编辑] 实际上标签docs
应该放在doc3
...
答案1
我在 TeX.SX 中看到过这个图,但是当我尝试找到它时,这里有一个可能的解决方案:
\documentclass[a4paper,openright,twoside,11pt]{memoir}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[font=\sffamily]
\tikzstyle{doc}=[%
minimum height=4em,
minimum width=3em,
draw, fill=white
]
\node[doc] (doc) {};
\node[doc, below left = 4pt and 4pt of doc.north east] (doc2) {};
\node[doc, below left = 4pt and 4pt of doc2.north east] (doc3) {docs};
\end{tikzpicture}
\caption{My docs.}
\end{figure}
\end{document}
更新:甚至更容易double copy shadow
double copy shadow
库中的样式shadows
可以用更少的代码来实现:
\documentclass[a4paper,openright,twoside,11pt]{memoir}
\usepackage{tikz}
\usetikzlibrary{positioning, shadows}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[font=\sffamily,
doc/.style={draw, minimum height=4em, minimum width=3em,
fill=white,
double copy shadow={shadow xshift=4pt,
shadow yshift=4pt, fill=white, draw}},
]
\node[doc] (doc) {doc};
\end{tikzpicture}
\caption{My docs.}
\end{figure}
答案2
这是一个有点过度的解决方案。:D
输出
代码
\documentclass{article}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,positioning}
\tikzset{
arr/.style={{Round Cap[]}-{Round Cap[]}, line width=1.5mm, shorten >=3.5mm, shorten <=3.5mm}
}
\newcommand{\picon}[1][1]{
\scalebox{#1}{%
\tikz{
\begin{scope}[shift={(1,1)}]
\node[draw, fill=white, line width=2mm, minimum height=2.5cm, minimum width=1.8cm] (o) at (0,0) {};
\draw[white, fill=white] ($(o.north east)+(-6mm,0)$) --++ (6mm,0) --++ (0,-6mm) -- cycle;
\fill[black] ($(o.north east)+(0,-6mm)$) --++ (0,-1mm) --++ (-7mm,0) --++ (0,7mm) --++ (1mm,0) -- cycle;
\end{scope}
\begin{scope}[shift={(.5,.5)}]
\node[draw, fill=white, line width=2mm, minimum height=2.5cm, minimum width=1.8cm] (p) at (0,0) {};
\draw[white, fill=white] ($(p.north east)+(-6mm,0)$) --++ (6mm,0) --++ (0,-6mm) -- cycle;
\fill[black] ($(p.north east)+(0,-6mm)$) --++ (0,-1mm) --++ (-7mm,0) --++ (0,7mm) --++ (1mm,0) -- cycle;
\node[anchor=south west, fill=white, minimum width=1cm, minimum height=1.5mm, outer sep=0, inner sep=0] at (p.north west) {};
\node[anchor=south west, fill=white, minimum width=1.5mm, minimum height=1cm, outer sep=0, inner sep=0] at (p.south east) {};
\end{scope}
\node[draw, fill=white, line width=2mm, minimum height=2.5cm, minimum width=1.8cm, inner sep=0] (n) at (0,0) {};
\draw[white, fill=white] ($(n.north east)+(-6mm,0)$) --++ (6mm,0) --++ (0,-6mm) -- cycle;
\fill[black] ($(n.north east)+(0,-6mm)$) --++ (0,-1mm) --++ (-7mm,0) --++ (0,7mm) --++ (1mm,0) -- cycle;
\node[anchor=south west, fill=white, minimum width=1cm, minimum height=1.5mm, outer sep=0, inner sep=0] at (n.north west) {};
\node[anchor=south west, fill=white, minimum width=1.5mm, minimum height=1cm, outer sep=0, inner sep=0] at (n.south east) {};
\foreach \n in {.32,.44,.56,.68,.8}{
\draw[arr] ($(n.north west)!\n!(n.south west)$) -- ($(n.north east)!\n!(n.south east)$);}
\node[anchor=south west, minimum size=2.4mm,fill=black, outer sep=0, inner sep=0] (m) at ($(o.north east)+(-7mm,-7mm)$) {};
\node[anchor=south west, minimum size=2.4mm,fill=black, outer sep=0, inner sep=0] (m) at ($(p.north east)+(-7mm,-7mm)$) {};
}}
}
\begin{document}
\lipsum*[1]
\begin{figure}[!h]
\centering
\picon
\caption{Some docs}
\end{figure}
\lipsum*[2]
\begin{figure}[!h]
\centering
\picon[.2]
\caption{Smaller docs}
\end{figure}
\end{document}
答案3
我需要做同样的事情,这是我的解决方案
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}
\def\corner{0.15in}
\def\cornerradius{0.02in}
\def\lwidth{0.02in}
\def\h{1.1in}
\def\w{0.85in}
\def\nline{10}
\def\iconmargin{0.1in}
\def\topmargin{0.3in}
\foreach[count=\i] \filename in {bar.c,bar.h,foo.c,foo.h}
{
\coordinate (nw) at ($(-0.05in*\i,-0.15in*\i)$);
\coordinate (ne0) at ($(nw) + (\w, 0)$);
\coordinate (ne1) at ($(ne0) - (\corner, 0)$);
\coordinate (ne2) at ($(ne0) - (0, \corner)$);
\coordinate (se) at ($(ne0) + (0, -\h)$);
\filldraw [-, line width = \lwidth, fill=white] (nw) -- (ne1) -- (ne2)
[rounded corners=\cornerradius]--(se) -- (nw|-se) -- cycle;
\draw [-, line width = \lwidth] (ne1) [rounded corners=\cornerradius]-- (ne1|-ne2) -- (ne2);
\node [anchor=north west] at (nw) {\scriptsize \tt \filename};
\foreach \k in {1,...,\nline}
{
\draw [-, line width = \lwidth, line cap=round]
($(nw|-se) + (\iconmargin,\iconmargin) + (0,{(\k-1)/(\nline-1)*(\h - \iconmargin - \topmargin)})$)
-- ++ ($(\w,0) - 2*(\iconmargin,0)$);
}
}
\end{tikzpicture}
\end{document}