在文本背景中渲染纹理

在文本背景中渲染纹理

我想在我的 latex 文档中渲染一些文本,并在背景中添加一些带纹理的框。就像附图中那样。我尝试了“tcolor”框包,但我认为它不允许你在文本背景中渲染带纹理的框。

关于我应该如何进行这项任务,有什么建议吗?

蓝盒子3

蓝盒子2

蓝盒1

答案1

Martin Scharrer 的回答略有修改这里应该可以解决问题:

\documentclass{article}

\usepackage{graphicx}

\newlength{\imgwidth}
\newlength{\imgtocenter}


\newsavebox\mysavebox
\newenvironment{imgminipage}[2][]{%
   \def\imgcmd{%
    \settowidth{\imgwidth}{\includegraphics[width=\wd\mysavebox,height=\dimexpr\ht\mysavebox+\dp\mysavebox\relax,#1]{#2}}%
    \setlength{\imgtocenter}{\dimexpr(0.5\wd\mysavebox-0.5\imgwidth)\relax}%
    \hspace*{\imgtocenter}%
    \includegraphics[width=\wd\mysavebox,height=\dimexpr\ht\mysavebox+\dp\mysavebox\relax,#1]{#2}}%
   \begin{lrbox}{\mysavebox}%
   \begin{minipage}%
}{%
   \end{minipage}%
   \end{lrbox}%
   \sbox\mysavebox{\fbox{\usebox\mysavebox}}%
   \mbox{\rlap{\raisebox{-\dp\mysavebox}{\imgcmd}}\usebox\mysavebox}%
}

\begin{document}

\noindent
\begin{imgminipage}[keepaspectratio]{example-image-a}{0.5\linewidth}
    Some text\\
    Hello world!
\end{imgminipage}

\noindent
\begin{imgminipage}{example-image-b}{\linewidth}
    Some more text\\
    Hello world!
\end{imgminipage}

\end{document}

结果

相关内容