I just discovered the environment numcases, which upgrades the package cases allowing to number the different cases.

I am also currently using the showlabels package, which puts the name of the label on the PDF, right where you put it in the TeX file. Very useful feature, especially when writing a long document and you want to get the tag name from the PDF scrolling up a page rather than open another TeX file and search for the equation!

Unfortunately, I can't get the numcases environment to work properly with the showlabels package. In particular, I cannot give a label to the last case, otherwise I get the error "Incompatible list can't be unboxed". However, without the showcases package, everything works smoothly. It also works smoothly if I don't label the last case, but of course that's not optimal, cause I need to label all the cases...

Here's an example. Comment/uncomment the line where the showlabels package is included to see the behavior.




a & b \label{a}\\
c & d \label{b}


Does anybody know a workaround for this? I would be fine also with a way to avoid numcases (while getting the same result).


2 Answers 2


I cannot understand why lines of a cases environment should be separately numbered. However, you get the effect with empheq:




&a\qquad & b \label{a}\\
&c\qquad & d \label{b}


enter image description here

  • 3
    Well, when you have a system of equations and you want to refer to one of those, it's more elegant to have a number like 1.2 rather than "the second equation in 1". And yes, align does that, but I also like the braket in front. =)
    – bartgol
    Commented Nov 12, 2014 at 21:34
  • @bartgol I disagree. But the document is yours. ;-)
    – egreg
    Commented Nov 12, 2014 at 21:35
  • Well, if the system has quite a few equations and you want to refer to one in particular, it is more effective to say 1.5 rather than ask the reader to count the equations. Perhaps that's just me. As you said, to each its own. ;-)
    – bartgol
    Commented Nov 12, 2014 at 21:45
  • While this apparently worked in 2014, it now seems to produces two pairs of partially overlapping labels. Commented Nov 20, 2018 at 18:38
  • I blame empheq, of course. :-)
    – egreg
    Commented Nov 20, 2018 at 18:46

One possibility is to use showkeys instead of showlabels (we've had healthy rivalry for a few decades:-) but if you want to stick with the opposition you can add some defensive coding to numcases so that the additional boxes don't break it:

enter image description here



{$$\numc@opts \setbox\z@\hbox
  {\advance\c@equation\@ne\def\@currentlabel{\p@equation\theequation}% local
  $\displaystyle {#1\null}\m@th$}%
  \global\@eqnswtrue\m@th \everycr{}\tabskip\numc@left\let\\\@eqncr
  \halign to\dimen@ii \bgroup \kern\wd\z@ \kern14\p@ % assume width of brace
    \tabskip\z@skip \global\@eqcnt\@ne $\displaystyle{##}$\hfil 
   &\global\@eqcnt\tw@ \skip@10\p@ \advance\skip@\tw@\arraycolsep \hskip\skip@
    ##\unskip\hfil\tabskip\@centering% \unskip removes space if no explanations
   &\global\@eqcnt\thr@@\hbox to\z@\bgroup\hss##\egroup\tabskip\z@skip\cr
}{\@@eqncr \egroup % end \halign, which does not contain first column or brace
%Measure the natural width of the alignment
 \unskip\unpenalty\unskip\unpenalty \setbox\z@\lastbox % grab last line
%%%%% NEW TEST
 \nointerlineskip \copy\z@ % then put it back
 \nointerlineskip \copy\tw@ % then put it back
 \nointerlineskip \copy\z@ % then put it back
%%%%% END NEW
 \setbox\z@\hbox{\hskip-\numc@left\unhbox\z@}% Measure its natural width
 \ifdim \wd\z@<\dimen@i \global\dimen@i\wd\z@ \fi
\egroup% end \vbox (box\tw@, box\z@ is restored to LHS)
\hbox to\dimen@ii{\m@th % assemble the whole equation
  \hbox to\dimen@i{$\displaystyle \box\z@ % parameter #1
    \dimen@\ht\tw@ \advance\dimen@\dp\tw@ % get size of brace
    \left\{\vcenter to\dimen@{\vfil}\right.\n@space % make brace
    $\hfil}\hskip\@centering % finished first part (filled whole line)
  \kern-\dimen@ii % backspace the full width
  $\vcenter{\box\tw@}$% overlay the alignment
 }% end the \hbox to\dimen@ii


a & b {\label{a}}\\
c & d {\label{b}}

  • Interesting option the showkeys. I think I will go with the empheq option proposed by egreg, just cause I was not super fond of numcases to strt with (I had to throw in dollar signs to insert math expressions). Just out of curiosity, what's the up/down side of using showkeys vs showlabels? They look pretty much the same to me at first look...
    – bartgol
    Commented Nov 12, 2014 at 21:41
  • @bartgol they are similar but patch in the output in different ways, both can break things, showkeys got lucky in this case (actually I think it is generally more robust, but then, I would) shame you gave the points to egreg though: he has far too many already:-) Commented Nov 12, 2014 at 21:46
  • LoL: you guys are both in the 100k range. No need for change... ;-) Thanks for your feedback though. I will definitely consider showkeys in the future. =)
    – bartgol
    Commented Nov 12, 2014 at 21:48
  • @DavidCarlisle hrmmmm, I've made this slightly more robust, I think, in 1.7b1 – the rivalry continues! Commented Dec 6, 2014 at 22:01
  • @NormanGray :-) Commented Dec 6, 2014 at 22:17

You must log in to answer this question.

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