
Estoy haciendo algunas divisiones de secciones en una hoja de estilo usando tikz
. Sin embargo, aunque empiezo a dibujar la línea, (0,0)
tiene un desplazamiento con respecto al borde del contenido de la página real. También lo configuré \parindent
y todavía no está perfectamente alineado. ¿Cómo puedo forzar que la línea comience (y termine) exactamente en los bordes?
Aquí hay un ejemplo mínimo del problema:
\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}
Respuesta1
Lo descubrí gracias a @JouleV que señaló esta pregunta:Una línea de longitud \textwidth en TikZ.
Lo siguiente resuelve el problema:
\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}}
Respuesta2
Una solución es usarla \clip
para evitar espacio adicional alrededor del dibujo, pero creo que una solución más simple es llenar un rectángulo delgado en su lugar para dibujar una línea:
\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}