Text FormattingTOC for custom item (new environment)

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
august_month
Posts: 12
Joined: Sat May 07, 2011 3:03 pm

TOC for custom item (new environment)

Post by august_month »

Hello Everyone!

I created the following new environment:

Code: Select all

\newenvironment{question}{\stepcounter{Questioncounter}
{\bf  Question.} \arabic{Questioncounter} }{\vspace{12pt}}{\begin{it}
\end{it} }
I would like to include this environment into TOC. Could anybody suggest something?
Last edited by august_month on Sat May 07, 2011 5:07 pm, edited 3 times in total.

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

TOC for custom item (new environment)

Post by Stefan Kottwitz »

Hi August,

welcome to the board!

A small tip first: the forum has code formatting, you can use the Code button above the edit field to mark code. I just did that for you.

Regarding your question: you can use one of the commands \addcontentsline and \addtocontents for that. If you follow the links, you can see the syntax.

Stefam
LaTeX.org admin
august_month
Posts: 12
Joined: Sat May 07, 2011 3:03 pm

TOC for custom item (new environment)

Post by august_month »

Thank you very much, Stefan!

Here is how I updated the code:

Code: Select all

\newenvironment{question}{\stepcounter{Questioncounter} {\bf  Question.} \arabic{Questioncounter}  \addcontentsline{toc}{section}{Questioncounter} }{\vspace{12pt}}{\begin{it}
\end{it} }
Now I get Questioncounter with page number in TOC, but I want to have Question (question number) then page number in TOC

Something like : Question 7 ........ 60

Is this possible?

Thanks again!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

TOC for custom item (new environment)

Post by Stefan Kottwitz »

Yes, you can write

Code: Select all

\addcontentsline{toc}{section}{Question \theQuestioncounter}
\thecountername prints the value resp. presentation of a counter.

Stefan
LaTeX.org admin
august_month
Posts: 12
Joined: Sat May 07, 2011 3:03 pm

Re: TOC for custom item (new environment)

Post by august_month »

Awesome!!! I am impressed with capabilities of latex!!!

Thank you again!
Post Reply