2

I have a table environment with a set caption.

I want the caption to be singular for tables with one row and plural for tables with multiple rows, all using the same environment.

Is that achievable and if so, how can I achieve it?

Here's an example:

\documentclass{article}
\usepackage[font=large,font=bf,justification=justified,singlelinecheck=false]{caption}
\newenvironment{Content}{\caption*{Contents}
\begin{tabular}{ll}}{\end{tabular}\vspace{0\baselineskip}}
\begin{document}
\begin{table}
\begin{Content}
test1 & test1 (want the caption for this one to be 'Content' instead)\\
\end{Content}

\begin{Content}
test2 & test2\\
test2 & test2\\
\end{Content}
\end{table}
\end{document}
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Symbol 1 Mar 15 '15 at 23:14
  • 1
    Why same environment? Easiest is to use two environments content and contents. – user11232 Mar 15 '15 at 23:14
2

enter image description here

\documentclass{article}
\usepackage[font=large,font=bf,justification=justified,singlelinecheck=false]{caption}
\newenvironment{Content}{\zz\caption*{Content\mys}
\begin{tabular}{ll}}{\end{tabular}\vspace{0\baselineskip}}
\def\zz#1\\#2{%
\ifx\end#2\def\mys{}\else\def\mys{s}\fi#1\\#2}
\begin{document}
\begin{table}
\begin{Content}
test1 & test1 (want the caption for this one to be 'Content' instead)\\
\end{Content}

\begin{Content}
test2 & test2\\
test2 & test2\\
\end{Content}
\end{table}
\end{document}

Normally the \\ on the last row is optional and best omitted, but here you need it otherwise you'll get a runaway argument error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.