3

I want to create three tables (using the tabular environment) side-by-side in a tcolorbox environment, each of which start and end at the same height. Strangely, the third column always shows up a little further south than the first two columns (which are properly, vertically aligned). I've tried adding \raggedcolumns to the preamble as other solutions have suggested, but there is still a height discrepancy. I suspect that the multicol environment is grappling with a height issue that I am not aware of. Below is a MWE (perhaps a little more than minimal).

\documentclass[12pt]{article}
\usepackage{amsmath,amsthm,verbatim,amssymb,amsfonts,amscd, graphicx, multicol, xcolor}
\usepackage{fancyhdr,array,tcolorbox,hyperref,faktor}
\tcbuselibrary{breakable}

\newcolumntype{D}{>{\centering\arraybackslash}p{3em}}

\raggedcolumns

\begin{document}

\begin{tcolorbox}[breakable, colbacktitle=white!5!red, title=Motivating Exponential Equations, colback=red!10!white]

A budding alpaca farm in Canada splits its herd up into 3 groups on January $1^{\text{st}}$, 2008. After 3 years, they record the number of alpacas in each herd. Assume each herd grows exponentially.

\begin{multicols}{3}

\[
\begin{tabular}{|*{2}{D|}}
\hline
$t$ & $P_1$ \\
\hline
0 & 8 \\
\hline
1 & \\
\hline
2 & \\
\hline
3 & 64 \\
\hline
\end{tabular}
\]

\columnbreak

\[
\begin{tabular}{|*{2}{D|}}
\hline
$t$ & $P_2$ \\
\hline
0 & 8 \\
\hline
1 & \\
\hline
2 & \\
\hline
3 & 512 \\
\hline
\end{tabular}
\]

\columnbreak

\[
\begin{tabular}{|*{2}{D|}}
\hline
$t$ & $P_3$ \\
\hline
0 & 2 \\
\hline
1 & \\
\hline
2 & \\
\hline
3 & 128 \\
\hline
\end{tabular}
\]

\end{multicols}

Let $P_1 = f(t)$, $P_2 = g(t)$, and $P_3 = h(t)$. Note that $t$ is in years.

\begin{enumerate}

\item Determine function formulas that model $P_1$, $P_2$ and $P_3$.

\item Fill in each of the tables. Determine from the tables when each herd is the same size \textit{at the same time}.

\item Determine algebraically when each pair of herds is the same size.

\end{enumerate}

\end{tcolorbox}

\end{document}

I'd like to avoid dramatically changing the code so as to maintain consistency (since this is part of a larger project), but I would appreciate any suggestions.

1 Answer 1

4

There is no point putting your tabular environments inside \[ and \], as they are not displayed equations. Removing these commands makes the multicols behave as you want:

\documentclass[12pt]{article}
\usepackage{amsmath,amsthm,verbatim,amssymb,amsfonts,amscd, graphicx, multicol, xcolor}
\usepackage{fancyhdr,array,tcolorbox,hyperref,faktor}
\tcbuselibrary{breakable}

\newcolumntype{D}{>{\centering\arraybackslash}p{3em}}

\raggedcolumns

\begin{document}

\begin{tcolorbox}[breakable, colbacktitle=white!5!red, title=Motivating Exponential Equations, colback=red!10!white]

A budding alpaca farm in Canada splits its herd up into 3 groups on January $1^{\text{st}}$, 2008. After 3 years, they record the number of alpacas in each herd. Assume each herd grows exponentially.

\begin{multicols}{3}

\begin{tabular}{|*{2}{D|}}
\hline
$t$ & $P_1$ \\
\hline
0 & 8 \\
\hline
1 & \\
\hline
2 & \\
\hline
3 & 64 \\
\hline
\end{tabular}

\columnbreak

\begin{tabular}{|*{2}{D|}}
\hline
$t$ & $P_2$ \\
\hline
0 & 8 \\
\hline
1 & \\
\hline
2 & \\
\hline
3 & 512 \\
\hline
\end{tabular}

\columnbreak

\begin{tabular}{|*{2}{D|}}
\hline
$t$ & $P_3$ \\
\hline
0 & 2 \\
\hline
1 & \\
\hline
2 & \\
\hline
3 & 128 \\
\hline
\end{tabular}
\end{multicols}

Let $P_1 = f(t)$, $P_2 = g(t)$, and $P_3 = h(t)$. Note that $t$ is in years.

\begin{enumerate}

\item Determine function formulas that model $P_1$, $P_2$ and $P_3$.

\item Fill in each of the tables. Determine from the tables when each herd is the same size \textit{at the same time}.

\item Determine algebraically when each pair of herds is the same size.

\end{enumerate}

\end{tcolorbox}

\end{document}

Screenshot

However, I find it strange to use a multicols environment for this (multicols is generally used for multicolumn text that flows from one column to the next; when you know precisely where to break the columns, it isn't really needed). I'd rather use a \begin{tabular*}{\linewidth}{...} ... \end{tabular*} containing three columns, one for each inner tabular, like this:

\bigskip
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}*{3}{c}@{}}
  \begin{tabular}{|*{2}{D|}}
    \hline
    $t$ & $P_1$ \\
    \hline
    0 & 8 \\
    \hline
    1 & \\
    \hline
    2 & \\
    \hline
    3 & 64 \\
    \hline
  \end{tabular} &

  \begin{tabular}{|*{2}{D|}}
    \hline
    $t$ & $P_2$ \\
    \hline
    0 & 8 \\
    \hline
    1 & \\
    \hline
    2 & \\
    \hline
    3 & 512 \\
    \hline
  \end{tabular} &

  \begin{tabular}{|*{2}{D|}}
    \hline
    $t$ & $P_3$ \\
    \hline
    0 & 2 \\
    \hline
    1 & \\
    \hline
    2 & \\
    \hline
    3 & 128 \\
    \hline
  \end{tabular}
\end{tabular*}
\bigskip

The result is better than with multicols, because the three tables really fill the line (see the spacing on the right in the previous screenshot). With the tabular*-based code, you'll get:

Better screenshot

3
  • Fabulous, thank you. I never thought about why I put them in equation mode until you mentioned it, but I think it's basically just for quick centering (in non-column environments). I also appreciate the tabular* suggestion; I've never heard of it before but will certainly be using it from this point forward. May 26, 2019 at 22:29
  • If you're happy, feel free to upvote. :-) The particularity of tabular* is that it fills a given width using space provided within the @{} specifications (intercolumn stuff). In contrast to tabular which takes the “natural width” and tabularx which fills a given width, but using computed column widths instead of playing with the intercolumn space. Roughly. I simplified a tiny bit the tabular* preamble, take a look: the @{} inside *{3}{...} wasn't needed because... to be continued
    – frougon
    May 26, 2019 at 22:35
  • ... because the @{\extracolsep{\fill}} already gives what we want for the intercolumn spaces (all such spaces except those before the first column and after the last).
    – frougon
    May 26, 2019 at 22:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .