如何将自定义的 mdframed 定理框并排放置?

如何将自定义的 mdframed 定理框并排放置?

我有自定义定理框,其中一些我想放在一起。我尝试使用wrapfigminipage和,但都不起作用。请参阅下面的代码multicol subfigtabular

\documentclass[a4paper, 10pt]{scrartcl}

\usepackage{tikz}%
\usepackage{pgfplots}%
\pgfplotsset{compat=1.13}%
\usepackage{graphicx}%
\usepackage{lipsum}

\usepackage{multicol}
\columnsep=30pt

\usepackage{subcaption}%

\usepackage{amsmath, amssymb, amsthm}%
\usepackage[framemethod=default]{mdframed}%
\usepackage{wrapfig}%
\setlength{\intextsep}{0pt}%

\newtheoremstyle{myStyle}%                % Name
  {0pt}%                                  % Space above
  {0pt}%                                  % Space below
  {\small}%                               % Body font
  {}%                                     % Indent amount
  {\bf}%                                  % Theorem head font
  {\;}%                                   % Punctuation after theorem head
  {\newline}%                             % Space after theorem head, ' ', or \newline = Abstand nach rechts oder neue Zeile
  {}%                                     % Theorem head spec (can be left empty, meaning `normal')

\theoremstyle{myStyle}%
\newtheorem*{myBox}{Title}%

\newmdenv[skipabove=1pt,
skipbelow=9pt,
backgroundcolor=black!5,
linecolor=white,
innerleftmargin=10pt,
innerrightmargin=10pt,
innertopmargin=10pt,
leftmargin=0cm,
rightmargin=0cm
innerbottommargin=10pt,
nobreak=true]{grayBoxNoBorder}%


\newenvironment{myBoxLeft}{\wrapfigure{l}{.45\textwidth}\begin{grayBoxNoBorder}\begin{myBox}}{\end{myBox}\end{grayBoxNoBorder}\endwrapfigure}%
\newenvironment{myBoxRight}{\wrapfigure{r}{.45\textwidth}\begin{grayBoxNoBorder}\begin{myBox}}{\end{myBox}\end{grayBoxNoBorder}\endwrapfigure}%
\newenvironment{myBoxFull}{\wrapfigure{l}{\textwidth}\begin{grayBoxNoBorder}\begin{myBox}}{\end{myBox}\end{grayBoxNoBorder}\endwrapfigure}%
\newenvironment{myBoxHalf}{\wrapfigure{l}{.5\textwidth}\begin{grayBoxNoBorder}\begin{myBox}}{\end{myBox}\end{grayBoxNoBorder}\endwrapfigure}%

\begin{document}

% First try
\begin{myBoxLeft}
\lipsum[2]
\end{myBoxLeft}
\begin{myBoxRight}
\lipsum[2]
\end{myBoxRight}
\clearpage
% Second try
\begin{minipage}{.45\textwidth}
\begin{myBoxFull}
\lipsum[2]
\end{myBoxFull}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{myBoxFull}
\lipsum[2]
\end{myBoxFull}
\end{minipage}
\clearpage
% Third try
\begin{multicols}{2}
\begin{myBoxHalf}
\lipsum[2]
\end{myBoxHalf}
\columnbreak
\begin{myBoxHalf}
\lipsum[2]
\end{myBoxHalf}
\end{multicols}

% \clearpage
%% Fourth try
% \begin{figure}
% \centering
% \begin{subfigure}{0.45\textwidth}
% \begin{myBoxFull}
% \lipsum[2]
% \end{myBoxFull}
% \end{subfigure}
% \begin{subfigure}{0.45\textwidth}
% \begin{myBoxFull}
% \lipsum[2]
% \end{myBoxFull}
% \end{subfigure}
% \end{figure}
%% doesn't work because error due to figure inside subfigure

\clearpage
% Fifth try
\begin{tabular}{ll}
\begin{minipage}{.45\textwidth}
\begin{myBoxFull}
\lipsum[2]
\end{myBoxFull}
\end{minipage}
&
\begin{minipage}{.45\textwidth}
\begin{myBoxFull}
\lipsum[2]
\end{myBoxFull}
\end{minipage}
\\
\end{tabular}

\end{document}

我该怎么做才能将它们并排放置?

答案1

如果您忘记了wrapping零件,mdframed可以轻松地将盒子并排排列minipage,,tabluar...

\documentclass[a4paper, 10pt]{scrartcl}

\usepackage{tikz}%
\usepackage{pgfplots}%
\pgfplotsset{compat=1.13}%
\usepackage{graphicx}%
\usepackage{lipsum}

\usepackage{multicol}
\columnsep=30pt

\usepackage{subcaption}%

\usepackage{amsmath, amssymb, amsthm}%
\usepackage[framemethod=default]{mdframed}%
\usepackage{wrapfig}%
\setlength{\intextsep}{0pt}%

\newtheoremstyle{myStyle}%                % Name
  {0pt}%                                  % Space above
  {0pt}%                                  % Space below
  {\small}%                               % Body font
  {}%                                     % Indent amount
  {\bfseries}%                                  % Theorem head font
  {\;}%                                   % Punctuation after theorem head
  {\newline}%                             % Space after theorem head, ' ', or \newline = Abstand nach rechts oder neue Zeile
  {}%                                     % Theorem head spec (can be left empty, meaning `normal')

\theoremstyle{myStyle}%
\newtheorem*{myBox}{Title}%

\newmdenv[skipabove=1pt,
skipbelow=9pt,
backgroundcolor=black!5,
linecolor=white,
innerleftmargin=10pt,
innerrightmargin=10pt,
innertopmargin=10pt,
leftmargin=0cm,
rightmargin=0cm
innerbottommargin=10pt,
nobreak=true]{grayBoxNoBorder}%


\newenvironment{myNewBox}{\begin{grayBoxNoBorder}\begin{myBox}}{\end{myBox}\end{grayBoxNoBorder}}%
%\newenvironment{myBoxRight}{\begin{grayBoxNoBorder}\begin{myBox}}{\end{myBox}\end{grayBoxNoBorder}}%
%\newenvironment{myBoxFull}{\wrapfigure{l}{\textwidth}\begin{grayBoxNoBorder}\begin{myBox}}{\end{myBox}\end{grayBoxNoBorder}\endwrapfigure}%
%\newenvironment{myBoxHalf}{\wrapfigure{l}{.5\textwidth}\begin{grayBoxNoBorder}\begin{myBox}}{\end{myBox}\end{grayBoxNoBorder}\endwrapfigure}%

\begin{document}

% First try
\noindent\begin{minipage}{.475\textwidth}
\begin{myNewBox}
\lipsum[2]
\end{myNewBox}
\end{minipage}\hfill\begin{minipage}{.475\textwidth}
\begin{myNewBox}
\lipsum[2]
\end{myNewBox}
\end{minipage}

\begin{myNewBox}
\lipsum[2]
\end{myNewBox}

\begin{multicols}{2}
\begin{myNewBox}
\lipsum[2]
\end{myNewBox}
\columnbreak
\begin{myNewBox}
\lipsum[2]
\end{myNewBox}
\end{multicols}

\end{document}

在此处输入图片描述

相关内容