MWE 是
\documentclass{book}
\usepackage{xcolor}
\pagecolor{red}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node [anchor=north,scope fading=south,inner sep=0pt,outer sep=0pt] at (current page.north) {\includegraphics[width=\paperwidth]{example-image-a.jpg}};
\end{tikzpicture}
\newpage
\begin{tikzpicture}[remember picture,overlay]
\node [anchor=north,inner sep=0pt,outer sep=0pt] at (current page.north) {\includegraphics[width=\paperwidth]{example-image-a.jpg}};
\end{tikzpicture}
\end{document}
当我使用scope fading=south
节点命令时,尽管我使用了选项,但在图像的右侧仍会有一个非常细的间隙inner sep=0pt, outer sep=0pt
,就像下面的截图一样
但是,如果我删除该选项scope fading=south
,间隙就会消失,就像下面的截图一样
那么,我怎样才能消除差距呢?
答案1
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt]
\node[preaction={draw, red}, draw, green, scope fading=south] (n) {\includegraphics[width=80cm]{example-image-a.jpg}};
\draw[blue] ([yshift=1pt]n.north west) -- +(80,0);
\end{tikzpicture}
\end{document}
右上角:
首先,fading
根据正确尺寸(红色)的图片制作一个。这fading
比图片小得多。(通过使用选项查看fit fading=false
)。fading transform
应用选项并拟合淡入淡出以填充区域。这种拟合/拉伸可能存在舍入误差。对于较大的淡入淡出,误差更明显,但不是系统性的。最后创建节点边界(绿色)。
在我看来,除了手动调整之外,没有其他好方法可以避免这种舍入误差
答案2
作为一种快速破解,你可以稍微增加图像的宽度:
\documentclass{book}
\usepackage{xcolor}
\pagecolor{red}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node [anchor=north,scope fading=south,inner sep=0pt,outer sep=0pt] at (current page.north) {\includegraphics[width=\dimexpr\paperwidth+1pt]{example-image-a.jpg}};
\end{tikzpicture}
\newpage
\begin{tikzpicture}[remember picture,overlay]
\node [anchor=north,inner sep=0pt,outer sep=0pt] at (current page.north) {\includegraphics[width=\paperwidth]{example-image-a.jpg}};
\end{tikzpicture}
\end{document}