3

I'm trying do define a new environment using tabu as a building block. The reason to use tabu is that it will break nicely across pages for long tables. I would like to have some help on doing the following:

  1. Create a new type of environment that appears in \listofinterfaces instead of \listoftables;
  2. The caption should read Interface X: text instead of Table X: text; and
  3. There is no need for automatic numbering, since I would prefer to use my own number provided with each table (it's currently the 3rd argument of ryetable); this also means that when I reference the new environment, the number provided is shown and not some automatic counter.

I understand you may need some serious latex voodoo to achieve this but even some pointers on the right direction would be helpful.


\documentclass{article}

\usepackage{array, booktabs, longtable, tabu}

% Usage: {}{<label>}{<ifNum>}{<caption>}
\newenvironment{ryetable}[4]{%
  \gdef\tmpheaders{#1} % Not currently used
  \gdef\tmplabel{\label{#2}} % Save label for later use
  \gdef\tmpifnum{#3} % Save interface number
  \gdef\tmpcaption{\caption{#4}} % Save caption for later use
  \renewcommand{\arraystretch}{1.3} % More space between rows
  \begin{longtabu} to \textwidth {@{} X[1,l] X[1,l] X[1,l] >{\raggedright}X[1,l] @{}}
    \\\toprule\rowfont\bfseries
    Header1 & Header2 & Header3 & Description \\
    \midrule
  \endfirsthead
    \multicolumn{4}{@{}c@{}}{\small\textit{(continued)}}\\
    \toprule\rowfont\bfseries
    Header1 & Header2 & Header3 & Description \\
    \midrule
  \endhead
    \bottomrule
    \multicolumn{4}{@{}r@{}}{\small\textit{(continues)}}\\
  \endfoot
    \bottomrule
    \tmpcaption
    \tmplabel
  \endlastfoot
}{%
  \end{longtabu}
}

\begin{document}
\listoftables
%\listofinterfaces %TODO
\section{MySection}
For a simple table see Table~\ref{tab:somelabel} and for a nifty new environment check Interface~\ref{if:myinterface}.

%TODO: 31 here should be the environment's number
\begin{ryetable}{}{if:myinterface}{31}{This is my pretty interface.}
a & b & c & d\\
e & f & g & h\\
i & j & k & l\\
m & n & o & p\\
q & r & s & t\\
u & v & w & x\\
y & z & -- & --\\
\end{ryetable}


% Some other table to show on list
\begin{table}[h]
  \centering
  \begin{tabular}{c|c}
    a&b\\
    c&d\\
  \end{tabular}
  \caption{Caption of tabular table.}
  \label{tab:somelabel}
\end{table}
\end{document}

enter image description here

0

1 Answer 1

2

Path to a possible solution:

  • Use \caption[]{...} instead of \caption{...} --> no entry to list of tables
  • Within \ryetable redefine \tablename to Interface, it is safe, because it is inside a group.
  • Also redefine \thetable (responsible for printing the 'table' number to your user provided number, also safe for the rest of the environment, since the redefinition occurs inside a group.
  • Define a rough \listofinterfaces command, using a new toc-type int (interfaces) and use @starttoc{int} to read in the toc entries provided by the command \addcontentsline{int}{subsection}{...} within ryetable environment.
  • Reduce the table counter by one, since ryetable increases it automatically, so consequent calls to table environment would have a wrong number.

Code:

\documentclass{article}

\usepackage{array, booktabs, longtable, tabu}

\newcommand{\ListOfInterfacesName}{List of Interfaces}%
\newcommand{\InterfaceName}{Interface}%

\makeatletter%
\newcommand{\listofinterfaces}{%
\section*{\ListOfInterfacesName}%
\@starttoc{int}  % New toc with extension *.int%
\clearpage%
}%
\makeatother%

% Usage: {}{<label>}{<ifNum>}{<caption>}
\newenvironment{ryetable}[4]{%
\renewcommand{\tablename}{\InterfaceName}%
\renewcommand{\thetable}{#3} % Explicitly set the number to the given argument
\addtocounter{table}{-1}%
\addcontentsline{int}{subsection}{\protect{\numberline{#3}{#4}}}%   Define an entry subsection like... (as normal tables)
  \gdef\tmpheaders{#1} % Not currently used
  \gdef\tmplabel{\label{#2}} % Save label for later use
  \gdef\tmpifnum{#3} % Save interface number
  \gdef\tmpcaption{\caption[]{#4}} % Save caption for later use ---> drop the entry to the table list
  \renewcommand{\arraystretch}{1.3} % More space between rows
  \begin{longtabu} to \textwidth {@{} X[1,l] X[1,l] X[1,l] >{\raggedright}X[1,l] @{}}
    \\\toprule\rowfont\bfseries
    Header1 & Header2 & Header3 & Description \\
    \midrule
  \endfirsthead
    \multicolumn{4}{@{}c@{}}{\small\textit{(continued)}}\\
    \toprule\rowfont\bfseries
    Header1 & Header2 & Header3 & Description \\
    \midrule
  \endhead
    \bottomrule
    \multicolumn{4}{@{}r@{}}{\small\textit{(continues)}}\\
  \endfoot
    \bottomrule
    \tmpcaption
    \tmplabel
  \endlastfoot
}{%
  \end{longtabu}
}

\begin{document}
\listoftables
\listofinterfaces %TODO
\section{MySection}
For a simple table see Table~\ref{tab:somelabel} and for a nifty new environment check Interface~\ref{if:myinterface}.

%TODO: 31 here should be the environment's number
\begin{ryetable}{}{if:myinterface}{31}{This is my pretty interface.}
a & b & c & d\\
e & f & g & h\\
i & j & k & l\\
m & n & o & p\\
q & r & s & t\\
u & v & w & x\\
y & z & -- & --\\
\end{ryetable}


% Some other table to show on list
\begin{table}[h]
  \centering
  \begin{tabular}{c|c}
    a&b\\
    c&d\\
  \end{tabular}
  \caption{Caption of tabular table.}
  \label{tab:somelabel}
\end{table}
\end{document} 

enter image description here enter image description here

You must log in to answer this question.

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