1

I have the following code:

\documentclass[a4paper,12pt]{article} 
\renewcommand{\proofname}{\textbf{Beweis}}
\newtheorem{Satz}{Satz}[section]
\newtheorem{code}[Satz]{MATLAB-Code} 

\begin{document}

\section*{Anhang}
\renewcommand\thesection{\hspace{-1em}}
\sectionmark{Anhang}
\addcontentsline{toc}{section}{Anhang}
\begin{code}
...
\end{code}
\end{document}

The problem is that the number of the code overlaps with the word MATLAB-Code in the appendix (Anhang). I guess it has something to do that there is no section number for the appendix. How can I fix that? If I write

\newtheorem{code}{MATLAB-Code} 

then the number of the newtheorem and the word MATLAB-Code don't overlap, but then the codes get numberes from 1 on instead of using the section number. Thanks a lot!!!

  • Can provide a working example illustrating the problem. Removing [Satz] from the above code makes it compilable, but also does not show any problem with overlapping numbers. – Andrew Swann Nov 27 '13 at 13:44
  • I did exact the same for \newtheorem{Bem}[Satz]{Bemerkung} and there it works. My guess is that MATLAB-Code is too long. – little_miss_sunshine Nov 27 '13 at 13:47
  • There is something you are not telling us. This includes something in the document sets up the count Satz, and possibly theorem related packages you are loading... – Andrew Swann Nov 27 '13 at 13:50
  • you are right, if i delete [Satz] it's working. That's exact how I wanted it, thanks. – little_miss_sunshine Nov 27 '13 at 13:52
  • But then the number of MATLAB-code starts with one, but I want that the number is the chapter number.1, chapter number.2 and so on. – little_miss_sunshine Nov 27 '13 at 13:59
  • Then have a look at Satz what it different in that definition in comparison to the definition to code? Hint: look at the end. – daleif Nov 27 '13 at 14:09
  • Also note that article does not use chapters, but sections. And what on earth, are you doing with that \renewcommand\thesection{\hspace{-1em}}? that is really bad coding. – daleif Nov 27 '13 at 14:27
  • I wanted to get rid of the section number of the Appendix (Anhang). With that command it works, but I guess that's why 'MATLAB-Code' and the code number overlap. – little_miss_sunshine Nov 27 '13 at 14:35
  • Oh, yes. the [section] part of Satz incorporates \thesection to number the Satz. Another lesson is, don't hide stuff in our minimal example – daleif Nov 27 '13 at 14:39
  • You might be interested in the matlab-prettifier package; see this answer. – jub0bs Apr 28 '14 at 16:27

1 Answers1

1

You ask how remove section numbers of theorem like items in the appendix. Redefining \thesection to \hspace{-1em} causes you many problems as you found out.

Instead to remove section numbering of these elements in the appendix use the chngcntr packages's function \counterwithout:

Sample output

\documentclass[a4paper,12pt]{article} 

\usepackage{chngcntr}

\newtheorem{Satz}{Satz}[section]
\newtheorem{code}[Satz]{MATLAB-Code} 

\begin{document}

\section{A section}

\begin{Satz}
  Theorem text.
\end{Satz}

\section*{Anhang}

\counterwithout{Satz}{section}
\sectionmark{Anhang}
\addcontentsline{toc}{section}{Anhang}
\begin{code}
...
\end{code}
\end{document}
Andrew Swann
  • 95,762
  • Thanks for your answer. If I use this code it still shows the section number of the Apeendix in the Header. How can I get rid of that? – little_miss_sunshine Nov 29 '13 at 11:22
  • The above code produces no header, so you will have to tell us how you make your headers. That is probably best done as a separate question. But have a look around this site for related questions. – Andrew Swann Nov 29 '13 at 12:37