3

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.

Enter image description here

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\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}
Hany
  • 4,709

2 Answers2

5

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}
\beamertemplatenavigationsymbolsempty
\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}

enter image description here

  • 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 07:05
  • 1
    @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. –  Jul 23 '18 at 07:17
3

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}
\beamertemplatenavigationsymbolsempty
\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}

Enter image description here

Zarko
  • 296,517