2

I would like to create a table that looks like this, preferably one that allows me to use enumitem in the 'table' :

enter image description here

As you can see, the alignment for the first row is centered but the subsequent rows are left aligned. Thanks.

5
  • You could use one big p type column for the table and for the first row use \multicolumn{1}{c}{Learning Outcomes}.
    – Skillmon
    Jul 23, 2018 at 7:23
  • 1
    Another viable solution would be a package like tcolorbox (which might be overkill for this simple looking result, but would add easy page breakability and allow more fancy looking boxes).
    – Skillmon
    Jul 23, 2018 at 7:30
  • Is it possible to use arrays for this? Jul 23, 2018 at 7:33
  • 1
    Do you mean the environment array? tabular is effectively the same but with text mode (what's what you want, as the contents are text not maths).
    – Skillmon
    Jul 23, 2018 at 7:33
  • 1
    Or did you mean to achieve the stuff in the braces which I wrote to describe the advantages of tcolorbox? Page breakable would be hard to do, as a tabular is one cell. longtable could fix that (it is page breakable), but I think not in the midst of a p row. And the fancy looks are not possible with tabular.
    – Skillmon
    Jul 23, 2018 at 7:49

1 Answer 1

2

If you want to use a tabular you could use

\documentclass[border=2mm]{standalone}

\usepackage[table]{xcolor}

\begin{document}
\begin{tabular}[]{|p{\dimexpr\linewidth-2\arrayrulewidth-2\tabcolsep\relax}|}
  \hline
  \rowcolor{gray!25}
  \multicolumn{1}{|c|}{Learning Outcomes}\\
  \hline
  \begin{enumerate}
    \item thingy
    \item thingy
  \end{enumerate}\\
  \hline
\end{tabular}
\end{document}

enter image description here

Small appetizer for tcolorbox (the breakable key makes the box page breakable if it is a big one):

\documentclass[border=2mm]{standalone}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\newtcolorbox{mybox}[1]{colframe=gray,fonttitle=\bfseries,adjusted
title=\centering#1,breakable}

\begin{document}
\begin{mybox}{Learning Outcomes}
  \begin{enumerate}
    \item thingy
    \item thingy
  \end{enumerate}
\end{mybox}
\end{document}

enter image description here

5
  • What do the bits after begin tabular do? Especially \dimexpr, \tabcolsep and \relax. Jul 23, 2018 at 7:41
  • 1
    @ChungRenKhoo \dimexpr lets you calculate a dimension based on simple maths. It absorbs every dimension/number following after it which are connected by correct maths operations. \relax stops this absorption to make sure that it can't absorb more than I want it to. So the stuff between \dimexpr and \relax is the width of the p type column. \linewidth should be self explanatory, \arrayrulewidth is the width of the vertical rules, \tabcolsep is the separation between the text and those rules (basically the padding which is added on both sides of each table column).
    – Skillmon
    Jul 23, 2018 at 7:46
  • 1
    @ChungRenKhoo This makes sure that the table takes up the whole line but doesn't produce an overfull \hbox error.
    – Skillmon
    Jul 23, 2018 at 7:47
  • If I would like to add more columns to the second box (it looks amazing btw) how do I go about doing that? e.g. Instead of just "Learning Outcomes", what if I want to have another column for "Random Stuff"? Jul 23, 2018 at 9:42
  • 1
    @ChungRenKhoo there is the raster column key in tcolorbox, but I don't know whether you'd like the output. You can take a look at the documentation.
    – Skillmon
    Jul 23, 2018 at 11:21

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.