TransWikia.com

[i]makeidx together with scrlayer-scrpage and tabbing in header leads to 'Something's wrong--perhaps a missing item. end{theindex}' error

TeX - LaTeX Asked by JohannesWilde on March 28, 2021

I tried to add an index to one of my documents. This however failed, as the following MWI does as well. The cryptic error message is:

Something's wrong--perhaps a missing item. end{theindex}

The MWI:

documentclass{scrreport}

RequirePackage{scrlayer-scrpage}

cohead[
                {
                begin{tabbing}
                               plain      = header content
                end{tabbing}
                }
                ]
                {
                               header content
                }

usepackage{makeidx}
usepackage{hyperref}

makeindex

begin{document}
                
Test index{indexEntry}.

printindex

end{document}

The problem seems to be the tabbing environment in the plain-style entry of the cohead macro.

Replacing the tabbing environment with a tabular environment removed the error – I am however still wondering what the actual problem is.

Additionally it seems replacing usepackage{makeidx} with usepackage{imakeidx} seems to remove the error for this MWI – not however for my full document.

If anyone has a clue, as to what I did wrong here – please let me know.

Thanks,

Johannes

2 Answers

First, an analysis of the problem

The theindex environment (which is inserted by printindex) changes the definition of item to do something else, which basically breaks all lists. In LaTeX, more things are lists than you may think, including tabbing. Now, when a page ends while that changed definition is in effect, it also affects the header and footer (which are typeset only then), which leads to the error. A somewhat more minimal example producing the error would be

documentclass{scrreprt}

usepackage{scrlayer-scrpage}

cohead{%
  begin{tabbing}
    one = two
  end{tabbing}%
}

begin{document}
                
Hello World!
letitemrelax

end{document}

or even

documentclass{article}

begin{document}
                
letitemrelax
begin{tabbing}
  Hello World!
end{tabbing}

end{document}

What to do about it

Now, we could carefully restore the original meaning of item in the header and get rid of the error. However, I would still advise against this, as the tabbing environment does not play nice with the alignment of the different header parts even then. (Remove letitemrelax from the first example above. Is the header set by cohead in the center?)

Instead, it seems to me that you really want a table.

documentclass[
    headlines=2,
  ]{scrreprt}

usepackage{scrlayer-scrpage}
usepackage{makeidx}
usepackage{hyperref}

usepackage{showframe}

lohead*{left text for alignment and such}
rohead*{right text for alignment and such}
cohead*{%
  strutsmash{%
    begin{tabular}[b]{ l l }
      one & two 
      three & four 
    end{tabular}%
  }%
}

makeindex

begin{document}
                
Testindex{indexEntry}.

printindex

end{document}

MWE output

Some notes on this:

  • showframe is just so we can see the type area.

  • Use headlines=2 to make the header high enough for two lines of text.

  • Use tabular's optional argument to specify the vertical alignment with the rest of the header ([b] for bottom alignment).

  • scrlayer-scrpage puts each of the different parts of the header inside a parbox, which vertically centers its content with surrounding one by default (which would make the [b] from before useless). For some reason, no option is provided to change this. In order to get around this without getting into the internals of the package, I used the following trick: I removed the height of the table using smash and added a strut (a zero-width rule). That is, the content of the cohead now has the width of the tabular and the height of the strut, which leads to the desired alignment.

    Note that this also means that LaTeX can't warn you anymore if your header gets too high (because we remove that height). You would not get a warning even without headlines=2. You will have to check the height yourself.

Correct answer by schtandard on March 28, 2021

I'm not sure what tabbing is doing in that position (it makes LaTeX issue a warning about the head height).

You can fix the issue by specifying that you set the first page style in the index to the one used by scrlayer-scrpage.

documentclass{scrreport}

usepackage{scrlayer-scrpage}
usepackage{imakeidx}
usepackage{hyperref}

cohead[%
  begin{tabbing}
  plain = header content
  end{tabbing}%
]{%
  header content%
}


makeindex
indexsetup{firstpagestyle=plain.scrheadings}

begin{document}

chapter{whatever}

Testindex{indexEntry}.

printindex

end{document}

However, the problem with the head height remains to be solved.

Package scrlayer-scrpage Warning: headheight to low.
(scrlayer-scrpage)                At least 58.8pt needed,
(scrlayer-scrpage)                but only 17.0pt found.
(scrlayer-scrpage)                I'll enlarge headheight, for further
(scrlayer-scrpage)                processing, but you should do this yourself,
(scrlayer-scrpage)                e.g., setting typearea's option
(scrlayer-scrpage)                `headheight=58.8pt'.
(scrlayer-scrpage)                I'll also decrease topmargin on input line 26.

Answered by egreg on March 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP