5

I build a minipage with some background picture:

\newsavebox\langscapeSafebox
\newenvironment{dsaBoxLandscape}[1][]{%
\def\imgcmd{\includegraphics[width=\wd\langscapeSafebox,height=\dimexpr\ht\langscapeSafebox+\dp\langscapeSafebox\relax,#1]{images/box-landscape.png}}%
   \begin{lrbox}{\langscapeSafebox}%
   \begin{minipage}%
}{%
   \end{minipage}
   \end{lrbox}%
   \sbox\langscapeSafebox{\usebox\langscapeSafebox}%
   \mbox{\rlap{\raisebox{-\dp\langscapeSafebox}{\imgcmd}}\usebox\langscapeSafebox}%
}

% somewhere in the document:

\begin{dsaBoxLandscape}{14cm}
   Some content
\end{dsaBoxLandscape}

Now I want to have some padding at each side (top, down, left, right) inside the minipage so that the content does not overlap with the styled border part of the background image. How can I do that?

  • The code will give an error, because the mandatory argument to \begin{minipage} is missing. Can you show a complete example? – egreg Jan 26 '14 at 15:15
  • @egreg: \begin{minipage} inherits the argument from the environment dsaBoxLandscape that has an optional argument and the arguments for minipage. – Heiko Oberdiek Jan 26 '14 at 16:39
  • @HeikoOberdiek That's why I asked for a complete example. – egreg Jan 26 '14 at 16:54
  • @JohnKormylo: That question is about drawing a border around an lrbox. I already have a border, it's part of my background image. I just want to add spacing to the content of the box so that it doesn't overlap to the border of the background image. @egreg: I'll add more code later, I don't have it here right now. – flyx Jan 27 '14 at 6:47
3

I've added the padding in the size of \fboxsep. The draft option is to show just a frame instead of the image, the string duck.jpg is just the file name I used for the example.

The padding is outside the left margin, remove the \hspace{-\fboxsep} and add \hspace{\fboxsep} before \usebox if you want to push right the inner box instead.

I removed the useless \sbox{\langscapeSafebox}{\usebox{\langscapeSafebox}} that simply resets the box to itself.

\documentclass{article}
\usepackage{lipsum} % just for the example
\usepackage[draft]{graphicx} % draft is just for the example

\newsavebox\langscapeSafebox
\newenvironment{dsaBoxLandscape}[2][]{%
  \def\imgcmd{%
    \includegraphics[
      width=\dimexpr\wd\langscapeSafebox+2\fboxsep\relax,
      height=\dimexpr\ht\langscapeSafebox+\dp\langscapeSafebox+2\fboxsep\relax,
      #1
    ]{images/box-landscape.png}}%
  \begin{lrbox}{\langscapeSafebox}%
  \begin{minipage}{#2}
}{%
   \end{minipage}
   \end{lrbox}%
   \noindent
   \makebox[0pt][l]{%
     \hspace{-\fboxsep}%
     \raisebox{\dimexpr-\dp\langscapeSafebox-\fboxsep}{\imgcmd}%
   }%
   \usebox\langscapeSafebox
}

\begin{document}

\lipsum[2]

\begin{dsaBoxLandscape}{\textwidth}
Some content

and some other
\end{dsaBoxLandscape}

\lipsum[3]

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.