3

I want to use an arbitrary number of mdframed boxes in a multicol environment. Each column should have the same height, which means the ends of the last box in each column should match (see figure below).

In my specific example, I want to put 5 mdframed boxes in a 3 column multicols environment. I tried to adjusted the heights of the boxes by using minipages as suggested here.

Here is a complete code example:

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{multicol}

\newlength{\columnheight}
\setlength{\columnheight}{10cm}

\begin{document}
\centering
\begin{multicols}{3}
% First Column
\begin{minipage}[t][\columnheight][t]{0.9\linewidth}
  \begin{mdframed}
    \begin{minipage}[t][0.6\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
            \item Point 2
        \item Point 3
      \end{itemize}
    \end{minipage}
  \end{mdframed}
  \vfill
  \begin{mdframed}
    \begin{minipage}[t][0.2\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
      \end{itemize}
    \end{minipage}
  \end{mdframed}
\end{minipage}
\columnbreak
% Second Column
\begin{minipage}[t][\columnheight][t]{0.9\linewidth}
  \begin{mdframed}
    \begin{minipage}[t][0.4\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
        \item Point 2
      \end{itemize}
    \end{minipage}
  \end{mdframed}
  \vfill
  \begin{mdframed}
    \begin{minipage}[t][0.4\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
        \item Point 2
      \end{itemize}
    \end{minipage}
  \end{mdframed}
\end{minipage}
\columnbreak
% Third Column
\begin{minipage}[t][\columnheight][t]{0.9\linewidth}
  \begin{mdframed}
    \begin{minipage}[t][\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
      \end{itemize}
    \end{minipage}
  \end{mdframed}
  \vfill
\end{minipage}
\columnbreak
\end{multicols}

\end{document}

The result looks as follows:

Result

As you can see in the picture, the right column is larger than the other ones. Is there a way to solve this automatically? Up till now, I use vspaces to adjust the margin between the boxes in the other two columns until the lengths match. Is there a more elegant way to do this? I already tried to adjust values such as skipbelow or skipabove of the boxes, but it doesn't help.

1

In your 3rd column, you use 2 nested minipages. The inner one is the full column height and then you add a frame about it, which actually forces the outer minipage to be larger than the column height. If these were mere \fboxes, one would need to subtract 2\fboxsep and 2\fboxrule from the height of the inner minipage.

But in mdframed, I did it the following way. I defined these in the preamble:

\newlength\innermarg
\innermarg 4pt\relax
\newlength\outerlinewidth
\outerlinewidth 3pt\relax
\mdfsetup{outerlinewidth=\outerlinewidth, innertopmargin=\innermarg, 
  innerbottommargin=\innermarg, outermargin=0pt}

Then, for the inner minipage of the 3rd column,

\begin{minipage}[t][\columnheight-2\outerlinewidth-2\innermarg][t]{0.9\linewidth}

In this way, the frame border and width are subtracted off, so you don't overflow. Note that package calc is required for my syntax.

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{multicol}
\usepackage{calc}
\newlength{\columnheight}
\setlength{\columnheight}{10cm}
\newlength\innermarg
\innermarg 4pt\relax
\newlength\outerlinewidth
\outerlinewidth 3pt\relax
\mdfsetup{outerlinewidth=\outerlinewidth, innertopmargin=\innermarg, 
  innerbottommargin=\innermarg, outermargin=0pt}
\begin{document}
\centering
\begin{multicols}{3}
% First Column
\begin{minipage}[t][\columnheight][t]{0.9\linewidth}
  \begin{mdframed}
    \begin{minipage}[t][0.6\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
            \item Point 2
        \item Point 3
      \end{itemize}
    \end{minipage}
  \end{mdframed}
  \vfill
  \begin{mdframed}
    \begin{minipage}[t][0.2\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
      \end{itemize}
    \end{minipage}
  \end{mdframed}
\end{minipage}
\columnbreak
% Second Column
\begin{minipage}[t][\columnheight][t]{0.9\linewidth}
  \begin{mdframed}
    \begin{minipage}[t][0.4\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
        \item Point 2
      \end{itemize}
    \end{minipage}
  \end{mdframed}
  \vfill
  \begin{mdframed}
    \begin{minipage}[t][0.4\columnheight][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
        \item Point 2
      \end{itemize}
    \end{minipage}
  \end{mdframed}
\end{minipage}
\columnbreak
% Third Column
\begin{minipage}[t][\columnheight][t]{0.9\linewidth}
  \begin{mdframed}
    \begin{minipage}[t][\columnheight-2\outerlinewidth-2\innermarg][t]{0.9\linewidth}
      \begin{itemize}
        \item Point 1
      \end{itemize}
    \end{minipage}
  \end{mdframed}
%  \vfill
\end{minipage}
\columnbreak
\end{multicols}

\end{document}

enter image description here

Note: there still seems to be an ever-so-slight discrepancy in the last column height. I don't have time to track it down, but did find that subtracting an extra 0.8pt from the column height of the 3rd column works, even when the column height is changed to various values:

\begin{minipage}[t][\columnheight-2\outerlinewidth-2\innermarg-.8pt][t]{0.9\linewidth}
| improve this answer | |

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.