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.

Fixed in the new version of ctable

ctan-ann: CTAN Update: ctable 26 May 2012

Might be a stupid question, but is there a way to reference, that means print, the caption of a ctable? hyperref has \nameref for sections, which works for normal floats, but not for ctable. This error is raised:

! Undefined control sequence.
<argument> \Hy@safe@activesfalse \@ctblcap
\relax
l.92 ...kewed towards commodity. \nameref{tab:ef4}

Min example:

\documentclass[pdftex,a4paper, 12pt, DIV12, BCOR10mm, bibliography=totoc]{scrreprt} %DIV, BCOR =Seitenränder
\usepackage{ctable}
\usepackage{hyperref}

\begin{document}

\ref{tab:table} %ok
\ref{tab:ctable} %ok
\autoref{tab:table} %ok
\autoref{tab:ctable} %ok
\nameref{tab:table} %ok 
\nameref{tab:ctable} %error


\begin{table}[h]
\centering
\begin{tabular}{|l|l}
hallo & bello\\
\end{tabular}
\caption{Table}
\label{tab:table}
\end{table}

\ctable[
caption = Ctable, label=tab:ctable,]{ll}
{}{
Hello & bello \LL
}

\end{document}
share|improve this question
    
\nameref (and \autoref) actually DOES work for table captions. –  Axel Sommerfeldt May 26 '12 at 6:48
    
Okay, you are right. Problem is that I am using ctable, where it raises an error. I edited teh original post. –  Narretz May 26 '12 at 7:55
    
Please add a minimal working example (MWE) that illustrates your problem. –  Marco Daniel May 26 '12 at 8:00
    
I added a minimal working example –  Narretz May 26 '12 at 8:08

1 Answer 1

up vote 4 down vote accepted

The problem based on the way how ctable wrote the information to the aux. There you can find the following relevant line:

\newlabel{tab:ctable}{{0.2}{1}{\@ctblcap \relax }{table.0.2}{}}

If you use \nameref{tab:ctable} the argument {\@ctblcap \relax } is called. However the command is undefined and it uses the special character @. Based on this information the first quick fix is:

\makeatletter
 \def\@ctblcap{Table}
 \nameref{tab:ctable} %error
\makeatother

On the other hand you can change the implementation of ctable:

\usepackage{etoolbox} %provided \expandonce
\makeatletter
\def\@ctblCaption{
   \ifx\@ctblcap\undefined\let\@ctblcap\@ctblcaption\fi
   \ifx\@ctblcaption\empty\else
      \def\@ctblcaptionarg{\ifx\@ctbllabel\empty\else\label{\@ctbllabel}\fi
         \@ctblcaption\ \@ctblcontinued\strut}
      \ifx\@ctblcap\empty
      \begingroup
        \edef\x{\endgroup\noexpand\caption[]{\expandonce\@ctblcaptionarg}}
        \x
      \else
      \begingroup
        \edef\x{\endgroup\noexpand\caption[\expandonce\@ctblcap]%
                                          {\expandonce\@ctblcaptionarg}}
        \x
      \fi
   \fi
}
\makeatother

The relevant part are the lines starting with \edef\x. E.g.:

\begingroup
 \edef\x{\endgroup\noexpand\caption[]{\expandonce\@ctblcaptionarg}}
\x

whereby the original code was:

\caption[]{\@ctblcaptionarg}

The command caption doesn't expand the information of its arguments. So in the aux file you have the entry \@ctblcaptionarg. Instead of a complete expansion of \@ctblcaptionarg I used \expandonce which is more robust in this case.

The complete MWE:

\documentclass{scrreprt} %DIV, BCOR =Seitenränder
\usepackage[]{ctable}
\usepackage{etoolbox}
\usepackage{hyperref}

\makeatletter
\def\@ctblCaption{
   \ifx\@ctblcap\undefined\let\@ctblcap\@ctblcaption\fi
   \ifx\@ctblcaption\empty\else
      \def\@ctblcaptionarg{\ifx\@ctbllabel\empty\else\label{\@ctbllabel}\fi
         \@ctblcaption\ \@ctblcontinued\strut}
      \ifx\@ctblcap\empty
      \begingroup
        \edef\x{\endgroup\noexpand\caption[]{\expandonce\@ctblcaptionarg}}
         \x
      \else
      \begingroup
        \edef\x{\endgroup\noexpand\caption[\expandonce\@ctblcap]%
                                          {\expandonce\@ctblcaptionarg}}
        \x
      \fi
   \fi
}
\makeatother

\begin{document}
\begin{verbatim}
\ref{tab:table} %ok
\autoref{tab:table} %ok
\nameref{tab:table} %ok 
\end{verbatim}
\ref{tab:table} %ok
\autoref{tab:table} %ok
\nameref{tab:table} %ok 


\begin{verbatim}
\ref{tab:ctable} %ok
\autoref{tab:ctable} %ok
\nameref{tab:ctable} %error
\end{verbatim}
\ref{tab:ctable} %ok
\autoref{tab:ctable} %ok
\nameref{tab:ctable} %error

\begin{table}[h]
\centering
\begin{tabular}{|l|l}
hallo & bello\\
\end{tabular}
\caption{Table}
\label{tab:table}
\end{table}

\ctable[caption = Ctable, label=tab:ctable,]{ll}{}{
Hello & bello \LL}

\end{document}

I think you should write bug report to the author of ctable.

share|improve this answer
    
Thanks a lot! I sent an email to the author, and linked to this page. –  Narretz May 26 '12 at 9:13

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.