1

I would like my code to give me something similar to the picture but my intersecting straight does not want to move above or below the variable 1 and when I try to get it look exact like my picture it shifts away from my coordinates.

\begin{figure}
    \begin{center}
    \begin{tikzpicture}[scale=3]
    \draw[->] (-2,0) -- (2,0) node[right] {$R_{pe}$}; 
    \draw[->] (0,-1.5) -- (0,2) node[above] {$R_{ph}$};
    \draw[->] (-2,1) -- (2,1);
    \draw[->] (1,-1.5) -- (1,2);
    \draw[blue] (0,1)  -- (1,0) ;
    \end{tikzpicture}
\end{center}    
\end{figure}
  • 2
    Please make your code compilable: it's much easier for people to help you, if you complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. – Thruston Aug 27 '17 at 12:54
  • 1
    Don't use \begin{center}...\end{center} inside figure or table environments. Just use \begin{figure}\centering...\end{figure} – user31729 Aug 27 '17 at 12:58
4

I don't really understand what your explanation of what goes wrong, but it's just a matter of choosing the proper coordinates I suppose. The slope of your blue line is -1, so you can for example start the line at (-1,2) instead of (0,1), and end it at (2,-1) instead of (1,0).

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=2]
    \draw[->] (-2,0) -- (2,0) node[right] {$R_{pe}$}; 
    \draw[->] (0,-1.5) -- (0,2) node[above] {$R_{ph}$};
    \draw[->] (-2,1) -- (2,1);
    \draw[->] (1,-1.5) -- (1,2);
    \draw[blue] (-1,2)  -- (2,-1) node[right,black] {$R_0=\dots$};
    \node at (0.25,0.25) {I};
    \node at (0.75,0.75) {II};
\end{tikzpicture}
\end{figure}
\end{document}

output of code

2

Choosing the proper coordinates, as suggested by Torbjørn T.s answer is probably the best way to deal with your requirements. But if you don't insist on the blue line going exactly from the top of the vertical lines to the right of the horizontal lines, you can use shorten with negative lengths to extend the line.

Remark: In the example here I choose -3cm to better show the limitations, although -4cm would fit much better. And that length depens on the scale you're using.

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}[scale=3]
\draw[->] (-2,0) -- (2,0) node[right] {$R_{pe}$}; 
\draw[->] (0,-1.5) -- (0,2) node[above] {$R_{ph}$};
\draw[->] (-2,1) -- (2,1);
\draw[->] (1,-1.5) -- (1,2);
% -4cm for shorten is better, but set to -3cm to show the limitations
\draw[blue,shorten >=-3cm,shorten <=-3cm] (0,1)  -- (1,0) ;
\end{tikzpicture}
\end{document}

enter image description here

Edit: As Torbjørn T. mentioned, a downside to this is, that nodes can't be easily added to the end of the line. Using

\draw[blue,shorten >=-3cm,shorten <=-3cm] (0,1)  -- (1,0) node[right]{foo};

will lead to this:

enter image description here

  • 2
    A potential downside to this is node placement, try \draw[blue,shorten >=-3cm,shorten <=-3cm] (0,1) -- (1,0) node[right]{foo}; – Torbjørn T. Aug 27 '17 at 15:35
  • 1
    @TorbjørnT. you're right. I added this to my answer. – Mike Aug 27 '17 at 15:50

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.