以下是我的 MWE这里:
\documentclass[varwidth]{standalone}
\usepackage{ eso-pic,tikz, lipsum}
\usetikzlibrary{tikzmark}
\linespread{2}
\newcommand\BackgroundPic{%
\begin{tikzpicture}[overlay,remember picture]
\node[anchor=north west,inner sep=0pt, rounded corners=10pt] at ([yshift=8pt]pic cs:start) {%
\includegraphics[width=\textwidth]{example-image}};
\end{tikzpicture}}
\begin{document}
\AddToShipoutPicture*{\BackgroundPic}
\tikzmark{start}\lipsum[1-1]\tikzmark{end}
\end{document}
我希望背景图像有圆角。但是它不行。
如何获得带圆角的背景图像?
答案1
另一个解决方案是tcolorbox
。由于blankest
选项抑制圆角,其效果已使用boxsep=0t
和其他几何参数进行了模拟。
\documentclass[tikz, border=2mm]{standalone}
\usepackage{graphicx, lipsum}
\usepackage[most]{tcolorbox}
\newtcolorbox{myminipage}[3][]{
enhanced,
% blankest,
% rounded corners,
boxsep=0pt,
left=0pt,
right=0pt,
top=0pt,
bottom=0pt,
width=#2,
underlay={\begin{tcbclipframe}
\node at (frame) {\includegraphics{#3}};
\end{tcbclipframe}},
#1
}
\begin{document}
\begin{myminipage}{3cm}{example-image}
This is some text not so long like \texttt{\textbackslash{}lipsum[2]}
\end{myminipage}
\begin{myminipage}{10cm}{example-image}
\lipsum[2]
\end{myminipage}
\end{document}
答案2
clip
一起使用rounded corners
,同时包含图像。
\documentclass[varwidth,border=10pt]{standalone}
\usepackage{calc}
\usepackage{ eso-pic,tikz, lipsum}
\usetikzlibrary{tikzmark}
\linespread{2}
\newcommand\BackgroundPic{%
\begin{tikzpicture}[overlay,remember picture]
\node[anchor=north west,inner sep=0pt, clip, rounded corners=20pt] at ([yshift=15pt,xshift=-5pt]pic cs:start) {%
\includegraphics[width=\textwidth+10pt]{example-image}};
\end{tikzpicture}}
\begin{document}
\AddToShipoutPicture*{\BackgroundPic}
\tikzmark{start}\lipsum[1-1]\tikzmark{end}
\end{document}