2

I am attempting to redefine the chapter command to remove the vertical space that appears above the chapter style when placed at the top of the page, while still keeping it in position (that is not making it overlap other text) if used in the middle of a page. I found that vspace only adds space when used in the middle of a page while vspace* adds space all the time I did something like this:

\documentclass[oneside,12pt]{report}
\usepackage{amsmath}
\RequirePackage[style=ieee, backend=biber, citestyle=ieee, natbib=true]{biblatex}

\makeatletter
\let\oldchapter\chapter
\renewcommand*\chapter{
  \@ifstar{\starchapter}{\@dblarg\nostarchapter}
}
\makeatother

\def \extrachpspc{15pt}
\newcommand*\starchapter[1]{
  \vspace{\extrachpspc}\vspace*{-\extrachpspc}\oldchapter*{#1}
}
\def\nostarchapter[#1]#2{
  \vspace{\extrachpspc}\vspace*{-\extrachpspc}\oldchapter[{#1}]{#2}
}

\addbibresource{references.bib}

\begin{document}
\tableofcontents{}
\end{document}

Where space is added before chapter in the middle of the page while also removed when rendered at the top of the page. Leaving chapter rendering without a top margin.

This used to work fine, but I'm guessing I updated some package somewhere (probably a while back because I can't remember) because now I get the following error:

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

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.3 \contentsline {chapter}{\numberline {1}*}{2}

So my questions are:

  • What does the error mean?
  • Is there some conflict with amsmath? Because if I remove the this simple example renders but I need that package later on.
  • Is there another way of achieving what I want?
  • And finally what is wrong with my approach?
1
  • your definitions are missing a lot of % but also the intention is rather hard to understand. \chapter in the report class starts a new page so what do you mean by the distinction between being at top or middle of a page? Commented Mar 22, 2018 at 23:55

1 Answer 1

2

If you use % to remove the spurious spaces added in the macros then the error goes (but the code seems very odd, given that chapters start a new page)

\documentclass[oneside,12pt]{report}
\usepackage{amsmath}
\RequirePackage[style=ieee, backend=biber, citestyle=ieee, natbib=true]{biblatex}

\makeatletter
\let\oldchapter\chapter
\renewcommand*\chapter{%
  \@ifstar{\starchapter}{\@dblarg\nostarchapter}%
}
\makeatother

\def \extrachpspc{15pt}
\newcommand*\starchapter[1]{%
  \vspace{\extrachpspc}\vspace*{-\extrachpspc}\oldchapter*{#1}%
}
\def\nostarchapter[#1]#2{%
  \vspace{\extrachpspc}\vspace*{-\extrachpspc}\oldchapter[{#1}]{#2}%
}

\addbibresource{references.bib}

\begin{document}
\tableofcontents
\end{document}
3
  • Ah, so that, among other things I suppose, is why one sees those %-signs in macro definitions. I seem to remember, the reason for this code is that other I wanted elements such as Table of [figures|algorithms|tables|...] to appear on the same page as one another. Since these elements use the chapter heading I got chapter headings in the middle of the page. These are the only place I use chapters in my report so I thought it fine to renew the command for this purpose. But I suspect that one, in some way, could have changed the TOX heading to a section, not sure how though. Commented Mar 23, 2018 at 9:14
  • @ChristianEriksson if you have no chapters in your report, don't all your sections get numbered as 0.1, 0.2 etc? The intention is that you use article not report in that case. Commented Mar 23, 2018 at 9:47
  • I can't find it in the file at the moment, but I believe the \section numbering has been changed to not show the chapter number. This is one of those templates that has been used forever and no one really knows what has been done or where. For some reason report was chosen over article as the document class, why I don't quite know. However, I agree it might have been better to use article over report in the beginning (unless those reasons mentioned above but don't know were really good) Commented Mar 23, 2018 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .