3

desired graph

I need to do a graph similar to the one in the picture above but I don't know how to do the horizontal lines without the arrow, or the vertical arrow. The best I could do is the following:

\documentclass{amsart}
\usepackage{tikz} 
\begin{document}
\begin{center}
\begin{tikzpicture}
    \node (p1) at ( 0, 0) {}; 
    \node (p2) at ( 1, -0.2) {i};
    \node (p3) at ( 3,0) {};
    \node (p4) at ( 0,1) {};
    \node (p5) at ( 2,1.2) {n+j};
    \node (p6) at ( 3,1) {};
    \begin{scope}[every path/.style={->}]
       \draw (p1) -- (p3); 
       \draw (p4) -- (p6);
       \draw (p2) -- (p5);
    \end{scope}  
\end{tikzpicture}
\end{center}
\end{document}

Output

enter image description here

3
  • 2
    Mmmm... I'm guessing this has to do with style={->}. :)
    – Werner
    Sep 30, 2014 at 0:26
  • Welcome to TeX.SE. Sep 30, 2014 at 0:45
  • Why not put i and n+j in math mode? ($i$ and $n+j$)
    – user10274
    Sep 30, 2014 at 13:28

2 Answers 2

4

Is this the desired result:

enter image description here

Notes:

  • If you don't want arrow heads on the end of lines, either change the style to every path/.style={-} or simply eliminate that option as I have done below. Lines do not get arrow heads be default.
  • The style of the arrow that you desire is -latex. So, just add that option when needed (as is the case for the orange line).
  • Added shorten <= and shorten >= to extend the orange line. Alternatively you could manully select points that are on the line.
  • The calc library was used to compute the midway coordinates with which the vertical black line was drawn.
  • I made the node labels to be in math mode by adding the $.
  • Colors added to make it easier to know which drawing command is doing what.

Code:

\documentclass{amsart}
\usepackage{tikz} 
\usetikzlibrary{calc}
\begin{document}
\begin{center}
\begin{tikzpicture}[thick]
    \node (p1) at ( 0, 0) {}; 
    \node (p2) at ( 1, -0.2) {$i$};
    \node (p3) at ( 3,0) {};
    \node (p4) at ( 0,1) {};
    \node (p5) at ( 2,1.2) {$n+j$};
    \node (p6) at ( 3,1) {};
    \coordinate (p1MidwayP3) at ($(p1)!0.5!(p3)$);
    \coordinate (p4MidwayP6) at ($(p4)!0.5!(p6)$);
    \begin{scope}%[every path/.style={-}]
       \draw [red] (p1) -- (p3); 
       \draw [blue] (p4) -- (p6);
       \draw [orange, shorten <=-0.08cm, shorten >=-0.10cm, -latex](p2) -- (p5);
       \draw  (p1MidwayP3) -- (p4MidwayP6);
    \end{scope}  
\end{tikzpicture}
\end{center}
\end{document}
0
1

A PSTricks solution, combined with xfp:

\documentclass{article}

\usepackage{pstricks-add}
\usepackage{xfp}

\begin{document}

\def\Horizontal{5} % length of the horizontal line segments
\def\Vertical{3}   % length of the vertical   line segment
\def\Indent{0.5}   % indentation of the arrow from both sides
\begin{pspicture}(0,-0.4)(\Horizontal,\fpeval{\Vertical+0.45})
  \psline(0,0)(\Horizontal,0)
  \psline(0,\Vertical)(\Horizontal,\Vertical)
  \psline(\fpeval{\Horizontal/2},0)(\fpeval{\Horizontal/2},\Vertical)
  \psline{->}(\Indent,0)(\fpeval{\Horizontal-\Indent},\Vertical)
  \uput[270](\Indent,0){$i$}
  \uput[90](\fpeval{\Horizontal-\Indent},\Vertical){$n+j$}
\end{pspicture}

\end{document}

output

All you have to do is choose the values of \Horizontal, \Vertical, and \Indent and the drawing will be adjusted accordingly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .