3

I created some node styles which are inspired by the presentation of Malte Schmitz. As you can see in the MWE, many things are hard coded – especially the node positioning of the tex,pdf etc. nodes. My question is: What do I have to change in the code to get the usage \node … (tex) --+ (2,0) … working?

MWE:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\setbeamertemplate{navigation symbols}{}
\tikzset{
    tex/.style={
        append after command={
            \pgfextra{
                    \node[minimum width=1.5cm,minimum height=1.5cm] (a) at (\tikzlastnode) {};
                    \draw[green!50!black,thick] ([xshift=-.4cm]a.north east) -- ([xshift=-.4cm,yshift=-.4cm]a.north east) -- ([yshift=-.4cm]a.north east);
                    \node[white,fill=green!50!black] at ([yshift=-.4cm]a.north west) (tex) {\sf TEX};
                    \draw[thick,green!50!black] (a.north west) -- (tex.north);
                    \draw[thick,green!50!black] (tex.south) -- (a.south west) -- (a.south east) -- ([yshift=-.4cm]a.north east) --  ([xshift=-.4cm]a.north east) -- ([xshift=-.014cm]a.north west);
                    \draw[shorten <=.2cm,thick,green!50!black] ([yshift=-.8cm]a.north west) -- ([xshift=-.2cm,yshift=-.8cm]a.north east) -- ([xshift=-.2cm,yshift=-.9cm]a.north east) -- ([yshift=-.9cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=-.2cm]a.north east);
            }
        }
    },
    pdf/.style={
        append after command={
            \pgfextra{
                \node[minimum width=1.5cm,minimum height=1.5cm] (a) at (\tikzlastnode) {};
                \draw[orange!80!black,thick] ([xshift=-.4cm]a.north east) -- ([xshift=-.4cm,yshift=-.4cm]a.north east) -- ([yshift=-.4cm]a.north east);
                \node[white,fill=orange!80!black] at ([yshift=-.4cm]a.north west) (pdf) {\sf PDF};
                \draw[thick,orange!80!black] (a.north west) -- (pdf.north);
                \draw[thick,orange!80!black] (pdf.south) -- (a.south west) -- (a.south east) -- ([yshift=-.4cm]a.north east) --  ([xshift=-.4cm]a.north east) -- ([xshift=-.014cm]a.north west);
                \draw[shorten <=.2cm,thick,orange!80!black] ([yshift=-.8cm]a.north west) -- ([xshift=-.2cm,yshift=-.8cm]a.north east) -- ([xshift=-.2cm,yshift=-.9cm]a.north east) -- ([yshift=-.9cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=-.2cm]a.north east);
            }
        }
    },
    aux/.style={
        append after command={
            \pgfextra{
                \node[minimum width=1.5cm,minimum height=1.5cm] (a) at (\tikzlastnode) {};
                \draw[purple!50,thick] ([xshift=-.4cm]a.north east) -- ([xshift=-.4cm,yshift=-.4cm]a.north east) -- ([yshift=-.4cm]a.north east);
                \node[white,fill=purple!50] at ([yshift=-.4cm]a.north west) (te) {\sf AUX};
                \draw[thick,purple!50] (a.north west) -- (te.north);
                \draw[thick,purple!50] (te.south) -- (a.south west) -- (a.south east) -- ([yshift=-.4cm]a.north east) --  ([xshift=-.4cm]a.north east) -- ([xshift=-.014cm]a.north west);
                \draw[shorten <=.2cm,thick,purple!50] ([yshift=-.8cm]a.north west) -- ([xshift=-.2cm,yshift=-.8cm]a.north east) -- ([xshift=-.2cm,yshift=-.9cm]a.north east) -- ([yshift=-.9cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=-.2cm]a.north east);
            }
        }
    },
    log/.style={
        append after command={
            \pgfextra{
                \node[minimum width=1.5cm,minimum height=1.5cm] (a) at (\tikzlastnode) {};
                \draw[thick] ([xshift=-.4cm]a.north east) -- ([xshift=-.4cm,yshift=-.4cm]a.north east) -- ([yshift=-.4cm]a.north east);
                \node[white,fill=black] at ([yshift=-.4cm]a.north west) (log) {\sf LOG};
                \draw[thick] (a.north west) -- (log.north);
                \draw[thick] (log.south) -- (a.south west) -- (a.south east) -- ([yshift=-.4cm]a.north east) --  ([xshift=-.4cm]a.north east) -- ([xshift=-.014cm]a.north west);
                \draw[shorten <=.2cm,thick] ([yshift=-.8cm]a.north west) -- ([xshift=-.2cm,yshift=-.8cm]a.north east) -- ([xshift=-.2cm,yshift=-.9cm]a.north east) -- ([yshift=-.9cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=-.2cm]a.north east);
            }
        }
    }
}
\begin{document}
    \begin{frame}
        \begin{tikzpicture}
            \scalebox{1.1}[1.1]{\node[tex,yshift=-6cm] (r) {};}
            \draw[very thick,->] ([xshift=.9cm,yshift=-.5cm]r.east) --+ (2,0) node[right] (s) {\bf\textrm{pdf\TeX}};
            \draw[very thick,->] (s) --+ (2,0);
                \node[pdf,right] at ($(s)+(3.5,0)$) {};
            \uncover<2>{
                \draw[very thick,->] (s) --+ (-1,-2);
                \draw[very thick,->] (s) --+ (1,-2);
                    \node[xshift=-.5cm,yshift=-1cm,aux] at ($(s)+(-1,-2)$) {};
                    \node[xshift=.5cm,yshift=-1cm,log] at ($(s)+(1,-2)$) {};
            }
            \uncover<3->{
                \begin{scope}[opacity=.5]
                    \draw[very thick,->] (s) --+ (-1,-2);
                    \draw[very thick,->] (s) --+ (1,-2);
                        \node[xshift=-.5cm,yshift=-1cm,aux] (c1) at ($(s)+(-1,-2)$) {};
                        \node[xshift=.5cm,yshift=-1cm,log] at ($(s)+(1,-2)$) {};
            \end{scope}
                \draw[very thick,->,shorten >=1cm] (0,-7.7) |- (2,-12) node[right=-1] (node) {\rm \textbf{pdf\TeX}};
                \draw[very thick,->] (node) --+ (2,0);
                \scalebox{1.1}[1.1]{\node[pdf] at (5,-11){};}
            }
        \end{tikzpicture}
    \end{frame}
\end{document}

P.S.: I know that the build of latex files is different as in the presentation, but this is just a visualiation.

The output:

Screenshot

Screenshot

Screenshot

  • 2
    I guess the problem is related to the pgfextras. Is there any reason not to put the shapes into path pictures or store them in saveboxes that can be put into the nodes? – marmot Aug 21 '18 at 23:58
  • @marmot: Thanks for the quick response! I don't exactly know how to write the node definition so that I can use it for later. Of course I could just use, as you mentioned, saveboxes and so on and draw them but I thought it would be pretty easy with nodes … – current_user Aug 22 '18 at 0:01
5

Here is an attempt to answer this nice question. I eliminated all \pgfextra in favor of path pictures, and all \scaleboxes in favor of scale. Further, there is a lot of repetition going on, I think, so I define a generic node style from which the others derive. All the explicit coordinates have been eliminated.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\setbeamertemplate{navigation symbols}{}
\tikzset{
    generic/.style args={color #1 and text #2}{minimum width=2.3cm,minimum height=1.54cm,
        path picture={
                    \node[minimum width=1.5cm,minimum height=1.5cm] (a) at (0,0) {};
                    \draw[#1,thick] ([xshift=-.4cm]a.north east) -- ([xshift=-.4cm,yshift=-.4cm]a.north east) -- ([yshift=-.4cm]a.north east);
                    \node[white,fill=#1,minimum height=5mm,minimum
                    width=9mm] at ([yshift=-.4cm]a.north west) (tex) {\sf #2};
                    \draw[thick,#1] (a.north west) -- (tex.north);
                    \draw[thick,#1] (tex.south) -- (a.south west) -- (a.south east) -- ([yshift=-.4cm]a.north east) --  ([xshift=-.4cm]a.north east) -- ([xshift=-.014cm]a.north west);
                    \draw[shorten <=.2cm,thick,#1] ([yshift=-.8cm]a.north west) -- ([xshift=-.2cm,yshift=-.8cm]a.north east) -- ([xshift=-.2cm,yshift=-.9cm]a.north east) -- ([yshift=-.9cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=-.2cm]a.north east);
        }
    },
    tex/.style={generic={color green!50!black and text {TEX}}},
    pdf/.style={generic={color orange!80!black and text {PDF}}},
    aux/.style={generic={color purple!50,thick and text {AUX}}},
    log/.style={generic={color black,thick and text {LOG}}},
}
\begin{document}
    \begin{frame}
        \begin{tikzpicture}
            \path (0,2);
            \node[tex,scale=1.1] (r) at (0,0) {};
            \draw[very thick,->] (r.east) --+ (2,0) node[right] (s) {\bf\textrm{pdf\TeX}};
            \draw[very thick,->] (s) --++ (2,0);
            \path (s) ++(4,0) node[pdf] {};
            \uncover<2>{
                \draw[very thick,->] (s) --+ (-1,-2);
                \draw[very thick,->] (s) --+ (1,-2);
                    \node[aux] at ($(s)+(-1.5,-3)$) {};
                    \node[log] at ($(s)+(1.5,-3)$) {};
            }
            \uncover<3->{
                \begin{scope}[opacity=.5]
                    \draw[very thick,->] (s) --+ (-1,-2);
                    \draw[very thick,->] (s) --+ (1,-2);
                        \node[aux] (c1) at ($(s)+(-1.5,-3)$) {};
                        \node[log] at ($(s)+(1.5,-3)$) {};
            \end{scope}}
            \uncover<4->{   
                \draw[very thick,->,shorten >=1cm] (r) |- ++(2,-6) node[right=-1] (node) {\rm \textbf{pdf\TeX}};
                \draw[very thick,->] (node) --+ (2,0);
                \path (node) ++ (3.5,0) node[pdf,scale=1.1] {};
            }            
    \end{tikzpicture}
    \end{frame}
\end{document}

enter image description here

Note, however, that path picture have a weakness. The options of the ambient node will partly effect the nodes in the path picture. This is sometimes good and sometimes be bad. In this case, options like right will distort the node.

One way to avoid this is to work with \saveboxes.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\setbeamertemplate{navigation symbols}{}
\tikzset{
    generic/.style args={color #1 and text #2}{minimum width=2.3cm,minimum height=1.54cm,
        path picture={
                    \node[minimum width=1.5cm,minimum height=1.5cm] (a) at (0,0) {};
                    \draw[#1,thick] ([xshift=-.4cm]a.north east) -- ([xshift=-.4cm,yshift=-.4cm]a.north east) -- ([yshift=-.4cm]a.north east);
                    \node[white,fill=#1,minimum height=5mm,minimum
                    width=9mm] at ([yshift=-.4cm]a.north west) (tex) {\sf #2};
                    \draw[thick,#1] (a.north west) -- (tex.north);
                    \draw[thick,#1] (tex.south) -- (a.south west) -- (a.south east) -- ([yshift=-.4cm]a.north east) --  ([xshift=-.4cm]a.north east) -- ([xshift=-.014cm]a.north west);
                    \draw[shorten <=.2cm,thick,#1] ([yshift=-.8cm]a.north west) -- ([xshift=-.2cm,yshift=-.8cm]a.north east) -- ([xshift=-.2cm,yshift=-.9cm]a.north east) -- ([yshift=-.9cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=.2cm]a.north west) -- ([yshift=-1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=-.2cm]a.north east) -- ([yshift=-1.1cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=.2cm]a.north west) -- ([yshift=-1.2cm,xshift=-.2cm]a.north east);
        }
    },
    tex/.style={generic={color green!50!black and text {TEX}}},
    pdf/.style={generic={color orange!80!black and text {PDF}}},
    aux/.style={generic={color purple!50,thick and text {AUX}}},
    log/.style={generic={color black,thick and text {LOG}}},
}
\newsavebox\TEXBOX
\newsavebox\PDFBOX
\newsavebox\AUXBOX
\newsavebox\LOGBOX
\sbox\TEXBOX{\tikz{\node[tex]{};}}
\sbox\PDFBOX{\tikz{\node[pdf]{};}}
\sbox\AUXBOX{\tikz{\node[aux]{};}}
\sbox\LOGBOX{\tikz{\node[log]{};}}
\begin{document}
    \begin{frame}
        \begin{tikzpicture}
            \path (0,2);
            \node[scale=1.1] (r) at (0,0) {\usebox\TEXBOX};
            \draw[very thick,->] (r.east) --+ (2,0) node[right] (s) {\bf\textrm{pdf\TeX}};
            \draw[very thick,->] (s) --++ (2,0) node[right]{\usebox\PDFBOX};
            \uncover<2>{
                \draw[very thick,->] (s) --+ (-1,-2) node[below left] {\usebox\AUXBOX};
                \draw[very thick,->] (s) --+ (1,-2) node[below right] {\usebox\LOGBOX};
            }
            \uncover<3->{
                \begin{scope}[opacity=.5]
                    \draw[very thick,->] (s) --+ (-1,-2) node[below left] {\usebox\AUXBOX};
                    \draw[very thick,->] (s) --+ (1,-2) node[below right] {\usebox\LOGBOX};
                \end{scope}
                }
            \uncover<4->{   
                \draw[very thick,->,shorten >=1cm] (r) |- ++(2,-6) node[right=-1] (node) {\rm \textbf{pdf\TeX}};
                \draw[very thick,->] (node) --+ (2,0) node[right,scale=1.1] {\usebox\PDFBOX};
            }
        \end{tikzpicture}
    \end{frame}
\end{document}

enter image description here

EDIT: Got victim of the hardcoded distances, hope to have fixed that.

ADDENDUM: The cleanest solution is IMHO to use shapes for that, and to load the overlay-beamer-styles library. Luckily the required shape is almost completely done in this nice answer.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,overlay-beamer-styles}
\makeatletter
% https://tex.stackexchange.com/a/103800/121799
\pgfdeclareshape{document}{%
    \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}
    \inheritanchor[from=rectangle]{north west}
    \inheritanchor[from=rectangle]{south west}
    \inheritanchor[from=rectangle]{north east}
    \inheritanchor[from=rectangle]{south 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
        \def\hangout{12pt}
        % compute corner of "flipped page"
        \pgf@xc=\pgf@xb \advance\pgf@xc by-\hangout % this should be a parameter
        \pgf@yc=\pgf@yb \advance\pgf@yc by-\hangout
        % 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}}
        \pgfpathclose
        % add lines
        \pgfmathtruncatemacro{\step}{abs(\pgf@yb-\pgf@ya)/6}
        \pgfmathtruncatemacro{\stepx}{abs(\pgf@yb-\pgf@ya)/12}
        \pgfmathtruncatemacro{\lines}{abs(\pgf@yb-\pgf@ya)/\step-1}
        \foreach \y in {1,...,\lines}{%
            \ifodd\y
              \pgfpathmoveto{\pgfpoint{\pgf@xa+\stepx*1pt+\hangout}{\pgf@yb-0.5*(\lines+\y)*\step*1pt}}
              \pgfpathlineto{\pgfpoint{\pgf@xc-\stepx*1pt}{\pgf@yb-0.5*(\lines+\y)*\step*1pt}}
              \ifnum\y=1
              \else
                \pgfpathlineto{\pgfpoint{\pgf@xc-\stepx*1pt}{\pgf@yb-0.5*(\lines+\y-1)*\step*1pt}}
              \fi
            \else  
              \pgfpathmoveto{\pgfpoint{\pgf@xc-\stepx*1pt}{\pgf@yb-0.5*(\lines+\y)*\step*1pt}}
              \pgfpathlineto{\pgfpoint{\pgf@xa+\stepx*1pt+\hangout}{\pgf@yb-0.5*(\lines+\y)*\step*1pt}}
              \ifnum\y=1
              \else
                \pgfpathlineto{\pgfpoint{\pgf@xa+\stepx*1pt+\hangout}{\pgf@yb-0.5*(\lines+\y-1)*\step*1pt}}
              \fi
            \fi
        }%  
    }%
}%
\makeatother
\setbeamertemplate{navigation symbols}{}
\begin{document}
\tikzset{doc/.style args={#1/#2}{%
draw=#1,
thick,
align=center,
shape=document,
minimum width=20mm,
minimum height=18mm,
label={[xshift=12pt,fill=#1,text=white,font=\sffamily]172:#2},
},
transparent on/.style={alt={#1{opacity=0.5}{}}},}
\begin{frame}[t]{Title}
\begin{tikzpicture}
   \path (0,2);
   \node[doc=green!50!black/TEX] (r) at (0,0){};
   \draw[very thick,->] (r) -- ++ (2.5,0) node[right] (s) {\bf\textrm{pdf\TeX}};
   \draw[very thick,->] (s) -- ++ (2.5,0) node[right,doc=orange!80!black/pdf]{};
   \uncover<2->{
      \draw[transparent on=<2>,very thick,->] (s) --++ (-1,-2) 
        node[below,xshift=-5mm,doc=purple!50/aux]{};
      \draw[transparent on=<2>,very thick,->] (s) --++ (1,-2) 
      node[below,xshift=5mm,doc=black/aux]{};
   }
   \uncover<4->{    
      \draw[very thick,->,shorten >=1cm] (r) |- ++(2,-6) node[right=-1] (node) 
      {\rm \textbf{pdf\TeX}};
      \draw[very thick,->] (node) --+ (2,0) node[right,doc=orange!80!black/pdf]{};
   }            
\end{tikzpicture}
\end{frame}
\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.