Featured Book

LaTeX Beginners Guide

Who is online

In total there are 19 users online :: 2 registered, 0 hidden and 17 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 17 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

Alter Table Caption Prefix

captionstablesAdd tags Information and discussion about graphics, figures & tables in LaTeX documents.

Alter Table Caption Prefix

Postby luis on Sat Jan 26th, 2013

Hello everyone,

I'd like to change the caption prefix of a table, e.g. like this.
Code: Select all  •  Open in writeLaTeX
\begin{table}
\caption{A caption}
\end{table
}

This results in something like this.
Table I: A caption

And I'd like to change it to this.
Listing I: A caption

I tried using the \tablename command, but it has no effect:
Code: Select all  •  Open in writeLaTeX
\begin{table}
\def\tablename{Listing I}
\caption{A caption}
\end{table
}

I also have tried it with \renewcommand*, but it doesn't have any effect.
Code: Select all  •  Open in writeLaTeX
\renewcommand*{\tablename}{Listing}
\begin{table}
\caption{A caption}
\end{table
}


How could this be made? Thank you,

Luís
luis
 
Posts: 14
Joined: Wed Dec 30th, 2009

Re: Alter Table Caption Prefix

Postby localghost on Sat Jan 26th, 2013

There are some smarter alternatives (in order of priority).

  • Use a package like listings or minted to typeset listings. These packages provide a float environment with the corresponding prefix.
  • Use a package like floatrow or newfloat (from the caption bundle) to create a new float environment with the corresponding prefix.


Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: Alter Table Caption Prefix

Postby luis on Sat Jan 26th, 2013

Hi Thorsten,

Neither listings (which I already tried) nor minted seem to apply in this case. I tried newfloat, but unfortunately the document doesn't compile if add the package command. As for floatrow its manual has over 100 pages and so far I haven't found an example where the float element prefix is changed.

Thanks for answering in any case.

Luís
luis
 
Posts: 14
Joined: Wed Dec 30th, 2009

Re: Alter Table Caption Prefix

Postby sommerfee on Sat Jan 26th, 2013

luis wrote:I tried newfloat, but unfortunatelly the document doesn't compile if add the package command.


What do you mean by "doesn't compile"? Do you get an error message? If yes, which one? (What document class do you use?)
User avatar
sommerfee
 
Posts: 493
Joined: Mon Apr 9th, 2007

Re: Alter Table Caption Prefix

Postby localghost on Sun Jan 27th, 2013

luis wrote:[…] Neither listings (which I already tried) nor minted seem to apply in this case. […]

Why? Give a minimal example where these packages fail.
luis wrote:[…] I tried newfloat, but unfortunately the document doesn't compile if add the package command. […]

Same questions as sommerfee already asked.
luis wrote:[…] As for floatrow its manual has over 100 pages and so far I haven't found an example where the float element prefix is changed. […]

So you should read Section 4 of its manual (which can be found in the ToC).
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: Alter Table Caption Prefix

Postby luis on Wed Jan 30th, 2013

Hi localghot and sommerfee, thank you for replying. My comments go below.

localghost wrote:Why? Give a minimal example where these packages fail.


I don't know where they fail, but I couldn't find examples where these packages are used to substitute a table caption prefix.

sommerfee wrote:What do you mean by "doesn't compile"? Do you get an error message? If yes, which one? (What document class do you use?)


I get this error:

LaTeXError: File `newfloat.sty' not found.


localghost wrote:So you should read Section 4 of its manual (which can be found in the ToC).


Section 4 of the manual I have focus on new float types, not on captions. With this particular package I tried this set up:

Code: Select all  •  Open in writeLaTeX
\captionsetup[table]{name=Listing}


But it has not effect on the caption prefix.

Any other hints are welcome. Thank you,

Luís
luis
 
Posts: 14
Joined: Wed Dec 30th, 2009

Re: Alter Table Caption Prefix

Postby sommerfee on Thu Jan 31st, 2013

luis wrote:I get this error:

LaTeXError: File `newfloat.sty' not found.


Then you simply do not have the newfloat package installed. Updating your TeX system (or at least the caption package bundle) should help.

As an alternative you could give the floatrow or the float package a try.

I tried this set up:

Code: Select all  •  Open in writeLaTeX
\captionsetup[table]{name=Listing}


But it has not effect on the caption prefix.


Please give us a minimal example.
User avatar
sommerfee
 
Posts: 493
Joined: Mon Apr 9th, 2007

Re: Alter Table Caption Prefix

Postby localghost on Thu Jan 31st, 2013

luis wrote:[…] I don't know where they fail, but I couldn't find examples where these packages are used to substitute a table caption prefix. […]

Of course they don't alter table captions. They offer new environments that are labeled as listings. At the moment I can't comprehend why you insist on altering the table caption prefix. Obviously you need something that you can label as listing. So it would be much smarter to create a new floating object or use a package that allows you to typeset listings. The corresponding tools have been mentioned. Perhaps you can elaborate what you want to put into the {table} environment and then label as a listing. Then it would be much easier to suggest a possible solution.
luis wrote:[…] Section 4 of the manual I have focus on new float types, not on captions. […]

The package allows to create a new float that you can label according to your needs. And Section 4 describes how to get one that is labeled e.g. as listing.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: Alter Table Caption Prefix

Postby luis on Sat Feb 2nd, 2013

Hello everyone, thank you for the replies.

First on this comment:

localghost wrote:At the moment I can't comprehend why you insist on altering the table caption prefix. Obviously you need something that you can label as listing. So it would be much smarter to create a new floating object or use a package that allows you to typeset listings.


And I don't understand why you insist on me doing something different from what I initially presented. Again, the use case is very simple: I have a {tabular} environment inside a {table} and I need to change its caption prefix from "Table" to "Listing". I do not want to change the contents of the floating environment, I just want to change the caption.

Regarding the newfloat package I have no idea why is it missing, I regularly run the updates on this system.

On defining a new floating environment, while I am able to change the prefix with floatrow, the caption is wrongly placed and seems to miss some of the presets of the {table} environment. Again, I'd say this way is not what I need, here's a minimum example:

Code: Select all  •  Open in writeLaTeX
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}

\usepackage{floatrow}

\DeclareNewFloatType{mylist
}%
        {name=Listing}

\begin{document}

\begin{mylist}
\caption{The caption}
   \begin{center}
        \begin{tabular}{| r | r |}
        \hline
        This is & a table. \\
        \hline
    \end{tabular}
   \end{center}
\end{mylist}

\end{document
}


Reading the floatrow manual the only example that seems to exactly fit the use case I'm presenting is using \captionsetup. Unfortunately this produces no effect, here's the example:

Code: Select all  •  Open in writeLaTeX
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}

\usepackage{floatrow}

\begin{document}

\captionsetup[table]{name=Listing}

\begin{table}
\caption{The caption}
   \begin{center}
        \begin{tabular}{| r | r |}
        \hline
        This is & a table. \\
        \hline
    \end{tabular}
   \end{center}
\end{table}

\end{document
}


If someone can tell me why \captionsetup isn't working that would be great. Otherwise, using a new floating environment, if it is possible, things must be a bit more refined than what is shown in the manual.

Thanks once more,
Luís
luis
 
Posts: 14
Joined: Wed Dec 30th, 2009

Re: Alter Table Caption Prefix

Postby sommerfee on Sat Feb 2nd, 2013

luis wrote:And I don't understand why you insist on me doing something different from what I initially presented.


Because what localghost suggests is the "natural" way. The floating environments {figure}, {table}, ..., have distinct names, counters, and lists, so if someone needs "listing"s, the choice of creating a new (floating) environment is self-evident while the choice of abusing an existing one is not.

Again, the use case is very simple: I have a {tabular} environment inside a {table} and I need to change its caption prefix from "Table" to "Listing". I do not want to change the contents of the floating environment, I just want to change the caption.


Code: Select all  •  Open in writeLaTeX
\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{table}
\captionsetup{name=Listing}
\centering
\begin{tabular}{cc}
A & B\\
C & D\\
\end{tabular}
\caption{A listing}
\end{table}
\end{document
}


This approach may have some unwanted side-effects, but this is what you want, so this is what you get.

Regarding the newfloat package I have no idea why is it missing, I regularly run the updates on this system.


The newfloat package was introduced November 2011, so no, your TeX system is not up-to-date.

On defining a new floating environment, while I am able to change the prefix with floatrow, the caption is wrongly placed


What caption placement do you want? Using the floatrow package you can adjust the placement by options of \DeclareNewFloatType.

and seems to miss some of the presets of the {table} environment.


What presets are you missing?
User avatar
sommerfee
 
Posts: 493
Joined: Mon Apr 9th, 2007


Topic Tags

captionstables

Return to Graphics, Figures & Tables

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 17 guests