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 am using ctable and I have a table with footnotes. Since the table is narrow, the caption text is squeezed in the table width, which looks odd. I can use mincapwidth to specify a minimum width for the table environment (not the table itself) which solves this issue, but creates another: it also applies to the footnote, which looks ugly since the footnote is small. Is there a way to make the footnote obey the width of the table itself and ignore mincapwidth?

Example:

\ctable[
caption = {Somewhat long long long caption which is long},
mincapwidth = \textwidth,
]{lr}{
  \tnote[a]{Short footnote}
}{
    \toprule
    Header 1 & Header 2 \\
    \midrule
    foo\tmark[a] & 1 \\
    \bottomrule
}

Which looks like this

End result

share|improve this question
add comment

4 Answers 4

up vote 9 down vote accepted

Here is a solution that adds a new key-value footerwidth (default is the width of the table):

enter image description here

\documentclass{article}
\usepackage{ctable}% http://ctan.org/pkg/ctable
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{xpatch}% http://ctan.org/pkg/etoolbox

\makeatletter
\newdimen\@ctblfooterwidth
\define@key{ctbl}{footerwidth}{\@ctblfooterwidth=#1}
\xpatchcmd{\ctable}% <cmd>
  {{\@ctblbeg}}% <search>
  {{\ifdim\@ctblfooterwidth=0pt
     \@ctblfooterwidth\@ctblw% or \@ctblfloatwidth for default as width of float
   \fi%
   \@ctblbeg}}% <replace> {\@defaultctblmincapwidth%
  {}{}% <success><failure>
\xpatchcmd{\ctable}{\hsize}{\@ctblfooterwidth}{}{}% Patch \ctable
\xpatchcmd{\ctable}{\hsize}{\@ctblfooterwidth}{}{}% Patch \ctable
\makeatother

\begin{document}
\ctable[
caption = {Somewhat long long long caption which is long},
mincapwidth = \textwidth,
]{lr}{
  \tnote[a]{Short footnote}
}{
    \toprule
    Header 1 & Header 2 \\
    \midrule
    foo\tmark[a] & 1 \\
    \bottomrule
}

\ctable[
caption = {Somewhat long long long caption which is long},
mincapwidth = \textwidth,
footerwidth = .5\textwidth
]{lr}{
  \tnote[a]{Short footnote}
}{
    \toprule
    Header 1 & Header 2 \\
    \midrule
    foo\tmark[a] & 1 \\
    \bottomrule
}
\end{document}

xpatch provides the patch to \ctable since it takes an optional argument.

The first patch inserts the appropriate definition of the newly defined dimension \@ctblfooterwidth if it has no length. The second and third patch replaces the default \hsize width of the footnote encasing in either a minipage or tabularx environment, as defined within \ctable originally.

share|improve this answer
add comment

I use, in this cases, a "poor man's ctable":

\documentclass{article}
\usepackage{booktabs}

\makeatletter
\newsavebox{\@tabnotebox}
\providecommand\tmark{} % so having ctable or not is irrelevant
\providecommand\tnote{}
\newenvironment{tabularwithnotes}[3][c]
  {\long\def\@tabnotes{#3}%
   \renewcommand\tmark[1][a]{\makebox[0pt][l]{\textsuperscript{\itshape##1}}}%
   \renewcommand\tnote[2][a]{\textsuperscript{\itshape##1}\,##2\par}
   \begin{lrbox}{\@tabnotebox}
   \begin{tabular}{#2}}
  {\end{tabular}\end{lrbox}%
   \parbox{\wd\@tabnotebox}{
     \usebox{\@tabnotebox}\par
     \smallskip\@tabnotes
   }%
  }
\makeatother

\begin{document}
\begin{table}
\centering
\caption{Somewhat long long long caption which is long}
\medskip
\begin{tabularwithnotes}{lr}
 {
  \tnote[a]{Short footnote}
  \tnote[b]{Short footnote}
 }
\toprule
Header 1 & Header 2 \\
\midrule
foo\tmark[a] & 1\tmark[b] \\
\bottomrule
\end{tabularwithnotes}
\end{table}
\end{document}

The arguments to tabularwithnotes are the same as for tabular, with the notes in an additional argument.

enter image description here

share|improve this answer
add comment

Send a feature request – there should be an option to have the caption set outside the minipage which contains the table and notes. In the meantime, you can make this change yourself:

\makeatletter
\newcommand{\modctable}[4][]{%
   \let\@ctbltaborfig  \@defaultctbltaborfig
   \let\@ctblalign     \@defaultctblalign
   \let\@ctblsideways  \@defaultctblsideways
   \let\@ctblcontinued \empty
   \let\@ctblpos       \@defaultctblpos
   \let\@ctblcaption   \empty
   \let\@ctblcap       \undefined
   \let\@ctbllabel     \empty
   \let\@ctblbotcap    \@defaultctblbotcap
   \let\@ctblstarred   \@defaultctblstarred
   \let\@ctblsuper     \@defaultctblsuper
   \let\@ctblnotespar  \@defaultctblnotespar
   \let\@ctbldoinside  \@defaultctbldoinside
   \@ctblframerule     \@defaultctblframerule
   \@ctblcaptionskip   \@defaultctblcaptionskip
   \@ctblframesep      \@defaultctblframesep
   \@ctblwidth         \@defaultctblwidth
   \@ctblmaxwidth      \@defaultctblmaxwidth
   \@ctblmincapwidth   \@defaultctblmincapwidth
   \def\@ctblfgactual {@defaultctblframefg}
   \def\@ctblbgactual {@defaultctblframebg}
   \def\@ctblbeg      {\begin{\@ctblsideways\@ctbltaborfig\@ctblstarred}}
   \def\@ctblbegin    {\@ctblbeg}
   \def\@ctblend      {\end{\@ctblsideways\@ctbltaborfig\@ctblstarred}}
   \setkeys{ctbl}{#1}
   \ifdim\@ctblwidth=0pt\else
      \ifdim\@ctblmaxwidth=0pt\else
         \PackageError{ctable}{
            You may not use the width and maxwidth options together}{
            Use either width or maxwidth}
      \fi
   \fi
   \ifx\@ctblpos\empty
      \ifx\@ctblsideways\empty\else
      \PackageError{ctable}{
         You may not use the pos and sideways options together}{
         Rotated tables and figures are always typeset on a separate page}
      \fi
   \fi
   \ifx\@ctblcaption\empty
      \ifx\@ctbllabel\empty\else
         \PackageError{ctable}{
            You may not label a captionless table}{
            Such a label can't be referenced}
      \fi
   \fi
   \sbox\ctbl@t{%
      \@ctblXcolumntype{l}% temporarily make  type X = l
      \@ctblframe{\@ctblfgactual}{\@ctblbgactual}{%
         \@ctbldoinside
         \begin{tabular}{#2}
            #4%
         \end{tabular}%
      }%
   }%
   \newif\if@ctblusex\@ctblusexfalse
   \ifdim\@ctblmaxwidth=0pt
      \ifdim\@ctblwidth=0pt
      \else
         \@ctblusextrue
      \fi
   \else
      \ifdim\wd\ctbl@t>\@ctblmaxwidth
         \@ctblusextrue
      \fi
   \fi
   \if@ctblusex
      \sbox\ctbl@t{%
         \@ctblXcolumntype{Y}% restore X
         \@ctblframe{\@ctblfgactual}{\@ctblbgactual}{%
            \@ctbldoinside
            \begin{tabularx}{\ifdim\@ctblwidth>0pt\@ctblwidth\else\@ctblmaxwidth\fi}{#2}
               #4%
            \end{tabularx}%
         }%
      }%
   \fi
   \@ctblw=\wd\ctbl@t
   \@ctblfloatwidth=\ifdim\@ctblmincapwidth>\@ctblw
      \@ctblmincapwidth
   \else
      \@ctblw
   \fi
   \@ctblbegin
      \ifx\@ctblcontinued\empty\else\addtocounter{\@ctbltaborfig}{-1}\fi
      \@ctblalign
      \@ctblCaption
      \begin{minipage}{\@ctblfloatwidth}\parindent0pt
         %%%%\ifx\@ctblbotcap\@ctblfalse\@ctblCaption\vskip\@ctblcaptionskip\fi
         \centering{\usebox\ctbl@t} % insert the tabular
         \def\@ctblfootnotes{#3}%
         \ifx#3\empty\else{% append footnotes, if any
            \footnotesize
            \ifx\@ctblnotespar\@ctbltrue%
               \\[.2ex]
               \begin{minipage}{\hsize}%
                  #3%
               \end{minipage}%
            \else%
               \\
               \begin{tabularx}{\hsize}{r@{\,}>{\raggedright}X}
                  #3%
               \end{tabularx}%
            \fi

         }
         \fi
         %%%%\ifx\@ctblbotcap\@ctbltrue\vskip\@ctblcaptionskip\@ctblCaption\fi
      \end{minipage}
   \@ctblend
}
\makeatother

Then the command in-text becomes:

\modctable[
caption = {Somewhat long long long caption which is long},
]{lr}{
  \tnote[a]{Short footnote}
}{
    \toprule
    Header 1 & Header 2 \\
    \midrule
    foo\tmark[a] & 1 \\
    \bottomrule
}
share|improve this answer
add comment

First, you should not use the booktabs commands explicitly, they are used internally, with modifications. Use \FL, \ML, \LL, see my sample text below. Second: are you using ctable v1.21 or higher?

I suggest that I introduce an option footerwidth which:
- if absent changes nothing (obviously)
- if present without a value sets footnotes in the width of the tabular
- if present with a value, sets footnotes in the width of that value
Any better ideas?

An example:

\documentclass{article}
\usepackage{ctable}
\usepackage[papersize={150mm,100mm},noheadfoot,margin=5mm]{geometry}
\pagestyle{empty}
\begin{document}

\ctable[
  caption = {Somewhat long caption, no footerwidth set},
  mincapwidth = \textwidth,
]{lr}{
  \tnote[a]{Short footnote}
}{\FL
  Header 1 & Header 2 \ML
  foo\tmark[a] & 1 \LL
}

\ctable[
  caption = {Somewhat long caption, footerwidth set, without a value},
  mincapwidth = \textwidth,
  footerwidth
]{lr}{
  \tnote[a]{Short footnote}
}{\FL
  Header 1 & Header 2 \ML
  foo\tmark[a] & 1 \LL
}

\ctable[
  caption = {Somewhat long caption, no footerwidth set to 15mm},
  mincapwidth = \textwidth,
  footerwidth = 15mm
]{lr}{
  \tnote[a]{Short footnote}
}{\FL
  Header 1 & Header 2 \ML
  foo\tmark[a] & 1 \LL
}
\end{document}

This produces:

End result

share|improve this answer
    
Your existing example does not contain a definition of the footerwidth key. Please add this definition to create a standalone document. –  Werner May 27 '12 at 15:03
    
Yes, I'm using 1.21. I wasn't aware of \FL etc, thanks! The footerwidth option you have suggested would be perfect. –  Conrado PLG May 27 '12 at 17:48
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.