2014-12-18 9 views
0

내 문서에서 목차에 두 가지 색상을 사용하여 두 명의 작가 사이의 작업을 구분하고 싶습니다. 예를 들어,라텍스에서 두 가지 색상으로 목차 사용자 정의

  • 제 1, 파란색으로 색 섹션과 하위 섹션은 몇 장, 절에서 저자 Y.

에 의해 작성하고 하위 섹션이 모두 기록 된 저자의 X에 의해과 붉은 색에 기록 된 장 저자의 제 A의 예 (블루),

  • 제 1 (청색)의 경우

Y. 의해 작성된 X.

  • 담당 1.1 (레드) 및 (2) (적색)에 의해 작성된 마지막으로, 이러한 색상은 목차에서는 변경해야하지만 문서의 내용에서는 변경되지 않아야합니다.

    어떻게 사용자 정의 할 수 있습니까? 아무도 그와 같은 것을 도울 수 있습니까?

    미리 감사드립니다.

  • 답변

    5

    tocloft을 사용하면 ToC 내의 모든 입력 유형의 형식을 제어 할 수 있습니다. 챕터의 경우 \cftchapfont, 섹션의 경우 \cftsecfont 및 하위 섹션은 \cftsubsecfont입니다.

    이하는 색을 변경하기 위해 ToC에 항목을 삽입하는 \authoredby{<name>}을 제공합니다. 또한 저자 색상은 \defineauthorcolor{<name>}{<colour>}을 사용하여 정의 할 수 있습니다.

    enter image description here

    \documentclass{book} 
    \usepackage{tocloft,xcolor} 
    
    \newcommand{\defineauthorcolor}[2]{% 
        \colorlet{author#1}{#2}% Create an author colour 
        \expandafter\def\csname authoredby#1\endcsname{% Create author colour settings 
        \renewcommand{\cftchapfont}{\bfseries\color{author#1}}% Chapter colour 
        \renewcommand{\cftsecfont}{\color{author#1}}% Section colour 
        \renewcommand{\cftsubsecfont}{\color{author#1}}}% Subsection colour 
    } 
    \makeatletter 
    \newcommand{\authoredby}[1]{\addtocontents{toc}{\protect\@nameuse{authoredby#1}}}% 
    \makeatother 
    
    \defineauthorcolor{A}{red}% Author A will be coloured red 
    \defineauthorcolor{B}{blue}% Author B will be coloured blue 
    
    \begin{document} 
    
    \tableofcontents 
    
    \authoredby{A} 
    \chapter{A chapter} 
    \authoredby{B} 
    \section{A section} 
    \subsection{A subsection} 
    \authoredby{A} 
    \section{Another section} 
    \subsection{Another subsection} 
    \authoredby{B} 
    \subsection{Yet another subsection} 
    
    \chapter{Another chapter} 
    \section{First section} 
    \section{Second section} 
    \section{Last section} 
    
    \authoredby{A} 
    \chapter{Last chapter} 
    
    \end{document} 
    

    상기 최소 예제의 .toc

    은 다음과 같다 :

    \@nameuse {authoredbyA} 
    \contentsline {chapter}{\numberline {1}A chapter}{3} 
    \@nameuse {authoredbyB} 
    \contentsline {section}{\numberline {1.1}A section}{3} 
    \contentsline {subsection}{\numberline {1.1.1}A subsection}{3} 
    \@nameuse {authoredbyA} 
    \contentsline {section}{\numberline {1.2}Another section}{3} 
    \contentsline {subsection}{\numberline {1.2.1}Another subsection}{3} 
    \@nameuse {authoredbyB} 
    \contentsline {subsection}{\numberline {1.2.2}Yet another subsection}{3} 
    \contentsline {chapter}{\numberline {2}Another chapter}{5} 
    \contentsline {section}{\numberline {2.1}First section}{5} 
    \contentsline {section}{\numberline {2.2}Second section}{5} 
    \contentsline {section}{\numberline {2.3}Last section}{5} 
    \@nameuse {authoredbyA} 
    \contentsline {chapter}{\numberline {3}Last chapter}{7} 
    

    \authoredby{<name>} 각각 사용 따라서 색을 전환 할 TOC에 \@nameuse{authoredby<name>}를 삽입한다. 이 솔루션은 모든 수의 작성자 (두 명으로 제한되지는 않음)에서 작동합니다.

    이 솔루션은 book, reportarticle 문서 클래스에서 작동합니다.