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 would like to reproduce a \section at a later position, with the same number as at the original position. I tried

\newsavebox{\meinebox}
\savebox{\meinebox}[80mm][l]{\section{Hier}}
\usebox{\meinebox}
A lot of text.
\usebox{\meinebox}

but LaTeX gives an error,

LaTeX Error: Something's wrong--perhaps a missing \item.

share|improve this question
    
Please tell us more about your document structure: Are sections the top-most sectioning division, or do you have chapter and even part divisions? When the section is re-introduced, do you want to re-use the original chapter and part numbers as well, or just the original section number? Separately, are you looking to replicate just the section header or the header and the entire contents of the section? –  Mico Jan 7 '13 at 21:26
    
Optimal would be a solution which prints again the section-number and name without writing again to the TOC, i.e. I would like to have a "graphical" reproduction without the logical side-effects. –  JF Meier Jan 7 '13 at 21:48
add comment

3 Answers

up vote 1 down vote accepted

If you're looking to reproduce a certain section header (including its "number") without generating a new entry in the Table of Contents, you could proceed as is indicated in the following MWE (minimum working example):

\documentclass{article}
\newcounter{mycounter} % counter to save section number 
\newcommand\myheader{Some header}

\begin{document}
\tableofcontents

\section{\myheader}
\setcounter{mycounter}{\value{section}} % save section number
A lot of text.

\section{Other}
Yet more text.

\section*{\arabic{mycounter}\quad\myheader}
\end{document}

enter image description here

share|improve this answer
add comment

The reason of the error is that \section only works in vertical mode and \savebox uses restricted horizontal mode. Giving it a width doesn't change that. You could use a minipage environment inside the savebox to have vertical mode internal:

\documentclass{article}

\newsavebox{\meinebox}

\begin{document}

\begin{lrbox}{\meinebox}
  \begin{minipage}{\linewidth}
    \section{Hier}
  \end{minipage}
\end{lrbox}

\noindent\usebox{\meinebox}
A lot of text.
\par\noindent
\usebox{\meinebox}

\end{document}

However this will not lead to the same result as using \section normally, because \usebox forces horizontal mode. Better is to use a vertical savebox, which however isn't provided by LaTeX itself. You need to use TeX primitives for that:

\documentclass{article}

\newsavebox{\meinebox}

\begin{document}

\setbox\meinebox\vbox{%
    \section{Hier}
}

\copy\meinebox
A lot of text.
\par
\copy\meinebox

\end{document}

Still, I wouldn't recommend to use boxes at all, but to reset the section counter to the previous value.

\documentclass{article}

\newcounter{mysection}

\begin{document}

\setcounter{mysection}{\value{section}}
\section{Hier}
A lot of text.

\section{Other}

\setcounter{section}{\value{mysection}}
\section{Hier}

\end{document}

Counters are always global with LaTeX, so you need to backup the correct section count if you need it afterwards:

\documentclass{article}

\newcounter{mysection}
\newcounter{mysectionbackup}

\begin{document}

\setcounter{mysection}{\value{section}}
\section{Hier}
A lot of text.

\section{Other}

\setcounter{mysectionbackup}{\value{section}}
\setcounter{section}{\value{mysection}}
\section{Hier}
\setcounter{section}{\value{mysectionbackup}}

\section{Third}

\end{document}

Note that all solutions will cause trouble with section references, hyperlinks and PDF bookmarks because the section counter or its label is used twice.

share|improve this answer
1  
I think even easier would be to use \section{Hier}\edef\savesecnum{\thesection} and later use \section*{\savesecnum \quad Hier}; no need for counter setting and restoring before re-using the section. This will, of course, also remove the section number from the ToC (but this seems desirable). –  Werner Jan 7 '13 at 22:16
add comment

You could put the section text in a separate file and \include or \input it twice. The second time you would surround the inclusion by code to \setcounter{section}{whatever} before and to reset it after.

That will work if you know the section number of the first appearance and the section number before the second. If those numbers arecomputed by \LaTeX on the fly and vary as you edit your document then you will need to remember them for later use - a little tricky but quite possible - see @Werner 's comment above for how to do it.

share|improve this answer
add comment

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.