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'm trying to show linenumbers for tables using lineno, i.e. edtable. The table is set using threeparttable and linenumbers work fine, but compilation fails when including a caption. The error message shown is you can't use \hrule here except with leaders. I use the caption package, but compilation also fails when using KOMA captions. The MWE illustrates the issue.

\documentclass{scrartcl}

\usepackage{threeparttable}
\usepackage{caption}
\usepackage[edtable]{lineno}

% That's the definition of caption@hrule from caption3.sty
% Redefine something here?
% \makeatletter
% \renewcommand*\caption@hrule{\hrule\@height\z@}
% \makeatother

\begin{document}

\begin{table}\centering
\begin{threeparttable}
\caption{A simple table}
\resetlinenumber[1]
\begin{edtable}{tabular}{l*{3}{c}}
                          & \multicolumn{1}{c}{(1)}   & \multicolumn{1}{c}{(2)}   & \multicolumn{1}{c}{(3)}   \\
Variable 1                &  1.85                     & 0.92                      & 1.11                      \\
                          & (0.34)                    & (0.24)                    & (0.14)                    \\
\end{edtable}
\end{threeparttable}
\end{table}

\end{document}
share|improve this question
1  
Never an easy question? ;-) –  egreg Dec 2 '12 at 16:45
    
@egreg Sorry ;-). Brilliant answer, as usual. –  Jörg Dec 2 '12 at 17:09
add comment

1 Answer 1

up vote 3 down vote accepted

After some headaches:

\documentclass{scrartcl}

\usepackage[edtable]{lineno}
\usepackage{caption}
\usepackage{threeparttable}

\usepackage{xpatch}
\makeatletter
\newenvironment{etabular}
  {\resetlinenumber[1]\let\@centercr\relax\edtable{tabular}}
  {\endedtable}
\newenvironment{etabular*}
  {\resetlinenumber[1]\let\@centercr\relax\edtable{tabular*}}
  {\endedtable}

\catcode`\*=11
\xpatchcmd{\threeparttable}
 {\TPT@hookarg{tabularx}}
 {\TPT@hookarg{tabularx}\TPT@hookin{etabular}\TPT@hookarg{etabular*}}
 {}{}
\catcode`\*=12
\makeatother


\begin{document}

\begin{table}\centering
\begin{threeparttable}[b]
\caption{A simple table}
\begin{etabular}{l*{3}{c}}
           & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} \\
Variable 1 &  1.85\tnote{1}          & 0.92                    & 1.11                    \\
           & (0.34)                  & (0.24)                  & (0.14)                  \\
\end{etabular}
\begin{tablenotes}
\item[1] A note
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}
  1. The edtable environment should be made known to threeparttable;

  2. however we can't pass it to the hooks, because edtable has an optional argument, so I use a "wrapper" for it;

  3. the command \resetlinenumber is not allowed in threeparttable, so I hide it in the new environment;

  4. a \@centercr emitted by edtable causes the infamous "Perhaps a missing \item" error, so I neutralize it;

  5. the \threeparttable environment is patched to made the etabular environment known to it (see this answer).

Similar patches are made for the etabular* environment that internally calls \begin{edtable}{tabular*}. One has to use \TPT@hookarg instead of \TPT@hookin, in this case, like for tabular*.

enter image description here

share|improve this answer
    
If anyone else wants to use this: As noted in the edtable style file, lineno does not support "sub"-linenumbers. This means that if you reset the linenumber for tables as in the answer above, the linenumber of the document will be reset as well from where the table is included. I solved this by creating a second set of lineno.sty and edtable.sty where all the relevant macros have new names. It works, but is not a very pretty solution. –  Jörg Dec 5 '12 at 13:39
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.