迷你页面的背景图片

迷你页面的背景图片

我想将背景图像放入迷你页面,并精确拉伸到周围的 fbox。最好的选择是什么?(在网上搜索,我只找到了将整个页面设为背景的解决方案)

答案1

您基本上需要将minipage内容存储在一个框寄存器中,测量它并将其与图形叠加。以下环境等待图像文件名作为第一个参数,然后接受任何minipage参数:

\documentclass{article}

\usepackage{graphicx}

\newsavebox\mysavebox
\newenvironment{imgminipage}[2][]{%
   \def\imgcmd{\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}

\begin{imgminipage}{imagefilename}{5cm}
    Some text\\
    Hello world!
\end{imgminipage}

\end{document}

结果


我现在添加了一个bgimage密钥adjustbox(开发版本),它允许您添加背景图像。也可以使用\fbox以下任一方法:

\begin{adjustbox}{minipage=<width>,fbox,bgimage=<image>}
    <text>
\end{adjustbox}

添加\fbox第一个图像,然后将背景图像放在其后面,以便框架覆盖图像的一小部分,或者

\begin{adjustbox}{minipage=<width>,margin=\fboxsep,bgimage=<image>,frame}
    <text>
\end{adjustbox}

它手动添加相同的边距,放置背景图像,然后在其周围绘制一个紧密的框架,以便完全显示图像(并且比以前小一点)。

答案2

\documentclass{article} 
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{blindtext}
\newsavebox\MBox
\newenvironment{Minipage}[1]
  {\par\smallskip\begin{lrbox}{\MBox}\begin{minipage}{#1}}
  {\end{minipage}\end{lrbox}%
   \makebox(0,0){\put(0,0){%
     \includegraphics[width=\wd\MBox,height=2\ht\MBox]{tiger}}}%
   \usebox\MBox\par%
  }
\begin{document}
Some text before

\begin{Minipage}{0.5\textwidth} 
\blindtext
\end{Minipage}

Some text behind    
\end{document}

在此处输入图片描述

答案3

编辑:

这里对包进行了修改。因此,您可以根据背景图像mdframed使用提供的所有设置:mdframed

\documentclass{article} 
\usepackage[english]{babel}
\usepackage{graphicx,tikz}
\usepackage{blindtext}
\usepackage[backgroundcolor=yellow!10,style=0]{mdframed}
\makeatletter
\newrobustcmd*\mdf@backgroundimage{%
      \rlap{\hspace*{0.5\mdfboundingboxwidth}%
             \makebox[0pt][c]{%
               \tikz[remember picture]%
                  \node (0,0) [opacity=0.4] {%
                  \includegraphics[width=\mdfboundingboxwidth,%
                                height=\mdfboundingboxheight,%
                                keepaspectratio]%
                                {\backgroundimage}%
                              };
             }%
           }%
}
\newenvironment{Minipage}[2][]
  {\def\backgroundimage{#2}%
   \appto\md@frame@background@single\mdf@backgroundimage%
   \appto\md@frame@background@first\mdf@backgroundimage%
   \appto\md@frame@background@middle\mdf@backgroundimage%
   \appto\md@frame@background@second\mdf@backgroundimage%
   \begin{mdframed}[#1]%
   }
  {\end{mdframed}}
\makeatother
\begin{document}
Some text before

\begin{Minipage}{tiger} 
\blindtext
\end{Minipage}

Some text behind    

\begin{Minipage}{tiger} 
\blindtext[10]
\end{Minipage}
\end{document}

编辑2感谢 xport — 我opacity通过使用添加了该选项tikz

在此处输入图片描述

一种可能性是minipage与相结合includegraphics。我尝试使用以下配置(选项democolor{red}。所以我可以在没有任何图像的情况下进行编译:-)

\documentclass[demo]{article}
\usepackage{adjustbox}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{lipsum}
\newlength{\widthofminipage}
\newsavebox{\MyMinBackBox}
% minipageback{<width>}{<backgroundimage>}
\newenvironment{minipageback}[2]{%
      \setlength{\widthofminipage}{#1}%
      \def\pictureminback{#2}%
      \begin{lrbox}{\MyMinBackBox}%
      \begin{minipage}[b]{\widthofminipage}\color{red}%
    }{%
     \end{minipage}\end{lrbox}%
     \includegraphics[width=\wd\MyMinBackBox,height=\dimexpr\ht\MyMinBackBox+\dp\MyMinBackBox\relax]{\pictureminback}%
    \llap{\usebox{\MyMinBackBox}}%
}

\begin{document}
Text 


\begin{minipageback}{.5\textwidth}{logo}
\lipsum[1]
\end{minipageback}
\end{document}

答案4

特征:可以调整不透明度以使其不会分散前景文本的注意力。

使用xelatex或编译以下内容latex-dvips-ps2pdf

在此处输入图片描述

\documentclass{article}
\usepackage[a4paper,margin=2cm,showframe=false]{geometry}
\usepackage{graphicx}
\usepackage{pst-node}
\newsavebox\IBox
\newenvironment{TinyPage}[2][1]
    {\def\scale{#1}\begin{lrbox}{\IBox}\begin{minipage}{\dimexpr#2\linewidth-2\fboxsep-2\fboxrule\relax}\ignorespaces}
    {%
        \end{minipage}\end{lrbox}%              
        \rput(\dimexpr0.5\wd\IBox+\fboxsep+\fboxrule\relax,0){%
                \special{ps: 0.2 .setopacityalpha}%
                \scalebox{\scale}[1]{\includegraphics[width=\wd\IBox]{Images/hen}}%
                \special{ps: 1 .setopacityalpha}}%
        {\color{gray}\fbox{\usebox\IBox}}%
        \ignorespacesafterend}

\parindent=0pt
\fboxsep=10pt
\fboxrule=10pt
\usepackage{lipsum}

\begin{document}
\lipsum[1]

\vspace{3mm}

\begin{TinyPage}[-1]{0.49}
\lipsum[1]
\end{TinyPage}\hfill
\begin{TinyPage}{0.49}
\lipsum[1]
\end{TinyPage}

\vspace{3mm}

\lipsum[1]
\end{document}

相关内容