[Tex/LaTex] How to use fncychap’s style for \section

chaptersfncychapkoma-scriptsectioning

I have a complex document which requires the use of many levels of document structures. In particular, the first two levels, \part and \chapter are reserved for meta-information while \section plays the role of \chapter in ordinary documents. However, it seems that packages like fncychap can only decorate \chapter. So here comes the question: how can I use the fncychap's chapter style for \section?

(I'm using koma-script's scrreprt class, if relevant.)

MWE:

\documentclass[fontsize=22pt]{scrreprt}

\usepackage[Sonny]{fncychap}
\renewcommand*{\DOCH}{}
\ChTitleVar{\large\sffamily}

\newcommand*{\mypart}[1]{
  \refstepcounter{part}
  \addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}
}
\newcommand*{\mychap}[1]{
  \refstepcounter{chapter}
  \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
}

\begin{document}
\tableofcontents

\mypart{big picture level 1}
\mychap{big picture level 2}
% \mypart and \mychap are used for adding meta-information

\section{real chapter here}
% \section is used like \chapter in ordinary documents
% I want the section title etc. to show up using fncychap's style

\end{document}

Best Answer

Rather than abuse the existing chapter and part counters for your metadata, you can create new items to add to the Table of Contents using the existing facilities of tocloft. Then you can use the fncychap formatting for chapters normally.

As part of its ability to create new contents lists, tocloft provides a command \newlistentry which lets you populate an existing list with TOC entries. It creates the counter for you, and then you use regular tocloft methods for assigning formatting to the entries. Here's an example which should get you going:

\documentclass[fontsize=22pt]{scrreprt}

\usepackage[Sonny]{fncychap}
\renewcommand*{\DOCH}{}
\ChTitleVar{\large\sffamily}

\usepackage{tocloft}
\newlistentry{mypart}{toc}{0}
\newlistentry{mychap}{toc}{0}
\renewcommand{\cftmypartfont}{\itshape}
\renewcommand{\cftmychapfont}{\sffamily}

\newcommand*{\mypart}[1]{
  \refstepcounter{mypart}
  \addcontentsline{toc}{mypart}{\protect\numberline{\themypart}#1}
}
\newcommand*{\mychap}[1]{
  \refstepcounter{mychap}
  \addcontentsline{toc}{mychap}{\protect\numberline{\themychap}#1}
}


\begin{document}
\tableofcontents

\mypart{big picture level 1}
\mychap{big picture level 2}
% \mypart and \mychap are used for adding meta-information

\chapter{real chapter here}
% \section is used like \chapter in ordinary documents
% I want the section title etc. to show up using fncychap's style
\end{document}

Table of Contents image