[Tex/LaTex] List of Boxes in Table of Contents

mdframedtable of contents

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}

Best Answer

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

Related Question