# Displaying parts of \draw command sequentially [closed]

I would like to display parts of a one \draw command sequentially. Using the following code I would like to display the axes only on the first slide, then the axes and the blue line only on the second slide, then the axes and the red line with the blue line on the third slide.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (8,0);
\draw [thick,-latex](0,0) -- (0,8.);
\draw [very thick,blue] (4.,4.) +(-45:4cm) node [black, xshift=.24cm, yshift=-.05cm] {$D$} -- +(135:4cm) +(45:4cm) node [black, xshift=0cm, yshift=.05cm] {$S$} edge[very thick, red] ++(-135:4cm);
\end{tikzpicture}
\end{frame}
\end{document}


• I think Beamer vs. TikZ: uncover nodes step-by-step does help. You could use \visible or \pause. If i'm right it could be flaged as a duplicat. – Bobyandbob Sep 3 '18 at 10:55
• Thank you for your suggestion; but you missed my point. Please refer to my edited question. I want to display parts of the \draw command in sequence; not the whole \draw command. – Hany Sep 3 '18 at 12:22

Till Tantau being the creator of BEAMER and Tikz-PGF the overlay work with tikz. Just add the overlay specification after the command name.

For example, here to make the transparency visible on the second and all subsequent images: draw<2->(0,0)--(2,0);

Edit 2: Beamer manual p 85:

9.6.1 Making Commands and Environments Overlay Specification-Aware

beamer extends the syntax of LaTeX's standard command \newcommand:

\newcommand<>{< command name>}[< argument number>][< default optional value>]{< text>}

[...]

The additionally allowed argument is the overlay specification

Till Tantau wrote all Tikz commands in this way. It is therefore essential that the overlay follows the name of the command. So we can't trace a path in sequence. It is necessary to write several paths, each written with a given overlay.

Then, it's not possible to display parts of the \draw command in sequence. It is mandatory to write as many \draw commands as sequences.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\useasboundingbox(0,0)rectangle(8,8);
\draw [thick,-latex](0,0) -- (8,0)(0,0) -- (0,8.);
\draw<2-> [very thick,blue] (4.,4.) +(-45:4cm) node [black, xshift=.24cm, yshift=-.05cm] {$D$} -- +(135:4cm) +(40:4cm) node [black, xshift=0cm, yshift=.05cm] {$S$} edge[very thick, purple!90!black, solid] ++(-140:4cm);
\draw<3-> [thick, black, densely dashed] (0,4.) node [black, xshift=-.28cm, yshift=-.05cm] {$P_0$} -- ++(0:4.) node [circle, draw, solid, black, fill=black, scale=0.2, xshift=0cm, yshift=0cm]{} -- +(-90:4.);
\end{tikzpicture}
\end{frame}
\end{document}


Note: instead of writing two \draw commands:

 \draw [thick,-latex](0,0) -- (8,0);
\draw [thick,-latex](0,0) -- (0,8.);


you can write only one draw command

\draw [thick,-latex](0,0) -- (8,0)(0,0) -- (0,8.);

• Thank you for your answer. What I want to do is to display the different parts, of one draw command, sequentially. The following code generates 2 lines. I want to display each line separately. \draw [very thick,blue] (4.,4.) +(-45:4cm) node [black, xshift=.24cm, yshift=-.05cm] {$D$} -- +(135:4cm) +(40:4cm) node [black, xshift=0cm, yshift=.05cm] {$S$} edge[very thick, purple, dashed] ++(-140:4cm); – Hany Aug 26 '18 at 5:37
• @Hany I don't understand. Edit your question by adding a minimal example of what you want to do that doesn't work. – AndréC Aug 26 '18 at 5:43
• I edited my question to clarify my request, removing my trial to do so. – Hany Aug 27 '18 at 5:02
• @Hany i edited my answer, I hope that will answer your question. – AndréC Aug 27 '18 at 6:49
• @Hany I'm sorry to misspoke in English. It is not possible to display draw commands in sequence. I'm editing again. – AndréC Aug 27 '18 at 19:25

Do you want to have this three graphics?

\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\newcommand{\achses}{\draw [thick,-latex](0,0) -- (8,0);\draw [thick,-latex](0,0) -- (0,8.);}
\newcommand{\blueline}{\draw [very thick,blue] (4.,4.) +(-45:4cm) node [black, xshift=.24cm, yshift=-.05cm] {$D$} -- +(135:4cm) +(45:4cm);}
\newcommand{\redline}{\draw [very thick,blue] (4.,4.) +(-45:4cm) node [black, xshift=.24cm, yshift=-.05cm] {$D$} -- +(135:4cm) +(45:4cm) node [black, xshift=0cm, yshift=.05cm] {$S$} edge[very thick, red] ++(-135:4cm);
}% needs removal of blueline!
\newcommand{\myframe}[2]{\frametitle{#1}\begin{tikzpicture}[scale=.9, transform shape]#2\end{tikzpicture}}
\begin{document}
\begin{frame}[fragile,t]\myframe{}{\achses}
\end{frame}
\newpage
\begin{frame}[fragile,t]\myframe{}{\achses\blueline}
\end{frame}
\newpage
\begin{frame}[fragile,t]\myframe{}{\achses\blueline\redline}
\end{frame}
\end{document}


From \redline the code for the blue line should be removed (otherwise the blue line is plotted twice).

First argument of \myframe is the argumet to \frametitle, which was empty in the minimal example.

Using the \pause command (see https://tex.stackexchange.com/a/9160/6865, thanks to Bobyandbob for pointing this out) it would also be possible:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (8,0);
\draw [thick,-latex](0,0) -- (0,8.);\pause
\draw [very thick,blue] (4.,4.) +(-45:4cm) node [black, xshift=.24cm, yshift=-.05cm] {$D$} -- +(135:4cm) +(45:4cm);\pause
\draw [very thick,blue] (4.,4.) +(-45:4cm) node [black, xshift=.24cm, yshift=-.05cm] {$D$} -- +(135:4cm) +(45:4cm) node [black, xshift=0cm, yshift=.05cm] {$S$} edge[very thick, red] ++(-135:4cm);
\end{tikzpicture}
\end{frame}
\end{document}

• Thank you for your answer. I`ve already tried this, which is too long. I was hoping to find a code to display parts of the \draw command in sequence. – Hany Sep 3 '18 at 12:21