文本代替章节编号

文本代替章节编号

我刚刚从漂亮的目录并根据我的目的对其进行修改)。但我需要一些可变文本参数或命令来代替目录中的章节编号。例如新命令:

\MyChapter{683(19)-021-15-T1}{The modernization of energetic system of someplace}

这必须创建新章节,编号为“683(19)-021-15-T1”,名称为“某地能源系统的现代化”,例如

683(19)-021-15-T1

某地能源系统的现代化................................15

或者。

你能解释一下我该怎么做吗?

这是“我的”工作代码和创建的 pdf 文件的屏幕截图,但遗憾的是,我不太熟悉 latex 的代码,所以没有成功解决这个问题((。你能解释一下我该怎么做吗?这是“我的”工作代码,但遗憾的是,我不太熟悉 latex 的代码,所以没有成功解决这个问题((。 在此处输入图片描述

\documentclass[a4paper,14pt]{extreport}
% debugging page breaks, but too short pageheight gives bad page breaks
% anyhow, despite my best efforts
%\usepackage[paperheight=12cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{framed}
\usepackage{tikz}
\usepackage{lmodern}
\usepackage{etoc}
\usepackage[unicode,hidelinks]{hyperref}

%% THE FOLLOWING IS TAKEN (STOLEN) VERBATIM 
%% FROM GONZALO MEDINA'S ANSWER
% definition of some personal colors
\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

% command for the circle for the number of part entries
\newcommand\Circle[1]{\tikz[overlay,remember picture] 
    \node[draw,circle, text width=18pt,line width=1pt,align=center] {#1};}

%% (jfbu) This defines an adjustable length, which gives the position of the
%% section and subsection from the left document margin.
\newlength{\tocmargin}
% Its value is set in the \etocsettocstyle command below, after \sffamily

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% USE OF framed package
\newenvironment{tocleftbar}
{\def\FrameCommand {\hspace{\dimexpr\tocmargin-4pt\relax}%
        {\color{myyellow}\vrule width 2.5pt depth 6pt}\hspace{10pt}%
        \hspace{-\tocmargin}}% 
    \MakeFramed {\leftskip\tocmargin\rightskip\tocmargin\FrameRestore}}
{\endMakeFramed}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\etocsetstyle{part}
{\nobreak\etocskipfirstprefix }
{\pagebreak[3]}% makes a page break before a Part favorable
{% debugging:
    \addvspace{1.15\baselineskip}%
    {\huge\centering
        \color{myyellow}\Circle{\makebox[0pt][c]{\etocnumber}}\\*[2.5ex]%
        \color{myred}{\Huge \etocname}\par}}
{}

\newif\ifintocleftbar

\etocsetstyle{chapter}
% don't break immediately after Part
{\nobreak\etocskipfirstprefix}
% but allow break after section or subsection
{\pagebreak[2]}
{% it seems that framed's code too easily allows a page break 
    % if some vertical glue is here, so let's use a \kern
    \kern\baselineskip
    \begin{tocleftbar}
        \intocleftbartrue
        \makebox[0pt][r]{\smash{\parbox{6em}%
                {\null\vspace*{5pt}\hfill\Huge\bfseries\color{myred}\etocpage
                    \hspace*{20pt}}}}%
        % use of \parbox, else framed.sty has a tendency to allow page breaks if
        % multi-line name
        \parbox[t]{\dimexpr\hsize-2\tocmargin\relax}
        {\large\textbf{\etoclink{Chapter~\etocthenumber}}%
            %\\* does not do what I want. \par\nobreak does.
            % But as we are now in \parbox, does not matter
            \par\etocname\rule[-\baselineskip]{0pt}{0pt}}%
        \par
        \normalsize\leftskip\dimexpr\leftskip+52pt\relax}
    {}

    \etocsetstyle {section}
    % avoid break after Chapter
    {\nopagebreak[3]\vspace{-5pt}\etocskipfirstprefix}
    % allow break after previous subsection or section
    {\vspace {1pt plus .2pt minus .2pt}}
    {\makebox[0pt][r]{\makebox[2.5em][l]{\etocnumber}}%
        \etocname
        \dotfill\nobreak{\itshape\color{myred}\etocpage}\par }
    {\end{tocleftbar}}

% IMPORTANT: this is ALSO executed if the last thing before the next chapter is a subsection

\etocsetstyle {subsection}
% avoid break immediately after section
{\nopagebreak[2]\vspace{1pt}\etocskipfirstprefix}
{\vspace {1pt plus .2pt minus .2pt}}%
{\makebox[0pt][r]{\makebox[2.5em][l]{\etocnumber}}\etocname
    \dotfill\nobreak{\itshape\color{myred}\etocpage}\par}
{}

\etocsettocstyle{\sffamily\setlength{\tocmargin}{4em}%
    {\Huge\bfseries\color{myred}\contentsname\par}%
    \leftskip 0pt\parindent 0pt }{}

\etocsetlevel {appendix}{0}


%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
%=====================================================================================
\begin{document}
    % Use \tableofcontents* for memoir class, as the TOC itself should not
    % appear as a Chapter in the TOC. The * works also with book/report+etoc
    % but does nothing. 
    % With memoir and without *, the TOC defines a  not-very aesthetic
    % chapter entry in itself and one must un-comment the more complicated
    % etoc style for chapter above.
    % debugging
    % \hrule
\tableofcontents*

\part{Designing with \TeX\ and \LaTeX}

\localtableofcontents

\chapter{Beginning to learn design with \TeX}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\subsection{A test subsection with a long title spanning more than one line in the table of contents}
\section{Another test section}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection with a long title spanning more than one line in the table of contents}

% If this is un-commented the more sophisticated chapter style must be used.
%\chapter{A lone chapter without any sections}

\chapter{Beginning to learn design with \LaTeX}
\section{A test section with a long title spanning more than one line in the table of contents}
\subsection{A test subsection}
\subsection{Another test subsection}
\section{A test section}
\ifdefined\phantomsection\phantomsection\fi
\addcontentsline{toc}{section}{Test unnumbered section}
\section*{Test unnumbered section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}


\newpage\setcounter{page}{123}% just for the example

\part{Designing with HTML}

\localtableofcontents

\chapter{Beginning to learn design with HTML and some other text to span more than one line} 
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section with a long title spanning more than one line in the table of contents}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}



\chapter{Beginning to learn design with HTML and some other text to span more than one line} 
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection with a long title spanning more than one line in the table of contents}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}

\part{Designing with HTML1}

\localtableofcontents

\chapter{Beginning to learn design with HTML and some other text to span more than one line} 
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}

\part{Designing with HTML2}

\localtableofcontents

\chapter{Beginning to learn design with HTML and some other text to span more than one line} 
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}

\part{Designing with HTML3}

\localtableofcontents

\chapter{Beginning to learn design with HTML and some other text to span more than one line} 
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}

\part{Designing with HTML4}

\localtableofcontents

\chapter{Beginning to learn design with HTML and some other text to span more than one line} 
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}

\appendix

\chapter{Test Appendix}
\section{Another test section}
\section{Another test section with a long title spanning more than one line in the table of contents}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}


\end{document}

答案1

您选择了一个非常复杂的设计,但这并不能帮助您明确您的目标。

这是一种方法。查看靠近的代码部分。还请查看正文中的输入%%%%%% //////////// CHANGES FOR QUESTION方式。\chapter

如果不是之前那些庞大的宏,解释起来会更简单。我不得不保留大部分的序言,因为在我这个年纪,修改这些内容太复杂了,但我删除了大部分文档正文。

\documentclass[a4paper,14pt]{extreport}
\usepackage[table]{xcolor}
\usepackage{framed}
\usepackage{tikz}
\usepackage{lmodern}
\usepackage{etoc}
\usepackage[unicode,hidelinks]{hyperref}

\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

\newcommand\Circle[1]{\tikz[overlay,remember picture] 
    \node[draw,circle, text width=18pt,line width=1pt,align=center] {#1};}

%% This defines an adjustable length, which gives the position of the
%% section and subsection from the left document margin.
\newlength{\tocmargin}
% Its value is set in the \etocsettocstyle command below, after \sffamily

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% USE OF framed package
\newenvironment{tocleftbar}
{\def\FrameCommand {\hspace{\dimexpr\tocmargin-4pt\relax}%
        {\color{myyellow}\vrule width 2.5pt depth 6pt}\hspace{10pt}%
        \hspace{-\tocmargin}}% 
    \MakeFramed {\leftskip\tocmargin\rightskip\tocmargin\FrameRestore}}
{\endMakeFramed}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\etocsetstyle{part}
{\nobreak\etocskipfirstprefix }
{\pagebreak[3]}% makes a page break before a Part favorable
{% debugging:
    \addvspace{1.15\baselineskip}%
    {\huge\centering
        \color{myyellow}\Circle{\makebox[0pt][c]{\etocnumber}}\\*[2.5ex]%
        \color{myred}{\Huge \etocname}\par}}
{}

\newif\ifintocleftbar

\etocsetstyle{chapter}
% don't break immediately after Part
{\nobreak\etocskipfirstprefix}
% but allow break after section or subsection
{\pagebreak[2]}
{% it seems that framed's code too easily allows a page break 
    % if some vertical glue is here, so let's use a \kern
    \kern\baselineskip
    \begin{tocleftbar}
        \intocleftbartrue
        \makebox[0pt][r]{\smash{\parbox{6em}%
                {\null\vspace*{5pt}\hfill\Huge\bfseries\color{myred}\etocpage
                    \hspace*{20pt}}}}%
        % use of \parbox, else framed.sty has a tendency to allow page breaks if
        % multi-line name
        \parbox[t]{\dimexpr\hsize-2\tocmargin\relax}
        {\large\textbf{\etoclink{Chapter~\etocthenumber}}%
            %\\* does not do what I want. \par\nobreak does.
            % But as we are now in \parbox, does not matter
            \par\etocname\rule[-\baselineskip]{0pt}{0pt}}%
        \par
        \normalsize\leftskip\dimexpr\leftskip+52pt\relax}
    {}

    \etocsetstyle {section}
    % avoid break after Chapter
    {\nopagebreak[3]\vspace{-5pt}\etocskipfirstprefix}
    % allow break after previous subsection or section
    {\vspace {1pt plus .2pt minus .2pt}}
    {\makebox[0pt][r]{\makebox[2.5em][l]{\etocnumber}}%
        \etocname
        \dotfill\nobreak{\itshape\color{myred}\etocpage}\par }
    {\end{tocleftbar}}

% IMPORTANT: this is ALSO executed if the last thing before the next chapter is a subsection

\etocsetstyle {subsection}
% avoid break immediately after section
{\nopagebreak[2]\vspace{1pt}\etocskipfirstprefix}
{\vspace {1pt plus .2pt minus .2pt}}%
{\makebox[0pt][r]{\makebox[2.5em][l]{\etocnumber}}\etocname
    \dotfill\nobreak{\itshape\color{myred}\etocpage}\par}
{}

\etocsetlevel {appendix}{0}



%%%%%% //////////// CHANGES FOR QUESTION:
%%%%%%         THE TEXT INSTEAD OF CHAPTER NUMBER
\etocsettocstyle
   {\sffamily\setlength{\tocmargin}{4em}%
         {\Huge\bfseries\color{myred}\contentsname\par}%
         \leftskip 0pt\parindent 0pt 
    \DeclareRobustCommand *{\Alex}[2]{##1\par ##2}%
    }
   {}


\DeclareRobustCommand *{\Alex}[2]{#2}
%%%%%%
%%%%%% //////////// SEE BELOW HOW \chapter ARE WRITTEN

\begin{document}
\tableofcontents*

\part{Designing with \TeX\ and \LaTeX}

\chapter{\Alex {683(19)-021-15-T1}{Beginning to learn design with \TeX}}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}

\chapter{\Alex {305(53)-091-13-LY1}{Beginning to learn design with \LaTeX}}
\section{A test section with a long title spanning more than one line in the table of contents}
\subsection{A test subsection}
\subsection{Another test subsection}
\section{A test section}

\end{document}

以下是目录:

etoc 搞笑 toc

为了说明这一点,以下是正文中的一章:

搞笑篇章

相关内容