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

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

2 Answers 2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.