# Drawing a rectangular contour for Complex Integration

I want to draw the following diagram:

I tried the following code :

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[decoration={markings,
mark=at position 1cm   with {\arrow[line width=1pt]{stealth}},
mark=at position 4.5cm with {\arrow[line width=1pt]{stealth}},
mark=at position 7cm   with {\arrow[line width=1pt]{stealth}},
mark=at position 9.5cm with {\arrow[line width=1pt]{stealth}}
}]
\draw[thick, ->] (-6,0) -- (6,0) coordinate (xaxis);

\draw[thick, ->] (0,0) -- (0,6) coordinate (yaxis);

\node[above] at (xaxis) {$\mathrm{Re}(s)$};

\node[right]  at (yaxis) {$\mathrm{Im}(s)$};

\path[draw,blue, line width=0.8pt, postaction=decorate] (-4,4)
-- node[midway, above, black] {$C_1$} (4,4)
-- node[midway, right, black] {$C_N$}(4,0)
-- node[midway, left, black] {$C_2$} (-4,0)
-- node[midway, above, black] {$C_N$}(-4,4);
\end{tikzpicture}
\end{document}


And I get:

How do I get the orientation of the arrows right and the markings on the $x$-axis?

Thanks for the help!!

As a "hack" way to fix it... you can use \arrowreversed instead of \arrow.

I also moved where the nodes are declared, to make it more clear that you can add more than one node at the same place in a path. Using the position options, it gives you fine control over where you can place them.

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[decoration={markings,
mark=at position 1cm   with {\arrowreversed[line width=1pt]{stealth}},
mark=at position 4.5cm with {\arrowreversed[line width=1pt]{stealth}},
mark=at position 7cm   with {\arrowreversed[line width=1pt]{stealth}},
mark=at position 9.5cm with {\arrowreversed[line width=1pt]{stealth}}
}]
\draw[thick, ->] (-6,0) -- (6,0) coordinate (xaxis);

\draw[thick, ->] (0,0) -- (0,6) coordinate (yaxis);

\node[above] at (xaxis) {$\mathrm{Re}(s)$};

\node[right]  at (yaxis) {$\mathrm{Im}(s)$};

\path[draw,blue, line width=0.8pt, postaction=decorate]
(-4,4)
--  (4, 4)  node[midway, above right, black] {$C_1$}
--  (4, 0)  node[midway, right, black] {$C_N$} node[below, black] {$R$}
--  (-4,0)  node[midway, below, black] {$C_2$} node[below, black] {$-R$}
--  (-4,4)  node[midway, left, black] {$C_N$};
\end{tikzpicture}
\end{document}


• How do I mark $(R,0)$ and $(-R,0)$? – tattwamasi amrutam Jan 25 '18 at 10:27
• @tattwamasiamrutam, look at the answer now. I have modified it to add the $R$ and $-R$ nodes. And moved the node commands to make it more clear – Alex Recuenco Jan 25 '18 at 10:38