Continue a line in different attributes

Using the following code I can draw a line in certain attributes, and then continue it in different attributes. Can this be done in one \draw command, instead of using two \draw commands?

I tried using edge from the answer of this question, but I could not apply it to get the following result.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (9,0) node [black, xshift=-.6cm, yshift=-.34cm] {S};
\draw [thick,-latex](0,0) -- (0,2.) node [black, xshift=-.2cm, yshift=.3cm] {E};
\draw [very thick, black] (0,1.) -- +(0:3.cm) node [black, xshift=.5cm, yshift=0cm] {MC};
\draw [thick, red, densely dashed] (3.86,1.) -- +(0:5.cm) node [red, xshift=0cm, yshift=0cm] {x};
\end{tikzpicture}
\end{frame}
\end{document}


It works precisely as in the answer you are referring to (except you need to use ++ instead of + for relative shifts, and that you have to adjust the xshift of the x node).

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (9,0) node [black, xshift=-.6cm, yshift=-.34cm] {S};
\draw [thick,-latex](0,0) -- (0,2.) node [black, xshift=-.2cm, yshift=.3cm] {E};
\draw [very thick, black] (0,1.) -- ++(0:3.cm) node [black, xshift=.5cm, yshift=0cm] {MC}
edge[thick, red, densely dashed] ++(0:5.cm) node [red, xshift=5cm, yshift=0cm] {x};
\end{tikzpicture}
\end{frame}
\end{document}


• Thank you very much for your answer. I just would like to understand the x shift please. I understand that when using -- ++(0:3.cm) it goes to this coordinates; so why do I have to adjust the x shift to add the extra 5cm.
– Hany
Jul 23 '18 at 7:05
• @Hany This is because an edge is not really a continuation of a path. Instead of xshift=5cm you could also just put ++(0:5.cm) twice: the first time to set the end point of the edge, the second time to set the location of the node.
– user121799
Jul 23 '18 at 7:17

No, as far as I know, you can change only a few parameters. Colors is not one of them. For details, check "tikz and pgf manual".

However, your example can be slightly simplified:

\documentclass{beamer}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9]
% axis
\draw [thick,-latex](0,0) -- (9,0) node [below left] {S};
\draw [thick,-latex](0,0) -- (0,2) node [below left] {E};
% lines
\draw [very thick] (0,1.) -- +(0:3) node[right] (mc) {MC};
\draw [thick, red, densely dashed,-Rays] (mc) -- +(0:5);
\end{tikzpicture}
\end{frame}
\end{document}


• Your code works very fine, but it still needs 2 \draw command lines.
– Hany
Jul 23 '18 at 6:59
• @Hany, what is shorter than use of edge and with it associated "complications" :-) Jul 23 '18 at 7:44