按照此答案 (小页面背景图片) 我在显示背景图像时遇到问题,下面的示例没有显示任何图像痕迹,我该如何修复它。
\documentclass{article}
\usepackage{graphicx,tikz}
\usepackage{lipsum}
\usepackage[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]%
{example-image}%
};
}%
}%
}
\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%
\makeatother
\begin{document}
Some text before
\begin{mdframed}
\lipsum[1-2]
\end{mdframed}
Some text behind
\end{document}
答案1
控制台输出清楚地描述了问题并提出了解决方案。这些信息也将在您的.log
文件中。这就是此输出的内容。为了:告诉你有用的东西!
Package mdframed Warning: package option style is depreciated
at this point and will be ignored
use framemethod instead
(mdframed) on input line 382.
这告诉您一些重要信息:该包已更改,您的请求已被忽略。它还向您指出了等效功能。
快速浏览文档中的示例可以获得更成功的结果,因此如果您的猫因为您没有阅读手册而离开家,请不要责怪它的作者。
\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{backgrounds}
\mdfdefinestyle{mystyle}{%
apptotikzsetting={%
\tikzset{mdfbackground/.style={},}
},
singleextra={%
\scoped[on background layer]{\node [xshift=.5*\mdfboundingboxwidth, yshift=.5*\mdfboundingboxheight, opacity=.4] {\includegraphics[width=\mdfboundingboxwidth, height=\mdfboundingboxheight, keepaspectratio]{cath-gadael-chartref}};}
},
}
\begin{document}
Some text before
\begin{mdframed}[style=mystyle]
\lipsum[1-2]
\end{mdframed}
Some text behind
\end{document}
答案2
我会放弃 mdframed。使用 tcolorbox 插入这样的背景图像要容易得多:
\documentclass{article}
\usepackage{graphicx,tikz}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\begin{document}
Some text before
\begin{tcolorbox}[enhanced,
watermark graphics=example-image-a,
watermark stretch=1.00]]
\lipsum[1-2]
\end{tcolorbox}
Some text behind
\end{document}