Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am writing a short report using the standard book class. In the report we describe about 10 experiments. I would like to define a sectioning command called experiment. This sectioning command should be very similar to that of a standard section. The only difference I would like if possible that it issues a new page and in the contents, the experiments must be shown at the end of the Chapter.

  Chapter 1 Introduction  12
    section 2  .....
    section 3  .....
    experiment 1.2 ....
    experiment 1.3 ....
    experiment 1.4 .... 
share|improve this question
1  
This might be a duplicate of Defining custom sectioning commands. –  Martin Scharrer Dec 2 '11 at 12:56
    
@MartinScharrer This is using the standard classes and I would prefer a solution without the use of a package. –  Yiannis Lazarides Dec 2 '11 at 13:16
3  
The solution there is not KOMA Script specific. Also, redefining something as complex as sectioning commands without a package is not trivial. At least not if you want to get it completely right. –  Martin Scharrer Dec 2 '11 at 13:32
1  
Would an environment be an option instead of a sectioning command? I ask this because you mentioned you don't want to use any additional packages, and a quick solution can be given with an environment. –  Gonzalo Medina Dec 2 '11 at 14:18
1  
Why must the experiments be shown at the end of the chapter in the TOC? Surely, they must be shown where they really are, otherwise it is just very confusing! (So, just put the experiment at the end of the chapter...) A way around this, would be to list the experiments in a additional table at the front, like it is often found as List of Figures or List of Tables. –  Unapiedra Dec 2 '11 at 15:08

1 Answer 1

up vote 6 down vote accepted

Here's one possible solution using an experiment environment: the environment places a title of the form Experiment # with a style similar to that of the standard sections, using a counter that resets with every new chapter; the environment also produces an entry in the ToC. However, the entry will appear where the environment was used (otherwise, as Unapiedra mentioned in a comment, the order in the ToC would be strange); if you want the entries to appear at the end of the entry for a chapter, you'll have to use the environment exactly there.

\documentclass{book}
\usepackage{lipsum}% just to generate text for the example

\newcounter{exp}
\renewcommand\theexp{\thechapter.\arabic{exp}}

\newcommand\experimentname{Experiment}

\makeatletter
\@addtoreset{exp}{chapter}
\makeatother

\newenvironment{experiment}
  {\clearpage
  %\phantomsection % un-comment if hyperref is to be used
  \stepcounter{exp}
  \addcontentsline{toc}{section}{\experimentname~\theexp}
  \noindent{\Large\bfseries\experimentname~\theexp}%
  \par\vspace*{2.3ex plus .2ex}\noindent\ignorespaces}
  {\clearpage}

\begin{document}

\tableofcontents

\chapter{Test Chapter}
\section{Test Section One One}
\lipsum[1]
\begin{experiment}
\lipsum*[1]
\end{experiment}
\section{Test Section One Two}
\lipsum[1]
\begin{experiment}
\lipsum*[1]
\end{experiment}

\end{document}

Another option would be to create a new List of Experiments, similar to the standard "Lists of...". Here's how this can be done:

\documentclass{book}
\usepackage{lipsum}

\newcounter{exp}
\renewcommand\theexp{\thechapter.\arabic{exp}}

\newcommand\experimentname{Experiment}
\newcommand\listexperimentname{List of Experiments}

\makeatletter
\@addtoreset{exp}{chapter}
\newcommand\listofexperiments{\chapter*{\listexperimentname}\@starttoc{exp}}
\makeatother

\newenvironment{experiment}
  {\clearpage
  %\phantomsection % un-comment if hyperref is to be used
  \stepcounter{exp}
\addcontentsline{exp}{section}{\experimentname~\theexp}
  \noindent{\Large\bfseries\experimentname~\theexp}%
  \par\vspace*{2.3ex plus .2ex}\noindent\ignorespaces}
  {\clearpage}

\begin{document}

\tableofcontents
\listofexperiments

\chapter{Test Chapter}
\section{Test Section One One}
\lipsum[1]
\begin{experiment}
\lipsum*[1]
\end{experiment}
\section{Test Section One Two}
\lipsum[1]
\begin{experiment}
\lipsum*[1]
\end{experiment}

\end{document}
share|improve this answer
    
This solution is by no means a complete definition of a new sectioning command; for this kind of definition please follow the link provided in Martin Scharrer's comment to the original question. –  Gonzalo Medina Dec 3 '11 at 19:27
    
Thanks this almost works as I wanted it. Do I need to do anything for the pdf contents? –  Yiannis Lazarides Dec 4 '11 at 19:48
    
@saltypen: You're welcome! Can you please explain in more detail what do you mean with "the pdf contents"? –  Gonzalo Medina Dec 4 '11 at 19:53
    
Sorry I did not see the commented \phantomsection which did the trick. –  Yiannis Lazarides Dec 6 '11 at 20:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.