1

I'm pretty new to tikz, I finished some days ago the tutorials on the manual. I tried to come up with a very simple diagram for a project of mine I'm writing. That's what I did:

\begin{tikzpicture}
    [
    node distance=5cm,
    cyl/.style={cylinder, aspect=0.3, shape border rotate=90, minimum height=2cm, minimum width=2.5cm, draw}]

    % \newcommand\file[3][]{\draw[xshift=#1, yshift=#2, scale=#3] (0,0) -- (0.8, 0) -- (1, -0.2) -- (1, -1.414) -- (0, -1.414) -- cycle;}
    \node[rectangle, rounded corners, draw, inner sep=8pt] (Application) {Application};
    \node[below left of=Application, cyl] (Filesystem) {Filesystem};
    \node[below right of=Application, cyl] (Database) {Database};
    \begin{scope}[xshift=-5mm, yshift=1cm]
        \draw[scale=0.75]   (Filesystem.east) -- ++(0.8, 0) -- ++(0.2, -0.2) -- ++(0, -1.214) -- ++(-1, 0) -- ++(0, 1.414) -- cycle;
    \end{scope}
    \draw[<->] (Application) -- (Filesystem);
    \draw[<->] (Application) -- (Database);

    \begin{scope}[on background layer]
        \node[fill=bluish, rounded corners, inner sep=4mm, fit=(Application) (Filesystem) (Database)] {};
        \node[draw=black!70,thick, dashed, fit=(Filesystem)(Database)] {};
    \end{scope}

\end{tikzpicture}

The result is this:

enter image description here

As you can see the little "sheet of paper" icon I wanted to put on the Filesystem node is not affected by the shifting I applied to it. I also tried applying it to the path, but the result does not change.

Moreover, I tried to define a new command to draw it, but the compilation fails saying that the \file command is undefined.

Could you help me in finding the mistakes I'm making, please?

Thanks in advance.

1
  • 1
    Symbolic coordinates do not get shifted. You can use \draw[scale=0.75] ([xshift=-5mm, yshift=1cm]Filesystem.east) -- ++(0.8, 0) -- ++(0.2, -0.2) -- ++(0, -1.214) -- ++(-1, 0) -- ++(0, 1.414) -- cycle;. – user194703 May 20 '20 at 16:21
1

Symbolic coordinates do not get shifted. You could use

\draw[scale=0.75]   ([xshift=-5mm, yshift=1cm]Filesystem.east) -- ++(0.8, 0) -- ++(0.2, -0.2) -- ++(0, -1.214) -- ++(-1, 0) -- ++(0, 1.414) -- cycle;

However, there is a very similar shape in the pgfmanual, which you also could use. And I'd recommend using positioning.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{backgrounds,fit,positioning,shapes.geometric}
\makeatletter
\pgfdeclareshape{document}{% from p. 1147 of pgfmanual v3.1.5
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle 
\inheritanchorborder[from=rectangle] 
\inheritanchor[from=rectangle]{center} 
\inheritanchor[from=rectangle]{north} 
\inheritanchor[from=rectangle]{south} 
\inheritanchor[from=rectangle]{west} 
\inheritanchor[from=rectangle]{east}
% ... and possibly more 
\backgroundpath{% this is new
    % store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% compute corner of ``flipped page''
\pgf@xc=\pgf@xb \advance\pgf@xc by-5pt % this should be a parameter \pgf@yc=\pgf@yb \advance\pgf@yc by-5pt
    % construct main path
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathclose
    % add little corner
    \pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
    \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
}
}
\makeatother
\colorlet{bluish}{blue!10}
\begin{document}
\begin{tikzpicture}
    [
    node distance=4cm,
    cyl/.style={cylinder, aspect=0.3, shape border rotate=90, minimum height=2cm, minimum width=2.5cm, draw}]

    \node[rectangle, rounded corners, draw, inner sep=8pt] (Application) {Application};
    \node[below left=of Application, cyl] (Filesystem) {Filesystem};
    \node[below right=of Application, cyl] (Database) {Database};
    \node[right=-3mm of Filesystem,yshift=1mm,document,draw,
        minimum width=2em,minimum height=3em] {};
    \draw[<->] (Application) -- (Filesystem);
    \draw[<->] (Application) -- (Database);

    \begin{scope}[on background layer]
        \node[fill=bluish, rounded corners, inner sep=4mm, fit=(Application) (Filesystem) (Database)] {};
        \node[draw=black!70,thick, dashed, fit=(Filesystem)(Database)] {};
    \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.