1

I have custom theorem boxes which, some of them, I want to be placed next to each other. I tried using wrapfig, minipage, multicol subfig and tabular, but got none of them to work. Please see code below.

\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}

What can I do to place them side by side?

  • You can't overlap two wrapfigures, and from what I can tell you shouldn't be using them at all. What exactly are you trying to accomplish? Place theorems next to each other? Theorems to the left of images, or images to the left of theorems? – John Kormylo Jun 19 '17 at 22:39
  • Thanks for the comment. I am trying to put two theorems next to each other. – jmjr Jun 20 '17 at 16:45
  • I'm sorry, but I don't get it to work with minipage. Please see second try in my MWE. minipages are contiguous. Either it doesn't help adding a % after first \end{minipage}. I also tried with \hfill and [t] top aligned, but the result keeps being one box beneath the other and not next to each other. Any ideas? – jmjr Jun 21 '17 at 10:08
2

If you forget the wrapping part, mdframed boxes are easily arranged side by side with 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}

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.