Tikz figure alignment with page margins

I am making some section divisions in a style sheet using tikz. However, even though I start drawing the line at (0,0) it has an offset from the actual page content border. I also set \parindent and it still is not perfectly aligned. How can I force the line to start (and end) exactly at the borders?

Here's a minimal example of the problem:

\documentclass{article}

\usepackage[a4paper, left=14.111mm,right=14.111mm,top=14.111mm,bottom=14.111mm, showframe]{geometry}
\usepackage{tikz}

\newcommand{\linehalfhalf}{\begin{tikzpicture}[]%
\draw [line width=1.5mm ] (0,0) -- ({0.5\textwidth},0);
\draw [line width=0.5mm] ([yshift=+0.5mm]{0.5\textwidth},0) -- ([yshift=+0.5mm]{\textwidth},0) ;
\end{tikzpicture}}

\begin{document}
\setlength\parindent{0pt}
\linehalfhalf
\end{document}


And an illustration:

• Welcome to TeX.SE! This question is related to tex.stackexchange.com/q/479079/156344, I think. – user156344 Mar 17 at 17:00
• @JouleV, thank you, that pointed me in a good direction – Aleksandar Petrov Mar 17 at 17:37
• You should also add a % at the end of \setlength\parindent{0pt}. – John Kormylo Mar 17 at 19:51

I figured it out thanks to @JouleV pointing out this question: A line of length \textwidth in TikZ.

The following resolves the problem:

\newcommand{\linehalfhalf}{\begin{tikzpicture}[]%
\draw [line width=1.5mm, cap=rect] (0,0) -- ({0.5\linewidth},0);
\draw [line width=0.5mm, cap=rect] ([yshift=+0.5mm]{0.5\linewidth-\pgflinewidth},0) -- ([yshift=+0.5mm] \linewidth-0.5mm-\pgflinewidth,0) ;
\end{tikzpicture}}


One solution is to use \clip to avoid extra space around your drawing, but I think that a simpler solution is to fill a thin rectangle in place to draw a line :

\documentclass{article}

\usepackage[a4paper, margin=14.111mm, paper height=5cm,showframe]{geometry}
\usepackage{tikz}

\newcommand{\linehalfhalf}{\begin{tikzpicture}[]%
\fill (0,0) rectangle (.5\textwidth,1.5mm);
\fill (0.5\textwidth,.5mm) rectangle (\textwidth,1mm) ;
\end{tikzpicture}}

\begin{document}%
\setlength\parindent{0pt}%
\linehalfhalf
\end{document}