0

Let's say we have a document broken into chapters and we want at the beginning of each chapter to add between two horizontal lines a "Section Break-Down" that shows all the sections and subsections of the Chapter with our preferred text before all or some of the sections.

For example... For the next document/MWE

\documentclass{book}
\usepackage{amsmath}
\usepackage{capt-of}
\usepackage{pgffor}
\usepackage{hyperref}
\makeatletter
\hypersetup{colorlinks=true, linkcolor=black, citecolor=black, filecolor=black, urlcolor=black,pdftitle = {\@title}}
\makeatother

\newcounter{mychapter}

\renewcommand\thepart{\Alph{part}}
\renewcommand\thechapter{\thepart.\arabic{mychapter}}
\renewcommand\thesection{\thechapter.\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}


\usepackage{tocloft}
\renewcommand\cftchapfont{\large\bfseries}
\setlength{\cftchapindent}{2.3em}
\setlength{\cftchapnumwidth}{2.6em}
\renewcommand\cftsecfont{\normalsize}
\setlength{\cftsecindent}{4.9em}
\setlength{\cftsecnumwidth}{2.9em}
\setlength{\cftsubsecnumwidth}{4em}
\setlength{\cftsubsecindent}{7em}

\let\oldpart\part
\def\part#1{\oldpart{#1}\setcounter{mychapter}{0}}
\let\oldchapter\chapter
\def\chapter#1{\stepcounter{mychapter}\oldchapter{#1}}



\title{Some Math Staff}
\author{Leledakis, K.}

\begin{document}
\maketitle
\tableofcontents
\listoffigures

\part{First Part}

\chapter{Some Mathematical Functions}
\section{The function $\mathbf{f(x)=c}$}\label{Sec:UFxC}
\subsection{Understanding the function}
This function is independent from the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFxC}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c$}
\end{minipage}
\subsection{Examples}
\ldots

\section{The function $\protect\mathbf{f(x)=c\cdot x}$}\label{Sec:UFxCx}
\subsection{Understanding the function}
This function depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFxCx}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c\cdot x$}
\end{minipage}
\subsection{Examples}
\ldots

\section{The function $\protect\mathbf{f(x)=c\cdot x+d}$}\label{Sec:UFxCxD}
\subsection{Understanding the function}
This function depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFxCxD}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c\cdot x+d$}
\end{minipage}
\subsection{Examples}
\ldots

\chapter{More Functions}
\section{The function $\protect\mathbf{f(x)=x^2}$}\label{Sec:UFxS}
\subsection{Understanding the function}
This function depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFxS}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=x^2$}
\end{minipage}
\subsection{Examples}
\ldots

\section{The function $\protect\mathbf{f(x)=c\cdot x^2}$}\label{Sec:UFCxS}
\subsection{Understanding the function}
This function depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFCxS}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c\cdot x^2$}
\end{minipage}
\subsection{Examples}
\ldots

\section{The function $\protect\mathbf{f(x)=c\cdot x^2+d}$}\label{Sec:UFCxSD}
\subsection{Understanding the function}
This function is depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFCxSD}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c\cdot x^2+d$}
\end{minipage}
\subsection{Examples}
\ldots
\end{document}

That has a TOC like this:

enter image description here

I want Something like this:

enter image description here

on the Chapter A.1

But also something like this:

on the Chapter A.2

enter image description here

koleygr
  • 20,105
  • Do you want to have these partial tocs at the beginning or at the end of each chapter? It is not quite clear to me. – Bernard Aug 08 '19 at 21:55
  • @Bernard ... thanks for the comment ... I will edit the title ... I meant just after \chapter command – koleygr Aug 08 '19 at 21:59
  • Maybe one of the answers here works for you. One would just have to patch in the text insertions. – schtandard Aug 08 '19 at 22:26
  • @schtandard these answers are about koma-script ... My own answer is enough for me and just uploaded since created to help future visitors in similar expectations ... It is much extendable for every usage. Thanks anyway. – koleygr Aug 08 '19 at 22:31
  • @koleygr While the question mentions KOMA Script and the answers consequently use it, as far as I can tell both answers do not rely on special features of the KOMA Script class. – schtandard Aug 08 '19 at 22:36
  • @schtandard ... may be you are right ... But in the content of the answers I think they use special features of koma-script ... Not sure ... But seems like this to me. Anyway, you could try to use them and add an answer if you wish... Sure I can understand my own answer easier (but this is about my knowledge -someone else could prefer your approach-) – koleygr Aug 08 '19 at 22:39
  • The package minitoc might be of interest. It provides means for placing a table of contents at the beginning of each chapter. – Ulrich Diez Aug 09 '19 at 14:38
  • Thanks @UlrichDiez ... It was easier for me define my way in order to have no page numbers and my own style and stops between sections... than reading it's documentation. But thanks anyway. – koleygr Aug 09 '19 at 21:14

1 Answers1

0

The solution is to auto-label the sections/subsections (I used \def to redefined them but you could use etoolbox -I think- to add this to the command) and to make a list with your preferred appearance by using a foreach loop on them (I used 'pgffor' package for this). A problem is that we have to stop to add text after some section and this is dealt by the optional argument of my \SBD command (that finishes at -1 for the last section to be included) and also one other problem was to stop adding subsections (and sections) when no label defined (thus \@ifundefined helped).

\documentclass{book}
\usepackage{amsmath}
\usepackage{capt-of}
\usepackage{pgffor}
\usepackage{hyperref}
\makeatletter
\hypersetup{colorlinks=true, linkcolor=black, citecolor=black, filecolor=black, urlcolor=black,pdftitle = {\@title}}
\makeatother

\newcounter{mychapter}

\renewcommand\thepart{\Alph{part}}
\renewcommand\thechapter{\thepart.\arabic{mychapter}}
\renewcommand\thesection{\thechapter.\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}


\usepackage{tocloft}
\renewcommand\cftchapfont{\large\bfseries}
\setlength{\cftchapindent}{2.3em}
\setlength{\cftchapnumwidth}{2.6em}
\renewcommand\cftsecfont{\normalsize}
\setlength{\cftsecindent}{4.9em}
\setlength{\cftsecnumwidth}{2.9em}
\setlength{\cftsubsecnumwidth}{4em}
\setlength{\cftsubsecindent}{7em}

\let\oldpart\part
\def\part#1{\oldpart{#1}\setcounter{mychapter}{0}}

\makeatletter
\let\oldsection\section
\let\oldsubsection\subsection
\let\olldchapter\chapter
\def\oldchapter{\stepcounter{mychapter}\olldchapter}
\makeatletter

\def\chapter{%
\@ifstar{\@StarredC}{\@nonStarredC}%
}
\def\@StarredC{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred chapter can not have parameters. I am going to ignore them!}\@StarredCWith}%
{\@StarredCWithout}%
}      
\def\@StarredCWith[#1]#2{%
\oldchapter*{#2}%
}
\def\@StarredCWithout#1{
\oldchapter*{#1}%
}
\def\@nonStarredC{%
\@ifnextchar[%
{\@nonStarredCWith}%
{\@nonStarredCWithout}%
}
\def\@nonStarredCWith[#1]#2{%
\oldchapter[#1]{#2}\label{Ch:\thechapter}%
}
\def\@nonStarredCWithout#1{%
\oldchapter{#1}\label{Ch:\thechapter}%
}



\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%
\oldsection{#2}\label{\thechapter:\arabic{section}}%
}
\def\@StarredWithout#1{
\oldsection*{#1}\label{\thechapter:\arabic{section}}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldsection[#1]{#2}\label{\thechapter:\arabic{section}}%
}
\def\@nonStarredWithout#1{%
\oldsection{#1}\label{\thechapter:\arabic{section}}%
}



\def\subsection{%
\@ifstar{\@StarredS}{\@nonStarredS}%
}
\def\@StarredS{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredSWith}%
{\@StarredSWithout}%
}      
\def\@StarredSWith[#1]#2{%
\oldsubsection*{#2}%
}
\def\@StarredSWithout#1{%
\oldsubsection*{#1}%
}
\def\@nonStarredS{%
\@ifnextchar[%
{\@nonStarredSWith}%
{\@nonStarredSWithout}%
}
\def\@nonStarredSWith[#1]#2{%
\oldsubsection[#1]{#2}\label{\thesection:\arabic{subsection}}%
}
\def\@nonStarredSWithout#1{%
\oldsubsection{#1}\label{\thesection:\arabic{subsection}}%
}



%SectionBreakDown

\newcounter{secc}
\newcounter{ssecc}
\newcounter{tssecc}
\xdef\OverC{0}

\newcommand{\myalph}[1]{\ifnum\OverC>0\alph{tssecc}\alph{tssecc}\else\ifnum\value{#1}>26\setcounter{tssecc}{\numexpr\value{#1}-26}\alph{tssecc}\alph{tssecc}\xdef\OverC{1}\else\alph{#1}\fi\fi}

\newcommand\SBD[2][1,-1]{%
  \xdef\OverC{0}%
  \def\Continued{1}%
  \def\ToBeContinued{-1}%
  \foreach \opt[count=\ll from 1] in {#1}{%
    \ifnum\ll=1
    \xdef\Continued{\opt}%
    \else
    \xdef\ToBeContinued{\opt}%
    \fi
  }%
  \ifx\ToBeContinued\empty
  \xdef\ToBeContinued{-1}%
  \fi
  \ifx\Continued\empty
  \xdef\Continued{1}%
  \fi

%\section{Section breakdown}

\ifnum\Continued>1
\relax%
\else
\noindent{\huge\bfseries Learning Objectives}%

\noindent\rule{\textwidth}{2pt}\vspace{0.5cm}
\setcounter{secc}{0}%
\setcounter{ssecc}{0}%
\setcounter{tssecc}{0}%
\fi

{\noindent #2}


\ifnum\ToBeContinued<0
\def\ContinueUntil{100}%
\else
\def\ContinueUntil{\ToBeContinued}%
\fi

\foreach \mk in {\Continued,...,\ContinueUntil}{%
  \@ifundefined{r@\thechapter:\mk}{%
    \breakforeach%
  }{%
    \setcounter{secc}{\mk}%
    \ifnum\mk<0
      \breakforeach%
    \else
    \ifnum\mk>\ContinueUntil
    \breakforeach%
    \else
         \noindent{\bfseries{\nameref{\thechapter:\mk}}}\\
         \foreach \ml in {1,...,100}{%
            \@ifundefined{r@\thechapter.\mk:\ml}{%
               \breakforeach%
            }{%
               \setcounter{ssecc}{\ml}%
               \stepcounter{tssecc}%
               \ifnum\mk>0
                     \hspace*{0.5cm}\myalph{tssecc}.\hspace{0.3cm}\parbox[t]{0.9\textwidth}{\setlength{\baselineskip}{4pt}\nameref{\thechapter.\mk:\ml}}\\[1.2ex]
                \fi
            }%
        }%
        \fi
    \fi
  }%
}
%\begin{enumerate}[label={\arabic{enumi}.},itemsep=0pt]
%\foreach \i in {#3,...,#4}
%{\item \nameref{\thechapter:\i}}
%\end{enumerate}

\ifnum\ToBeContinued>0
\relax%
\else
\vspace{-0.5cm}
\par
\noindent\rule{\textwidth}{2pt}
\fi
}
\makeatother


\title{Some Math Staff}
\author{Leledakis, K.}

\begin{document}
\maketitle
\tableofcontents
\listoffigures

\part{First Part}

\chapter{Some Mathematical Functions}
\SBD{In this Section we are going to analyze linear functions:}
\section{The function $\mathbf{f(x)=c}$}\label{Sec:UFxC}
\subsection{Understanding the function}
This function is independent from the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFxC}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c$}
\end{minipage}
\subsection{Examples}
\ldots

\section{The function $\protect\mathbf{f(x)=c\cdot x}$}\label{Sec:UFxCx}
\subsection{Understanding the function}
This function depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFxCx}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c\cdot x$}
\end{minipage}
\subsection{Examples}
\ldots

\section{The function $\protect\mathbf{f(x)=c\cdot x+d}$}\label{Sec:UFxCxD}
\subsection{Understanding the function}
This function depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFxCxD}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c\cdot x+d$}
\end{minipage}
\subsection{Examples}
\ldots

\chapter{More Functions}
\SBD[1,2]{Now we will start with the analysis of the functions:}
\SBD[3,-1]{And will finish with:}
\section{The function $\protect\mathbf{f(x)=x^2}$}\label{Sec:UFxS}
\subsection{Understanding the function}
This function depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFxS}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=x^2$}
\end{minipage}
\subsection{Examples}
\ldots

\section{The function $\protect\mathbf{f(x)=c\cdot x^2}$}\label{Sec:UFCxS}
\subsection{Understanding the function}
This function depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFCxS}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c\cdot x^2$}
\end{minipage}
\subsection{Examples}
\ldots

\section{The function $\protect\mathbf{f(x)=c\cdot x^2+d}$}\label{Sec:UFCxSD}
\subsection{Understanding the function}
This function is depends on the variable $x$ and thus\ldots
\subsection{Plotting the function}
By understanding the content of Subsection~\ref{Sec:UFCxSD}\ldots

\noindent\begin{minipage}[inner sep=0,outer sep=0]{\textwidth}
  \centering
  \captionof{figure}{Plot of $f(x)=c\cdot x^2+d$}
\end{minipage}
\subsection{Examples}
\ldots
\end{document}

PS: For bigger counter (that \alph command can't accept... I used aa, bb, cc etc to continue the enumeration)

Output: The output of the question.

koleygr
  • 20,105