4

I would like to put a enumerate environment (customized with the enumitem package) inside of a shadowbox created from the Fancybox package. Here's my MWE:

\documentclass[letterpaper,10pt,american]{article}
\usepackage[left=1 in, right=1 in, top=1 in, bottom=1 in]{geometry}
\usepackage{amsmath,amsfonts,amssymb,amsthm,color,hyperref,enumitem}
\usepackage{setspace}
\usepackage{caption}
\usepackage{pgf,tikz}
\usetikzlibrary{automata,arrows,positioning,calc,decorations.pathreplacing}
\usepackage{fancybox}
\begin{document}
\shadowbox{
\begin{enumerate}[before=\itshape,font=\normalfont,label=\textbf{ABC.\arabic*}]
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}}
\end{document}

However, the customization of my enumerate environment doesn't show up: only numbers 1., 2., 3. are displayed, rather than ABC.1, ABC.2, ABC.3. Am I doing something wrong? What's causing enumitem customization not to work inside fancybox?

EDIT: We've almost solved the issue! But there's still one small obstacle remaining to fix: When you have ten or more items in the list, then ABC.10, ABC.11, ABC.12, etc. will leak outside of the box.

0

3 Answers 3

3

Some improvements to @Harish Kumar's solution: enumitem has the tools to solve the leak problem for long labels: the key wide= and widest=.

There is also a problem in case of long items: the box leaks into the right margin. I propose 3 solutions for 3 different layouts: one with an indent on both sides, another where only the shadow leaks into the right margin, and no leak at all. Also, I simplified your code for the margins, since they're all equal, and used the showframe option to demonstrate what happens:

\documentclass[letterpaper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1 in, showframe]{geometry}
\usepackage{enumitem}
\usepackage{fancybox}
\usepackage{varwidth}
\begin{document}

\shadowbox{%
  \begin{varwidth}{\dimexpr\linewidth-2\fboxsep-\shadowsize-\parindent\relax}
    \begin{enumerate}[before=\itshape,wide = 0pt, font=\normalfont,label=\textbf{ABC.\arabic*}]
      \item Item 1\setcounter{enumi}{99}
      \item Item 2 \emph{This one’s a very long item. This one’s a very long item. This one’s a very long item. This one’s a very long item.}
      \item Item 3
    \end{enumerate}
  \end{varwidth}
}
\vskip1cm
\noindent\shadowbox{%
  \begin{varwidth}{\dimexpr\linewidth-2\fboxsep-2\shadowsize\relax}
    \begin{enumerate}[before=\itshape,wide = 0pt, font=\normalfont, leftmargin =*, label=\textbf{ABC.\arabic*},widest =999]
      \item Item 1\setcounter{enumi}{99}
      \item Item 2. \emph{This one’s a very long item. This one’s a very long item. This one’s a very long item. This one’s a very long item.}
      \item Item 3
    \end{enumerate}
  \end{varwidth}
}
\vskip1cm
\noindent\shadowbox{%
  \begin{varwidth}{\dimexpr\linewidth-2\fboxsep-\shadowsize\relax}
    \begin{enumerate}[before=\itshape,wide = 0pt, font=\normalfont, leftmargin =*, label=\textbf{ABC.\arabic*},widest =999]
      \item Item 1\setcounter{enumi}{99}
      \item Item 2. \emph{This one’s a very long item. This one’s a very long item. This one’s a very long item. This one’s a very long item.}
      \item Item 3
    \end{enumerate}
  \end{varwidth}
}
\end{document} 

enter image description here

6
  • You're welcome. Glad to help!
    – Bernard
    Commented Sep 28, 2015 at 0:18
  • Sorry, I found one more issue. If you put display equations in the items of the list, the last equation in your list gets aligned left instead of center. Commented Sep 28, 2015 at 0:38
  • Here's a demo showing what I mean: sharelatex.com/project/56088acb379fa8ec2a255224 Commented Sep 28, 2015 at 0:38
  • Also, putting \begin{center} ... \end{center} around it doesn't fix it. Commented Sep 28, 2015 at 0:56
  • I'll see that tomorrrow, but note if you use minipage instead of varwidth there seems to be no problem.
    – Bernard
    Commented Sep 28, 2015 at 1:56
5

Here's a breakable version with tcolorbox as an alternative:

\documentclass[letterpaper,10pt,american]{article}
\usepackage[left=1 in, right=1 in, top=1 in, bottom=1 in]{geometry}
\usepackage{amsmath,amsfonts,amssymb,amsthm,color,enumitem}


\usepackage{setspace}
\usepackage{caption}
\usepackage{pgf,tikz}
\usetikzlibrary{automata,arrows,positioning,calc,decorations.pathreplacing}
%\usepackage{fancybox}
\usepackage[most]{tcolorbox}
\usepackage{xpatch}

\newtcolorbox{enumshadebox}[1][]{breakable, enhanced jigsaw,sharp corners, colframe=black,drop shadow,boxsep=5pt,#1}
\usepackage{hyperref}



\begin{document}

\begin{enumshadebox}
\begin{enumerate}[leftmargin=50pt,before=\itshape,font=\normalfont,label=\textbf{ABC.\arabic*},widest={ABC.100}]
\foreach \x in {1,...,60} {%
  \item \x
}
\end{enumerate}
\end{enumshadebox}

\end{document}

enter image description here

1
  • This is another great option. Thank you, Christian! Commented Sep 28, 2015 at 0:16
4

You have to use enumerate inside a minipage. If you want a tight box, use varwidth package. Use leftmargin=* in addition.

\documentclass[letterpaper,10pt]{article}
\usepackage[left=1 in, right=1 in, top=1 in, bottom=1 in]{geometry}
\usepackage{enumitem}
\usepackage{fancybox}
\usepackage{varwidth}
\begin{document}
\shadowbox{%
\begin{varwidth}{\linewidth}
\begin{enumerate}[before=\itshape,leftmargin=*,font=\normalfont,label=\textbf{ABC.\arabic*}]
\item Item 1
\item Item 2
\item Item 3
\end{enumerate}
\end{varwidth}
}
\end{document}

enter image description here

4
  • Thank you for your answer @HarishKumar. There are 2 problems. The first problem is, when you have ten or more items in the list, then ABC.10, ABC.11, ABC.12, etc. will leak outside of the box. The second problem is, varwidth doesn't seem to work with the hyperref package. See demo here: sharelatex.com/project/56077096379fa8ec2a25302a Commented Sep 27, 2015 at 6:22
  • @EthanAlvaree Adjsut the \fboxsep: \setlength{\fboxsep}{2em} for example.
    – user11232
    Commented Sep 27, 2015 at 6:31
  • Where in the code should that go? Commented Sep 27, 2015 at 6:33
  • @EthanAlvaree: \shadowbox{% \setlength{\fboxsep}{2em} \begin{varwidth}{\linewidth}
    – user11232
    Commented Sep 27, 2015 at 6:34

You must log in to answer this question.

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