带有背景颜色的照片条纹跨越整个页面宽度?

带有背景颜色的照片条纹跨越整个页面宽度?

对于海报,我需要将三张照片放在一个条纹中(3x1 网格布局)。此外,条纹应该有颜色,以便填充照片之间的空白(以及相邻的边距)。

我的第一个方法是使用\centerlinetabucolortbl,但我无法让照片与边距正确对齐给它们上色。其次,我尝试了一个简单的tikzpicture,它有一些多余的间距(垂直和水平),我需要摆脱它。

因此,我创建了以下 MWE:

\documentclass[a4paper, 10pt]{scrartcl}

\usepackage[american]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\parindent0mm
\usepackage{showframe, mwe}
\usepackage{xcolor, colortbl}
\usepackage{graphicx}
\usepackage{tabu}

\usepackage{tikz}
\usetikzlibrary{matrix, positioning, shapes, backgrounds}
\newlength\pictureheight
\setlength{\pictureheight}{30mm}

\begin{document}
\pagestyle{empty}

\lipsum[2]
\medskip
%% Fotostreifen mit tabu
\centerline
{
\tabulinesep^0.1pt_0pt
\begin{tabu}to \textwidth[c]{@{}X[l,m,2] X[c,m,1.5] X[r,m,2] @{}}
\rowcolor{blue}
\includegraphics[height=\pictureheight]{example-image-16x9} &
\includegraphics[height=\pictureheight]{example-image-16x10} &
\includegraphics[height=\pictureheight]{example-image-16x9}
\\
\end{tabu}
}

\medskip
\lipsum[2]

\centerline
{
\begin{tikzpicture}[node distance=0mm and 0mm, show background rectangle, 
  background rectangle/.style={fill=blue}, anchor=center]
\node(lRand) at (0,1)[shape=rectangle, color=blue]{};
\node(bild1) at (1.27,0)[anchor=south west]
{\includegraphics[height=\pictureheight]{example-image-16x9}};
\node(bild2) at (10.5,0)[anchor=south]
{\includegraphics[height=\pictureheight]{example-image-16x10}};
\node(bild3) at (19.73,0)[anchor=south east]
{\includegraphics[height=\pictureheight]{example-image-16x9}};
\node(rRand) at (21,1)[shape=rectangle, color=blue]{};
\end{tikzpicture}
}

\medskip
\lipsum[2]
\end{document}

它看起来是这样的: 照片条纹背景颜色

我希望像第一个示例(使用tabu)那样排列图像,颜色垂直裁剪,但背景颜色框跨越整个页面宽度,如第二个示例(使用TikZ)所示。有什么想法吗?

答案1

这里还有另外两种方法。第一种方法是将整个图像放在tabu一个节点内,第二种方法是tikzpagenodes将每个图像相对于(current page text area)节点放置。

注意:需要运行两次才能[remember picture]起作用。

\documentclass[a4paper, 10pt]{scrartcl}

\usepackage[american]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\parindent0mm
\usepackage{showframe, mwe}
\usepackage{xcolor, colortbl}
\usepackage{graphicx}
\usepackage{tabu}

\usepackage{tikzpagenodes}
\usetikzlibrary{matrix, positioning, shapes, backgrounds}
\newlength\pictureheight
\setlength{\pictureheight}{30mm}

\begin{document}
\pagestyle{empty}

\lipsum[2]
\medskip
%% Fotostreifen mit tikz

\begin{tikzpicture}[remember picture]
\node[inner sep=0pt, outer sep=5pt] (A)% outer sep conmtrols top/bottom margin
{\parbox{\textwidth}{% not sure why this is needed
  \tabulinesep^0.1pt_0pt
  \begin{tabu}to \textwidth[c]{@{}X[l,m,2] X[c,m,1.5] X[r,m,2] @{}}
  \includegraphics[height=\pictureheight]{example-image-16x9} &
  \includegraphics[height=\pictureheight]{example-image-16x10} &
  \includegraphics[height=\pictureheight]{example-image-16x9}
  \\
  \end{tabu}}%
};
\path (A.south) -- (A.north);% reserve space for overlay
\begin{scope}[on background layer, overlay]
  \fill[blue] (A.south-|current page.west) rectangle (A.north-|current page.east); 
\end{scope}
\end{tikzpicture}

\medskip
\lipsum[2]

\begin{tikzpicture}[remember picture]
\coordinate (origin) at (0,0);
\node[right, inner sep=0pt] at (origin-|current page text area.west)
  {\includegraphics[height=\pictureheight]{example-image-16x9}};
\node[inner sep=0pt, outer sep=5pt] (A) at (origin-|current page text area.center)
  {\includegraphics[height=\pictureheight]{example-image-16x10}};
\node[left, inner sep=0pt] at (origin-|current page text area.east)
  {\includegraphics[height=\pictureheight]{example-image-16x9}};
\path (A.south) -- (A.north);% reserve space for overlay
\begin{scope}[on background layer, overlay]
  \fill[blue] (A.south-|current page.west) rectangle (A.north-|current page.east); 
\end{scope}
\end{tikzpicture}

\medskip
\lipsum[2]
\end{document}

相关内容