2

Is there an easy way to create a inner section like environment that can produce a sub-table of contents at a preferred location? The sub-table does not necessarily need to give page numbers, but it should set links to the inner subsection items. What I have in mind looks somewhat like this

\section{Lorem Ipsum}
\myinnersec_subtable

\myinnersec{InnerSubSectionOne}\label{InnerSubSectionOne}
....
\myinnersec{InnerSubSectionTwo}\label{InnerSubSectionTwo}
....

and should produce something like

Inner subsections with sub-table

3
  • Should the inner subsection also be included in an eventual general table of contents? Commented Jan 22, 2014 at 20:13
  • It rather shouldn't, @GonzaloMedina. Right now, I have a manually set up table at the beginning (made via a customized itemize'ation with hyperlinks) and my inner sections are smth like `\noindent \textbf{\hypertarget{isecone}{InnerSubSectionOne}} \`. The inner section are rather short and they'd rather disturb/distract on the main table of contents. I was about to add alphabetic counting manually, but thought there has to be a lightweight solution to this. The problem is for me even installing a counter is kind of...well..hard.
    – user41429
    Commented Jan 22, 2014 at 20:33
  • Please see my updated answer; with the new settings, the inner subsections won't appear in the general ToC. Commented Jan 22, 2014 at 20:58

1 Answer 1

4

You can achieve the partial ToC using the titletoc package and its \startcontents, \printcontents, \stopcontents commands. A little example, showing the partial ToC for a section and the active hyperlinks:

\documentclass{article}
\usepackage{titletoc}
\usepackage{hyperref}

\newcommand\innercontentsname[1]{%
  Contents for section~\ref{#1}}

\let\oldthesubsection\thesubsection

\begin{document}

\section{A regular section}
\subsection{Regular subsection one}
\subsection{Regular subsection two}

\section{Section with inner units and partial ToC}
\label{sec:ptoc}
\renewcommand\thesubsection{\Alph{subsection}}

\startcontents[inner]
\printcontents[inner]{}{1}{\subsection*{\innercontentsname{sec:ptoc}}}

\subsection{Inner special subsection one}
\subsection{Inner special subsection two}
\subsubsection{Inner special subsubsection one}
\subsubsection{Inner special subsubsection two}
\subsection{Inner special subsection three}

\stopcontents[inner]
\renewcommand\thesubsection{\oldthesubsection}

\section{Another regular section}
\subsection{Regular subsection one}
\subsection{Regular subsection two}

\end{document}

enter image description here

In a comment to the question, it has been requested that the inner subsections shouldn't be included in the general table of contents; this can be achieved by using \startcontents, \printcontents, \resumecontents to print the general table of contents:

\documentclass{article}
\usepackage{titletoc}
\usepackage{hyperref}

\newcommand\innercontentsname[1]{%
  Contents for section~\ref{#1}}

\let\oldthesubsection\thesubsection

\begin{document}

\startcontents
\printcontents{}{1}{\section*{\contentsname}}

\section{A regular section}
\subsection{Regular subsection one}
\subsection{Regular subsection two}

\section{Section with inner units and partial ToC}
\label{sec:ptoc}
\renewcommand\thesubsection{\Alph{subsection}}
\stopcontents[default]

\startcontents[inner]
\printcontents[inner]{}{1}{\subsection*{\innercontentsname{sec:ptoc}}}

\subsection{Inner special subsection one}
\subsection{Inner special subsection two}
\subsubsection{Inner special subsubsection one}
\subsubsection{Inner special subsubsection two}
\subsection{Inner special subsection three}

\stopcontents[inner]
\renewcommand\thesubsection{\oldthesubsection}

\resumecontents
\section{Another regular section}
\subsection{Regular subsection one}
\subsection{Regular subsection two}

\end{document}

enter image description here

4
  • While your post is already pretty much what's on my mind, it just prints some weird additional stuff 1. in the new main table of contents 2. before and after the sub table of my doc. One thing I noticed is, that I put that in a subsection (one level deeper as in the example). Might that be the reason or do I need to check for interference with other packages?
    – user41429
    Commented Jan 22, 2014 at 21:16
  • Please mention also how to make the tables tight (less line spacing). I'm switching to \onehalfspacing, does that effect the table?
    – user41429
    Commented Jan 22, 2014 at 21:22
  • @embert Assuming you are using the setspace package, you can suroound the \printcontents commands with a singlespace environment; for example, for the general ToC: \begin{singlespace} \printcontents{}{1}{\section*{\contentsname}} \end{singlespace}. Commented Jan 22, 2014 at 23:26
  • Tried to adapt it, to make it work one level deeper, but besides this, there is something wrong, some interference or so with other things used. Maybe I can get it to work later.
    – user41429
    Commented Jan 23, 2014 at 14:37

You must log in to answer this question.