목차에서 여러 줄 부분을 중앙에 배치

목차에서 여러 줄 부분을 중앙에 배치

나는 당황했다. 여러 줄로 된 부분 제목을 목차의 중앙에 어떻게 배치할 수 있나요?

\documentclass[a4paper,12pt,openright]{book}  

\usepackage{tocloft}% toc spacing and ragged right (below)  
\cftpagenumbersoff{part}  
\renewcommand{\cfttoctitlefont}{\hfill\Large}  
\renewcommand{\cftaftertoctitle}{\hfill}  

\begin{document}

\tableofcontents  
\chapter{Chapter 1}  
\chapter{Chapter 2}  
\part{A moderately long part title}  
\chapter{Chapter 3}  
\chapter{Chapter 4}  
\chapter{Chapter 5}  
\part{A Very very very long part title which runs over multiple lines in the table of contents}  
\chapter{Chapter 6}  
\chapter{Chapter 7}  
\chapter{Chapter 8}  

\end{document}

이상적으로는 목차를 다음과 같이 배치하고 싶습니다.

                       Contents             
  1. 소개 . . . . . . . . . . . . . . . . . . . . . . . . . 1

                        Part I
             A moderately long part title
    
  2. 제 2 장 . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

  3. 3 장 . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
  4. 4장. . . . . . . . . . . . . . . . . . . . . . . . . . . 30

                       Part II
     A Very very very long part title which runs 
     over multiple lines in the table of contents
    
  5. 5장. . . . . . . . . . . . . . . . . . . . . . . . . . . 40

  6. 6장. . . . . . . . . . . . . . . . . . . . . . . . . . . 50

이전에 이런 질문을 받았다면 죄송합니다. 하지만 솔루션을 함께 해킹하려고 몇 시간을 보냈지만 아무 소용이 없습니다.

답변1

내 관점에서는 여기에서 명령을 \@part사용하는 것보다 패치를 사용하는 것이 더 쉽습니다 tocloft.

\documentclass[a4paper,12pt,openright]{book}  

\usepackage{xpatch}
\usepackage{tocloft}% toc spacing and ragged right (below)  



%\cftpagenumbersoff{part}  
\makeatletter
\xpatchcmd{\@part}{%
  \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
}{%
  % Rather use an `\addcontentsline` to get rid off the restrictions of `\contentsline` etc. 
  \addtocontents{toc}{\begingroup\Large \mdseries\protect\centering\partname\ \thepart\par\large\protect\centering#1\par\endgroup}
}{}{}


\makeatother

\renewcommand{\cfttoctitlefont}{\hfill\Large}  
\renewcommand{\cftaftertoctitle}{\hfill}  


\begin{document}

\tableofcontents  
\chapter{Chapter 1}  
\chapter{Chapter 2}  
\part{A moderately long part title}  
\chapter{Chapter 3}  
\chapter{Chapter 4}  
\chapter{Chapter 5}  
\part{A Very very very long part title which runs over multiple lines in the table of contents}  
\chapter{Chapter 6}  
\chapter{Chapter 7}  
\chapter{Chapter 8}  

\end{document}

여기에 이미지 설명을 입력하세요

다른 설정\parbox

\documentclass[a4paper,12pt,openright]{book}  




\usepackage{xpatch}
\usepackage{tocloft}% toc spacing and ragged right (below)  


\DeclareRobustCommand{\wrapmytitles}[1]{%
  \leavevmode

  \centering
  \parbox{0.7\linewidth}{\centering #1}%

}

\makeatletter
\xpatchcmd{\@part}{%
  \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
}{%
  \addtocontents{toc}{\begingroup\Large \mdseries\protect\centering\partname\ \thepart\par\large\wrapmytitles{#1}\endgroup}
}{}{}


\makeatother

\renewcommand{\cfttoctitlefont}{\hfill\Large}  
\renewcommand{\cftaftertoctitle}{\hfill}  


\begin{document}

\tableofcontents  
\chapter{Chapter 1}  
\chapter{Chapter 2}  
\part{A moderately long part title}  
\chapter{Chapter 3}  
\chapter{Chapter 4}  
\chapter{Chapter 5}  
\part{A Very very very long part title which runs over multiple lines in the table of contents}  
\chapter{Chapter 6}  
\chapter{Chapter 7}  
\chapter{Chapter 8}  

\end{document}

여기에 이미지 설명을 입력하세요

관련 정보