Graphics, Figures & TablesThe text insted of chapter number

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Alex_1988
Posts: 1
Joined: Fri Mar 06, 2015 7:15 pm

The text insted of chapter number

Post by Alex_1988 »

Hallo.
I just get some code from http://tex.stackexchange.com/questions/ ... f-contents and modify it for my purpose)).
But I need some variable text parameter or command for using insted of chapter number in the Table of Contents.
Something like new command for example:

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

and this must create new chapter with number of "683(19)-021-15-T1" and name
"The modernisation of energetic system of someplace" like

683(19)-021-15-T1
The modernisation of energetic system of someplace................15


or so.

Can you explain how can I do it?
There is "my" working code and a screenshot of created pdf file, but to my shame, I'm not too versed in the code of latex and didn't succeed in solving this problem((.

Code: Select all

\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}
Attachments
Table of contents.png
Table of contents.png (67.1 KiB) Viewed 2192 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

The text insted of chapter number

Post by Johannes_B »

This is a crosspost to TeX.SX.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply