我无法理解 TikZline width
和 之间的关系tikzpagenodes.sty
。(MacTeX2017,上周更新。)当我使用tikzpagenodes.sty
如下所示时,生成的线条会按 缩进line width
,从而导致 的溢出\hbox
量line width
。如果我使用 ,问题就会消失,remember picture,overlay
但这会将线条固定在我不想要的位置。
我确信我忽略了一些基本的东西。
\documentclass{article}
\usepackage{tikzpagenodes}
\begin{document}
\parindent0pt
\noindent
\begin{tikzpicture}[remember picture,overlay]
\draw[line width=18pt] (current page text area.north west) -- (current page text area.north east);
\end{tikzpicture}
\vspace{0.15in}
$\uparrow$ With \verb+\draw[remember picture,overlay]+
\vspace{0.5in}
$\leftarrow$ Left margin. With \verb+\draw[]+ $\downarrow$
\noindent
\begin{tikzpicture}[]
\draw[line width=18pt] (current page text area.north west) -- (current page text area.north east);
\end{tikzpicture}
\end{document}
答案1
TikZ 在计算边界框时,会在坐标周围添加当前线宽的一半,为线条留出空间。但是,这里只有一条水平线。因此,垂直间距是正确的,但默认的线帽样式是butt
,不是rect
,round
因此左右两侧的空间虽然增加了,但为空。
以下示例修复了环境末尾的边界框tikzpicture
:
\documentclass{article}
\usepackage{tikzpagenodes}
\begin{document}
\noindent
\begin{tikzpicture}[remember picture,overlay]
\draw[line width=18pt]
(current page text area.north west) --
(current page text area.north east)
;
\end{tikzpicture}
\vspace{0.15in}
$\uparrow$ With \verb+\draw[remember picture,overlay]+
\vspace{0.5in}
$\leftarrow$ Left margin. With \verb+\draw[]+ $\downarrow$
\noindent
\begin{tikzpicture}
\draw[line width=18pt]
(current page text area.north west) --
(current page text area.north east)
;
% Fix bounding box
\path
(current bounding box.south west) ++(9pt, 0) coordinate (ll)
(current bounding box.north east) ++(-9pt, 0) coordinate (ur)
\pgfextra{\pgfresetboundingbox}
(ll)
(ur)
;
\end{tikzpicture}
\end{document}
答案2
带有 [记住图片,覆盖] 的 tikzpicture 不占用水平空间,但它确实有一个位置。具体来说,(0,0) 将位于 tikzpicture 所在的基线处。
\documentclass{article}
\usepackage{tikzpagenodes}
\begin{document}
\parindent0pt
$\downarrow$ With \verb+\draw[remember picture,overlay]+
\noindent
\begin{tikzpicture}[remember picture,overlay]
\coordinate (origin) at (0,0);
\draw[line width=18pt] (current page text area.west |- origin) -- (current page text area.east |- origin);
\end{tikzpicture}
\end{document}