표준 \section 을 사용하지 않고 기사 클래스에 \tableofcontents 생성하기

표준 \section 을 사용하지 않고 기사 클래스에 \tableofcontents 생성하기

\tableofcontents표준 s를 사용하지 않고 기사 클래스에서 를 생성하는 방법이 있지만 \section다른 " \section" 번호 매기기 체계가 사용되었습니까? 특히 David Carlisle의 답변 중 두 번째 부분을 참조하세요.하위 섹션이 많은 문서를 만드는 가장 좋은 방법은 무엇입니까?. 표준이 \tableofcontents작동하지 않는 것 같습니다. 저는 LaTeX를 처음 접했지만 완벽하게 잘 작동하는 \label것을 보고 놀랐습니다 .\ref

편집: 예를 들어 첫 번째 또는 첫 번째 및 두 번째 제목 수준(\setcounter{toclength}{2}이 작동하는 것처럼 보이는 방식)을 포함하는 목차를 만들고 싶습니다. 위에서 참조한 코드는 다음과 같습니다.

\documentclass{article}

\newcounter{depth}
\setcounter{depth}{1}
\newcounter{pi}
\newcounter{pii} [pi]  \renewcommand\thepii{\thepi.\arabic{pii}}
\newcounter{piii}[pii] \renewcommand\thepiii{\thepii.\arabic{piii}}
\newcounter{piv} [piii]\renewcommand\thepiv{\thepiii.\arabic{piv}}
\newcounter{pv}  [piv] \renewcommand\thepv{\thepiv.\arabic{pv}}


\def\psetdepth#1#2\relax{%
\ifx+#1\relax\addtocounter{depth}{#2}%
\else\ifx-#1\relax\addtocounter{depth}{-#2}%
\else\setcounter{depth}{#1#2}\fi\fi}

\newcommand\sentence[2][+0]{%
  \par
  \psetdepth#1\relax\relax
  \vspace{\csname pspace\roman{depth}\endcsname}%
  \hspace{\csname phspace\roman{depth}\endcsname}%
  \hangindent=\csname pindent\roman{depth}\endcsname
  \hangafter=1
  \indent\refstepcounter{p\roman{depth}}\llap{\csname thep\roman{depth}\endcsname\ }%
  {\csname pstyle\roman{depth}\endcsname#2\par}}

\newcommand\phspacei{20pt}
\newcommand\phspaceii{40pt}
\newcommand\phspaceiii{65pt}
\newcommand\phspaceiv{100pt}
\newcommand\phspacev{140pt}

\newcommand\pindenti{5ex}
\newcommand\pindentii{10ex}
\newcommand\pindentiii{15ex}
\newcommand\pindentiv{23.5ex}
\newcommand\pindentv{32.5ex}

\newcommand\pspacei{15pt}
\newcommand\pspaceii{15pt}
\newcommand\pspaceiii{10pt}
\newcommand\pspaceiv{10pt}
\newcommand\pspacev{10pt}

\newcommand\pstylei{\Large\bfseries}
\newcommand\pstyleii{\bfseries\itshape}
\newcommand\pstyleiii{\normalfont}
\newcommand\pstyleiv{\normalfont}
\newcommand\pstylev{\normalfont}

\begin{document}

\raggedright

\sentence{This is a sentence.}

\sentence{This is another sentence. Just like any other sentence one would think but perhaps not.}


\sentence[+1]{This sentence is similar to the others, but longer. This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}


\sentence{This is a sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}


\sentence[+1]{This is another sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}


\sentence[+1]{This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}


\sentence{This is a sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}

\sentence{This is another sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}

\sentence{This sentence is similar to the others, but longer.}

\sentence[+1]{Hey there how is it going my good friend. Hey there how is it going my good friend.}

\sentence[-2]{This is a sentence hey.}

\sentence{This is another sentence.}

\sentence{This sentence is similar to the others, but longer.}

\sentence[-1]{This is a sentence.}

\end{document}

답변1

캔 은 TOC 수준을 카운터 값으로 매핑하여 ToC생성됩니다 .\addcontentslinedepth

코드

\ifcase\c@depth
 \or
  \def\tocstyle{section}
  \or 
  \def\tocstyle{subsection}
  \or
  \def\tocstyle{subsubsection}
  \or
  \def\tocstyle{paragraph}
  \or
  \def\tocstyle{subparagraph}
\fi

\tocstyle의 값에 따라 매크로를 정의합니다 depth. 여기서는 등을 1의미합니다 .section

라인은 \addcontentsline{toc}{\toclevel}{\protect\numberline{}#2}ToC에 라인을 추가하고 를 hyperlinks사용할 때 필요한 경우 를 생성합니다 hyperref.

tocdepth값으로 설정하면 2일반 단면 수준과 마찬가지로 처음 두 수준만 허용됩니다.

\documentclass{article}

\newcounter{depth}
\setcounter{depth}{1}
\newcounter{pi}
\newcounter{pii} [pi]  \renewcommand\thepii{\thepi.\arabic{pii}}
\newcounter{piii}[pii] \renewcommand\thepiii{\thepii.\arabic{piii}}
\newcounter{piv} [piii]\renewcommand\thepiv{\thepiii.\arabic{piv}}
\newcounter{pv}  [piv] \renewcommand\thepv{\thepiv.\arabic{pv}}


\def\psetdepth#1#2\relax{%
\ifx+#1\relax\addtocounter{depth}{#2}%
\else\ifx-#1\relax\addtocounter{depth}{-#2}%
\else\setcounter{depth}{#1#2}\fi\fi}

\setcounter{tocdepth}{2}

\makeatletter
\newcommand\sentence[2][+0]{%
  \par
  \psetdepth#1\relax\relax
  \vspace{\csname pspace\roman{depth}\endcsname}%
  \hspace{\csname phspace\roman{depth}\endcsname}%
  \hangindent=\csname pindent\roman{depth}\endcsname
  \hangafter=1
  \indent\refstepcounter{p\roman{depth}}\llap{\csname thep\roman{depth}\endcsname\ }%
  \ifcase\c@depth
  \or
  \def\tocstyle{section}
  \or 
  \def\tocstyle{subsection}
  \or
  \def\tocstyle{subsubsection}
  \or
  \def\tocstyle{paragraph}
  \or
  \def\tocstyle{subparagraph}
  \fi
  {\csname pstyle\roman{depth}\endcsname#2\addcontentsline{toc}{\tocstyle}{\protect\numberline{\csname thep\roman{depth}\endcsname}#2}\par}} 
\makeatother

\newcommand\phspacei{20pt}
\newcommand\phspaceii{40pt}
\newcommand\phspaceiii{65pt}
\newcommand\phspaceiv{100pt}
\newcommand\phspacev{140pt}

\newcommand\pindenti{5ex}
\newcommand\pindentii{10ex}
\newcommand\pindentiii{15ex}
\newcommand\pindentiv{23.5ex}
\newcommand\pindentv{32.5ex}

\newcommand\pspacei{15pt}
\newcommand\pspaceii{15pt}
\newcommand\pspaceiii{10pt}
\newcommand\pspaceiv{10pt}
\newcommand\pspacev{10pt}

\newcommand\pstylei{\Large\bfseries}
\newcommand\pstyleii{\bfseries\itshape}
\newcommand\pstyleiii{\normalfont}
\newcommand\pstyleiv{\normalfont}
\newcommand\pstylev{\normalfont}

\begin{document}
\tableofcontents
\raggedright

\sentence{This is a sentence.}

\sentence{This is another sentence. Just like any other sentence one would think but perhaps not.}


\sentence[+1]{This sentence is similar to the others, but longer. This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}


\sentence{This is a sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}


\sentence[+1]{This is another sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}


\sentence[+1]{This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}


\sentence{This is a sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}

\sentence{This is another sentence.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.This sentence is similar to the others, but longer.}

\sentence{This sentence is similar to the others, but longer.}

\sentence[+1]{Hey there how is it going my good friend. Hey there how is it going my good friend.}

\sentence[-2]{This is a sentence hey.}

\sentence{This is another sentence.}

\sentence{This sentence is similar to the others, but longer.}

\sentence[-1]{This is a sentence.}

\end{document}

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

관련 정보