调整框中的部分目录

调整框中的部分目录

我正在使用titletoc来为我的章节创建部分目录。我想将部分目录放在框中,以便框的宽度调整为目录的宽度 (a tcbox)。tcolorbox环境可以工作(但大小未调整),但根本tcbox不起作用。下面是一个说明我的问题的示例:

\documentclass[twoside,openright,titlepage,numbers=noenddot,
footinclude,cleardoublepage=empty,abstract=on,
BCOR=5mm,paper=a4,fontsize=12pt
]{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{titletoc}
\usepackage{tcolorbox}

\titlecontents{lsection}
[1pc]
{\sffamily}
{\bfseries\scriptsize\contentslabel[\thechapter.\thecontentslabel]{2pc}}
{}
{\bfseries\scriptsize\contentspage}
[\addvspace{-3pt}]

\titlecontents{lsubsection}
[3pc]
{\sffamily}
{\scriptsize\contentslabel[\thechapter.\thecontentslabel]{2pc}}
{}
{\scriptsize\contentspage}
[\addvspace{-3pt}]

\begin{document}
        \tableofcontents

\chapter{Chapter 1}
\startcontents[chapter]

\begin{tcolorbox}[colback=gray!10!white, colframe= gray!10!white,
    title=Sommaire,coltitle=black]
    \printcontents[chapter]{l}{1}{\setcounter{tocdepth}{2}}
\end{tcolorbox}

\tcbox[colback=gray!10!white, colframe= gray!10!white,
    title=Sommaire,coltitle=black]{
    \printcontents[chapter]{l}{1}{\setcounter{tocdepth}{2}}}


    \section{Sec1}

        \subsection{Subsec1}
        Some text
        \subsection{Subsec2}
        Some text   

    \section{Sec2}


\end{document}

答案1

如果您将部分目录插入其中,它就可以工作\parbox。因此,我提出了一种解决方法:使用 (大约) 章节标题宽度的 \parbox。

    \documentclass[twoside,openright,titlepage,numbers=noenddot,
    footinclude,cleardoublepage=empty,abstract=on,
    BCOR=5mm,paper=a4,fontsize=12pt]{scrreprt}

    \usepackage[utf8]{inputenc}
    \usepackage[french]{babel}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}

    \usepackage{titletoc}
    \usepackage{tcolorbox}
    \usepackage{pbox}

    \titlecontents{lsection}
    [1pc]
    {\sffamily}
    {\bfseries\scriptsize\contentslabel[\thechapter.\thecontentslabel]{2pc}}
    {}
    {\hfill\bfseries\scriptsize\contentspage}
    [\addvspace{-3pt}]

    \titlecontents{lsubsection}
    [3pc]
    {\sffamily}
    {\scriptsize\contentslabel[\thechapter.\thecontentslabel]{2pc}}
    {}
    {\scriptsize\contentspage}
    [\addvspace{-3pt}]

    \begin{document}
        \tableofcontents

    \chapter{Chapter 1}
    \startcontents[chapter]

    \tcbox[colback=gray!10!white, colframe= gray!10!white,
    title=Sommaire,coltitle=black]{
    \parbox{0.25\linewidth}{\printcontents[chapter]{l}{1}{\setcounter{tocdepth}{2}}}}

        \section{Sec1}

        \subsection{Subsec1}
        Some text
        \subsection{Subsec2}
        Some text

    \section{Sec2}

\end{document} 

在此处输入图片描述

相关内容