3

This is a graph picture, what I would like to ask you is how to name "s_1" as same as "s_2", it means if you compile this, then you can see "s_1" is positioned at the right of the curve I would like to change naming as "s_2".

Also, how can I put "T" at (0,T)?

\documentclass[10pt]{beamer}    
\usepackage{tikz}


\begin{document}

    \begin{frame}{}

    \frametitle{Key lemmas}

    \framesubtitle{The weak maximum (minimum) principle}

For two continuous curves $s_1$, $s_2$ such that $s_1(t)<s_2(t), t\in[0,T]$, let us set $\displaystyle E_T:=\{(x,t): s_{1}(t)<x<s_{2}(t),\ 0<t\leq T\}$ and $\displaystyle B_T:=\{(s_{i}(t),t): 0\leq t\leq T,\ i\in\{1,2\}\}\cup\{(x,0): s_{1}(0)< x< s_{2}(0)\}$.

\begin{tikzpicture}

 \draw[help lines, color=gray!30, dashed]  ;

   \draw[->,] (-4,0)--(5.5,0) node[right]{$x(position)$};

   \draw[->,](0,0)--(0,3) node[above]{$t(time)$};

     \draw[scale=1,domain=1:4,smooth,variable=\x,red,ultra thick] plot ({\x},{\x-1}) node[right]{$s_2$};

          \draw [scale=1,domain=-2:-0.5,smooth,variable=\x,red,ultra thick] plot ({\x},{(-2)*\x-1}) node[left]{$s_1$};

           \draw[scale=1,domain=-0.5:1,smooth,variable=\x,red,ultra thick] plot ({\x},{0});

      \draw[scale=1,domain=-3:5.5,smooth,variable=\x,blue,dashed] plot ({\x},{2});

      \end{tikzpicture}

      \end{frame}

\end{document}
  • I am a bit confused about your question. You already have a label on your y-axis, and what prevents you from just replace s_1 in the tikzpicture by s_2? – user121799 May 5 '18 at 6:39
  • It's about indication what is s_1. "s_1" is printed on the right side of it's curve I want to change it like s_2. – Jimmy May 5 '18 at 7:16
  • I honestly do not understand what you mean. Can you draw a sketch in for example Paint, to illustrate? For the T, I guess \node[above right] at (0,2) {(0,T)};? – Torbjørn T. May 5 '18 at 7:40
  • If you compile this, you will notice what I mean easily. I want to indicate which curve by s_1, s_2 but s_1 is not printed like s_2 at the end of curve. – Jimmy May 5 '18 at 7:47
2

Like this?

enter image description here

The key change is to swap the order of the domain in the first \draw .. plot. That is, use domain=-0.5:-2 instead of domain=-2:-0.5. When you append node {..} at the end of a \draw plot like that, the node is placed at the last plotted point. By swapping the order in the domain specification, the leftmost point is plotted last, so the s_1 node ends up where you see in the image.

(In a normal path, like \draw (0,0) -- (2,2);, you could have used pos=0 in the node options to move the node to the start of the path, but that doesn't work for a plot.)

I removed some unnecessary stuff from your code. variable=\x is default, so you don't have to specify it, and smooth is pointless for linear functions. scale=1 didn't seem necessary either.

\documentclass[10pt]{beamer}    
\usepackage{tikz}
\begin{document}

\begin{frame}
\frametitle{Key lemmas}
\framesubtitle{The weak maximum (minimum) principle}

For two continuous curves $s_1$, $s_2$ such that $s_1(t)<s_2(t), t\in[0,T]$,
let us set $\displaystyle E_T:=\{(x,t): s_{1}(t)<x<s_{2}(t),\ 0<t\leq T\}$ and
$\displaystyle B_T:=\{(s_{i}(t),t): 0\leq t\leq T,\ i\in\{1,2\}\}\cup\{(x,0): s_{1}(0)< x< s_{2}(0)\}$.

\begin{tikzpicture}[samples=2]

  \draw [->] (-4,0) -- (5.5,0) node[right]{$x$ (position)};
  \draw [->] (0,0) -- (0,3) node[above]{$t$ (time)};

  % the domain is changed in the following line
  \draw [domain=-0.5:-2,red,ultra thick] plot ({\x},{(-2)*\x-1}) node [left]  {$s_1$};
  \draw [domain=-0.5:1,red,ultra thick]  plot ({\x},{0});
  \draw [domain=1:4,red,ultra thick]     plot ({\x},{\x-1})      node [right] {$s_2$};

  \draw [domain=-3:5.5,blue,dashed]      plot ({\x},{2});

  \node [above right] at (0,2) {(0,T)};

\end{tikzpicture}
\end{frame}
\end{document}
  • 1
    @Jimmy No worries. As a sidenote, with a simple graph like that you could perhaps just as well do \draw [red,ultra thick] (-2,3) node [left] {$s_1$} -- (-0.5,0) -- (1,0) -- (4,3) node [right] {$s_2$};. – Torbjørn T. May 5 '18 at 12:30

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.