1

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:Illustration of the problem

Bernard
  • 271,350

2 Answers2

2

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}}
0

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}

enter image description here

Kpym
  • 23,002