2

I want to render some text in my latex document with some textured box in background. Like the one in the attached images. I tried the "tcolor" box package, but I don't think it allows you to render textured box in background of the text.

Any suggestions on how should I proceed with this task?

Blue Box 3

Blue Box 2

BlueBox1

JVJ
  • 165

1 Answers1

1

A slightly modified version of Martin Scharrer's answer from here should do the trick:

\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}

result

nox
  • 4,160
  • 12
  • 26