Text FormattingAlter Float Caption Label

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Alter Float Caption Label

Post by sw3quant »

I am using WinEdt 6 with MikTeX 2.9 on Windows 7. I have a LaTeX document with figures and tables in, as follows.

Code: Select all

\begin{figure}%[!ht]
  \centering
  \includegraphics[width=3in,height=4in,keepaspectratio]{filename}
  \caption{Figure caption}
  \label{fig:sample}
\end{figure}

\begin{table}%[!ht]
  \caption{Table caption}
  \label{tab:sample}
  \centering
  \begin{tabular}{|c|l|} \hline
    {\bf Variable} & {\bf Description} \\ \hline \hline
    2 & 1). \\ \hline
  \end{tabular}
\end{table}
After compiling LaTeX refers to these items as "Figure X" and "Table Y".

How can I force LaTeX to call all tables and figures "Exhibit", e.g. "Exhibit 1", "Exhibit 2", etc.


Thank you!
Last edited by sw3quant on Mon Mar 25, 2013 6:57 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alter Float Caption Label

Post by localghost »

You could create a new float type. There are several packages that support this.

Thorsten
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Re: Alter Float Caption Label

Post by sw3quant »

Thank you for your reply.

Could you give me an example of how you would apply one of your suggestions?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alter Float Caption Label

Post by localghost »

sw3quant wrote:[…] Could you give me an example of how you would apply one of your suggestions?
That's no sorcery. Examples can be found in the corresponding package manuals. Perhaps try newfloat from the caption bundle. Assumed that the bundle is installed in your TeX system, you have direct access to the manual on the command line.

Code: Select all

texdoc newfloat
So it should be quite straightforward to create an example on your own. If you run into trouble, ask targeted questions which we can answer.
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Alter Float Caption Label

Post by sw3quant »

I am still struggling with this. I can not get it to work:(. My MWE is here:

Code: Select all

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{array}[attachment=0]latex2.png[/attachment]
\usepackage{caption}
\usepackage{subcaption}
\usepackage{capt-of}
\usepackage{amsfonts}
\usepackage{amsmath,amssymb}
\usepackage{float}

\begin{document}
If I want to use the word Exhibit rather than Figure and Table then latex can't count properly. \\


In Exhibit \ref{myGraph} I show an image,
\begin{figure}[H]
    \begin{center}
        {\includegraphics[width=1in,keepaspectratio]{myGraph}} % any PNG image here will do...
        \caption{My graph is very nice, though I would like this to say ``Exhibit 1:'' and not ``Figure 1:'' }
        \label{myGraph}
    \end{center}
\end{figure}

In Exhibit \ref{myTable} I put some data,
\begin{table}[H]
\centering
\captionof{table}{\bf A latex table}
\begin{tabular}{|c|c|c|c|}
  \hline
  {\bf Statistic}  & {\bf Value}   & {\bf Statistic} & {\bf Value}\\
  \hline \hline
  Mean & 5 & Maximum & 1,069 \\
  Mode & 1 & $95^{\text{th}}$ Percentile & 21 \\
  \hline
\end{tabular}
\label{myTable}
\end{table}
My table is also very nice, though I would like this to say ``Exhibit 2:'' and not ``Table 1:'' 


\end{document} 
and below I insert an image of what this looks like when its run.
latex.png
latex.png (74.15 KiB) Viewed 9055 times
I now try and modify this, as suggested by localghost to use newfloat. The documentation does not seem to have any examples for the case I need to apply. In summary I can't get it to work. My attempted code is below. Can anyone advise?

Code: Select all

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{array}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{capt-of}
\usepackage{amsfonts}
\usepackage{amsmath,amssymb}
\usepackage{float}

%\usepackage{newfloat} %http://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/latex/contrib/caption/newfloat.pdf
%\floatstyle{ruled}
\newfloat{Exhibit}{}{}
\floatname{Exhibit}{Exhibit}
%\newcommand{\listofExhibits}{\listof{Exhibit}{Exhibit List}}


\begin{document}
Close, but I need the captions to be above the table, but here they are below. How do I change that????\\


In Exhibit \ref{myGraph} I show an image,
\begin{Exhibit}[H]
\begin{figure}[H]
    \begin{center}
        {\includegraphics[width=1in,keepaspectratio]{myGraph}} % any PNG image here will do...             
    \end{center}
\end{figure}
\caption{Better}\label{myGraph}
\end{Exhibit}

In Exhibit \ref{myTable} I put some data,
\begin{Exhibit}[H]
\caption{\bf A latex table} 
\label{myTable}
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|}
  \hline
  {\bf Statistic}  & {\bf Value}   & {\bf Statistic} & {\bf Value}\\
  \hline \hline
  Mean & 5 & Maximum & 1,069 \\
  Mode & 1 & $95^{\text{th}}$ Percentile & 21 \\
  \hline 
\end{tabular}
\end{table}
\end{Exhibit}
nearly there...!

\end{document} 
the output is here:
latex2.png
latex2.png (64.69 KiB) Viewed 9052 times
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Alter Float Caption Label

Post by sw3quant »

Subsequent to my last post, I have hit an even bigger problem.

I often wish to have a table/figure spread across two coloumns and so use

Code: Select all

\begin{Exhibit}
\begin{figure*}

\end{figure*}
\end{Exhibit}
However, this just doesn't work. The PDF compiles with no error message.

I also want to let latex specify the position of the figure/ table and so don't want to use [H]. However when I remove [H] the code will not compile. Have I missed something obvious?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alter Float Caption Label

Post by localghost »

sw3quant wrote:[…] I now try and modify this, as suggested by localghost to use newfloat. The documentation does not seem to have any examples for the case I need to apply. In summary I can't get it to work. […]
No offense. But in situations like this I always wonder what is so difficult in just reading a package manual and then applying the stuff to personal needs. The manuals must be written so bad that even people with academic background seem to be presented with insoluble problems. m(

The below code should solve all the issues. Since a starred environment exhibit* is defined automatically (but seemingly not documented), there should be no further issues in documents with multiple columns.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mwe}  % loads »graphicx«
\usepackage{caption}
\captionsetup{%
  font=small,
  labelfont=bf
}
\usepackage{subcaption}
\usepackage{newfloat}
\DeclareFloatingEnvironment[%
  fileext=loe,
  name=Exhibit
]{exhibit}

% see UK TeX FAQ: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wholerow
\usepackage{array}
\newcolumntype{_}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{%
  \gdef\currentrowstyle{#1}%
  #1\ignorespaces
}
\usepackage[super]{nth}  % Gen­er­ate English or­di­nal num­bers
\usepackage{booktabs}  % nice looking tables

\begin{document}
  \listofexhibits
  \newpage

  If I want to use the word ``Exhibit'' rather than ``Figure'' and ``Table'' then \LaTeX\ can't count properly.

  \medskip
  In \exhibitname~\ref{exh:sample-figure} I show an image.

  \begin{exhibit}[!ht]
    \centering
    \includegraphics{example-image-a}
    \caption{My graph is very nice, though I would like this to say ``Exhibit 1:'' and not ``Figure 1:'' }
    \label{exh:sample-figure}
  \end{exhibit}

  In \exhibitname~\ref{exh:sample-table} I put some data,

  \begin{exhibit}[!ht]
    \caption{A Table}
    \label{exh:sample-table}
    \centering
    \begin{tabular}{_c^c^c^c} \toprule
      \rowstyle{\bfseries}  % make (only) the whole following row bold faced
      Statistic  & Value & Statistic & Value \\ \midrule
      Mean & 5 & Maximum & 1,069 \\
      Mode & 1 & \nth{95} Percentile & 21 \\ \bottomrule
    \end{tabular}
  \end{exhibit}

  My table is also very nice, though I would like this to say ``Exhibit 2:'' and not ``Table 1:''
\end{document}
The environments {figure} and {table} still exist. Please note the mwe package which is only used here and not in the actual document. Furthermore it is recommendable to take a look at all other involved packages.

You can instantly test the code by clicking "Open in writeLaTeX" in the head of the above code box.
Post Reply