我从上一个问题中找到了如何使用 Mdframe 自定义文本框的示例。我很难将文本框居中,
\documentclass[11.5pt]{report}
\usepackage[usenames,dvipsnames] {xcolor}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{shadows}
\usepackage{environ}
\usepackage{varwidth}
\newlength{\MyMdframedWidthTweak}%
\NewEnviron{MyMdframed}[1][]{%
\setlength{\MyMdframedWidthTweak}{\dimexpr%
+\mdflength{innerleftmargin}
+\mdflength{innerrightmargin}
+\mdflength{leftmargin}
+\mdflength{rightmargin}
}%
\savebox0{%
\begin{varwidth}{\dimexpr\linewidth-\MyMdframedWidthTweak\relax}%
\BODY
\end{varwidth}%
}%
\begin{mdframed}[
backgroundcolor=lightgray,
shadow=true,
shadowsize=4pt,
roundcorner=5pt,
userdefinedwidth=\dimexpr\wd0+\MyMdframedWidthTweak\relax,
#1]
\usebox0
\end{mdframed}
}
\begin{document}
\begingroup
\centering
\begin{minipage}[c]{5in}
\begin{MyMdframed}[backgroundcolor=blue!10]
blah blah blah
\end{MyMdframed}
\end{minipage}
\endgroup
\end{document}
它给了我一个框,但它只会左对齐页面。我怎样才能自由调整整个框的对齐方式?
答案1
我自己想出了这个办法。我所要做的就是在背景颜色选项旁边添加“align=center”。所以
\begin{MyMdframed}[backgroundcolor=blue!10, align=center]
blah blah blah
\end{MyMdframed}