5

I am creating titled boxes using mdframed environment.

How do I add a List of Boxes after the Table of Contents (as List of Tables and List of Figures)?

Here is my MWE.

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage{makeidx}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}
\makeindex
\author{Draft: Do not Cite}
\date{}
\title{alskdj alskdj alksjd}
\hypersetup{
 pdfauthor={Draft: Do not Cite},
 pdftitle={alskdj alskdj alksjd},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 24.5.1 (Org mode 8.3)}, 
 pdflang={English}}
\begin{document}

\maketitle
\tableofcontents


\section{Heading}

\lipsum[5]

\begin{infobox}[Title of the box]
\label{orgspecialblock1}



\lipsum[8]
\end{infobox}
\end{document}

In my actual use case, I am using the memoir class. Memoir class integrates tocloft. So the solution for the article class do not seem to work out of them box when using memoir class. I am adding another MWE for the memoir class. Would appreciate if you could also help with these.

The MWE below combines Alan's code with my use case. But when running pdflatex on it, I get the error "Command \infobox already defined.". What am I doing wrong?

\documentclass[a4paper,11pt,twoside,openany,showtrims,strict,extrafontsizes]{memoir}

\newcommand{\listinfoboxname}{List of Boxes}
\newlistof{infobox}{ibx}{\listinfoboxname}

\newcounter{infobox}[chapter]
\renewcommand{\theinfobox}{\thechapter.\arabic{infobox}}

\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\addcontentsline{ibx}{infobox}{\protect\numberline{\theinfobox}#1}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}

\begin{document}

\tableofcontents
\listoffigures
\listofboxes

\chapter{Chapter one starts here}
\section{Heading}

\lipsum[4]
\begin{infobox}[Title of the first test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}

\begin{figure}
\caption{\label{orgspecialblock3}ksfkhjsdkjhfs}
\includegraphics[width=0.9\linewidth]{pou.png}
\end{figure}

\chapter{Chapter two starts here}
\section{Heading}

\lipsum[4]
\begin{infobox}[Title of the third test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the fourth test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}

\end{document}



\documentclass[a4paper,11pt,twoside,openany,showtrims,strict,extrafontsizes]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage{makeidx}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}
\makeindex
\author{Draft: Do not Cite}
\date{}
\title{alskdj alskdj alksjd}
\hypersetup{
 pdfauthor={Draft: Do not Cite},
 pdftitle={alskdj alskdj alksjd},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 24.5.1 (Org mode 8.3)}, 
 pdflang={English}}
\begin{document}

\maketitle
\tableofcontents

\chapter{Chapter one starts}    

\section{Heading}

\lipsum[5]

\begin{infobox}[Title of the box]
\label{orgspecialblock1}



\lipsum[8]
\end{infobox}
\end{document}

And here is an MWE that combines Gonzalo's solution

\documentclass[a4paper,11pt,twoside,openany,showtrims,strict,extrafontsizes]{memoir}
\newcounter{infobox}[chapter]
\renewcommand{\theinfobox}{\thechapter.\arabic{infobox}}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}

\newcounter{infobox}[chapter]

\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}%
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
\addcontentsline{lob}{section}{\numberline{\theinfobox}#1}%
}{%
\end{mdframed}
}
\makeatletter
\newcommand\listboxname{Boxes}
\newcommand\listofboxes{
\section*{\listboxname}
\@starttoc{lob}
}
\makeatother

\begin{document}

\tableofcontents
\listoffigures
\listofboxes

\chapter{Chapter one starts here}
\section{Heading}

\lipsum[4]
\begin{infobox}[Title of the first test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}

\begin{figure}
\caption{\label{orgspecialblock3}ksfkhjsdkjhfs}
\includegraphics[width=0.9\linewidth]{pou.png}
\end{figure}

\chapter{Chapter two starts here}
\section{Heading}

\lipsum[4]
\begin{infobox}[Title of the third test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the fourth test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}


\end{document}
5

Update

Since memoir is being used, then things are easier since memoir already provides all the required tools to produce the desired list using \newlistof and associates; in particular now \listofboxes comes with a starred variant that won't add to the ToC an entry for the new list:

\documentclass[a4paper,11pt,twoside,openany,showtrims,strict,extrafontsizes]{memoir}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}

\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}%
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
\addcontentsline{lob}{infobox}{\numberline{\theinfobox}#1}%
}{%
\end{mdframed}
}
\makeatletter
\newcommand\listboxname{Boxes}
\newlistof{listofboxes}{lob}{\listboxname}
\newlistentry[chapter]{infobox}{lob}{0}
\cftsetindents{infobox}{0em}{2.3em}
\renewcommand{\theinfobox}{\thechapter.\arabic{infobox}}
\makeatother

\begin{document}

\tableofcontents
\listoffigures
\listofboxes

\chapter{Test chapter}
\section{Test section}

\lipsum[4]
\begin{infobox}[Title of the first test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}

\begin{figure}
\caption{\label{orgspecialblock3}A test figure}
\end{figure}

\end{document}

An image of the result showing the ToC, the LoF and te new list:

enter image description here

mdframed version

Here's one possibility:

\documentclass[11pt]{article}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}

\newcounter{infobox}

\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}%
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
\addcontentsline{lob}{section}{\numberline{\theinfobox}#1}%
}{%
\end{mdframed}
}
\makeatletter
\newcommand\listboxname{List of Boxes}
\newcommand\listofboxes{
\section*{\listboxname}
\@starttoc{lob}
}
\makeatother

\begin{document}

\tableofcontents
\listofboxes

\section{Heading}

\lipsum[4]
\begin{infobox}[Title of the first test box]
\label{orgspecialblock1}
\lipsum[4]
\end{infobox}
\begin{infobox}[Title of the second test box]
\label{orgspecialblock2}
\lipsum[4]
\end{infobox}

\end{document}

An image of the result showing the ToC and the new list of boxes:

enter image description here

tcolorbox version

Here I present a version using tcolorbox which already provides the tools to easily generate a list of boxes:

\documentclass[11pt]{article}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\usepackage{xparse}

\newtcolorbox[auto counter,list inside=infobox]{infobox}[2][]{
  breakable,
  enhanced jigsaw,
  before=\vskip25pt,
  after=\vskip25pt,
  colback=white,
  colbacktitle=white,
  coltitle=black,
  fonttitle=\bfseries,
  arc=0pt,
  outer arc=0pt,
  boxsep=0pt,
  toptitle=5pt,
  bottomtitle=5pt,
  left=10pt,
  right=10pt,
  enlarge left by=10pt,
  enlarge right by=10pt,
  width=\textwidth-20pt,
  boxrule=0.4pt,
  title={\strut Box~\thetcbcounter\ #1\strut},
  label={#2}
}

\newcommand\listboxname{List of Boxes}

\begin{document}

\tableofcontents
\tcblistof[\section*]{infobox}{\listboxname}

\section{Heading}

\lipsum[4]
\begin{infobox}[Title of the first test box]{orgspecialblock1}
\lipsum[4]
\end{infobox}

\begin{infobox}[Title of the second test box]{orgspecialblock2}
\lipsum[4]
\end{infobox}

\end{document}

An image of the result showing the ToC and the new list of boxes:

enter image description here

  • I have not been able to make it work for my use case yet. One difference is that I am using memoir class. Which seems to conflict with tocloft, so solution by @AlanMunn does not seem to work. For some reason, I am having trouble with your solution as well. One thing that happens is that entries for my boxes end up in the main table of contents, rather than in a separate list. Also, I notice that you have put \addcontentsline inside the mdframed environment while AlanMunn puts it outside. Does that make a difference? – len71 Aug 23 '15 at 0:09
  • You should have mentioned memoir in the first place. Besides, without seeing the actual code you use, nothing effective can be done. Please consider edition your question and add there a minimal document (like the one in my answer) showing your current attempt and allowing us to reproduce the problem you have. – Gonzalo Medina Aug 23 '15 at 0:18
  • @VRL please add a MWE using my code and showing the problems you mentioned, otherwise, we will loose time. – Gonzalo Medina Aug 23 '15 at 0:36
  • @VRL If you're going to use Alan's code, ask Alan for advise. – Gonzalo Medina Aug 23 '15 at 1:16
  • I have added an MWE that integrates your code with memoir. It works. There are two small issues. One is, since we are using {section} with \addcontentsline, the entries are correctly formatted but indented to the level of entries for sections in the main TOC. I do not want these indented. Secondly, how does one make an entry for List of Boxes in the main table of contents. – len71 Aug 23 '15 at 2:10
4

More or less the same answer as Gonzalo's but using the tocloft package, which hides a little of the machinery. But if you need it to format your TOC more generally you might as well do things using it:

\documentclass[11pt]{article}
\usepackage[titles]{tocloft}
\newcommand{\listinfoboxname}{List of Boxes}
\newlistof{infobox}{ibx}{\listinfoboxname}

\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\addcontentsline{ibx}{infobox}{\protect\numberline{\theinfobox}#1}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}

\begin{document}

\tableofcontents
\listofinfobox

\section{Heading}

\lipsum[5]

\begin{infobox}[Title of the box]
\label{orgspecialblock1}
   \lipsum[8]
\end{infobox}
\end{document}

output of code

Solution using memoir

The memoir package incorporates the code of tocloft so tocloft cannot be used with memoir. But all of the functionality is there, although there are some differences in the way memoir implements this.

First, the \newlistof command takes the list name instead of the basename of the list as its argument, and as a result, the counter for the list needs to be created by the user. Furthermore, we need to tell what level the list entries are supposed to be. 0 means the same indentation level as \chapter (which is what you want, I think.)

\newlistof{listofinfobox}{ibx}{\listinfoboxname}
\newcounter{infobox}
\newlistentry{listofinfobox}{ibx}{0}

In the infobox environment, the addcontentsline also needs to be changed:

\addcontentsline{ibx}{listofinfobox}{\protect\numberline{\theinfobox}#1}

So the complete memoir code is the following:

% !TEX TS-program = pdflatex
\documentclass[11pt]{memoir}
%\usepackage[titles]{tocloft}
\newcommand{\listinfoboxname}{List of Boxes}
\newlistof{listofinfobox}{ibx}{\listinfoboxname}
\newcounter{infobox}
\newlistentry{listofinfobox}{ibx}{0}
\usepackage[skipabove=25pt,skipbelow=25pt,leftmargin=10pt,rightmargin=10pt,framemethod=TikZ]{mdframed}
\usepackage{lipsum}

\newenvironment{infobox}[1][]{%
\refstepcounter{infobox}
\addcontentsline{ibx}{listofinfobox}{\protect\numberline{\theinfobox}#1}
\begin{mdframed}[%
frametitle={Box \theinfobox\ #1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
repeatframetitle=true,
font=\small,
]%
}{%
\end{mdframed}
}

\begin{document}


\tableofcontents
\listofinfobox
\chapter{}

\section{Heading}

\lipsum[5]

\begin{infobox}[Title of the box]
\label{orgspecialblock1}



\lipsum[8]
\end{infobox}
\end{document}
  • Could you kindly advise how to use this with memoir. Memoir seems to conflict with the tocloft. – len71 Aug 23 '15 at 0:11
  • @VRL I've added the memoir solution. It would have helped to have mentioned that at the outset. – Alan Munn Aug 23 '15 at 3:27

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.