I am trying to use \newcommand to reproduce a tikz diagram multiple times. When i make these diagrams manually, they are drawn appropriate, but when i reproduce them with \newcommand, they slightly go to right side. I have tried removing space by using \% at the end of tikzpicture, but that is not working for me. Here is the MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[left=2cm, right=5cm, top=2cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\newcommand{\tklines}[1]
{
\begin{tikzpicture}[red,overlay]
\draw (0,#1)--++(5,0);
\end{tikzpicture}%
}
\begin{document}
\begin{tikzpicture}[overlay]
\draw (0,0)--++(5,0);
\end{tikzpicture}%
\begin{tikzpicture}[overlay]
\draw (0,1)--++(5,0);
\end{tikzpicture}%
\begin{tikzpicture}[overlay]
\draw (0,2)--++(5,0);
\end{tikzpicture}
\hspace{5cm}
\tklines{0}
\tklines{1}
\tklines{2}
\end{document}
The result is displayed in following picture. See red lines going to right side. I have tried to search several time but I think i am missing something. Kindly help.
{
so put a space before each tikzpicture, use{%
\newcommand
third argument, but it does not solve the problem - lines are still going to the right side.