5

In Brazil, we consider tables to be "charts" that follow specific formatting (the translation might be a little off here, but that's what I'll use for this question). This specific formatting includes column alignment and borders, for example.

Both tables and charts are easily created in the tabular environment. My problem comes when I try to caption them separetely. The captions for the charts should say something like Chart 1: Example, while the captions for the tables should be the default Table 1: Example

My idea was to "duplicate" the table environment into something like the "mychart" environment, and then change this environment's captions. Is it the best way to achieve that or is there a better way to do it?

Note: I have tried using the captions package \captionsetup{name=Chart} command, it kinda worked, but the the tables and charts still shared the counters, so I had "chart 1 / table 2" instead of "chart 1 / table 1"...

Here I have a MWE of a table and a chart:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
    This is a Table:

\begin{table}[h]
    \centering
    \caption{Example}

    \begin{tabular}{l r}
        \hline
        City        &   Habitants   \\
        \hline
        City A      &   2000000 \\
        City B      &   4000000 \\
        City C      &   500000  \\
        \hline
    \end{tabular}
\end{table}

And this is a "chart": %might want to change the word

    \begin{table}[h]
        \centering
        \caption{Example}

        \begin{tabular}{|c c|}
            \hline
            City        &   Habitants   \\
            \hline
            City A      &   2000000 \\
            \hline
            City B      &   4000000 \\
            \hline
            City C      &   500000  \\
            \hline
        \end{tabular}
    \end{table}
\end{document}
4

It would be advisable to create a separate float that contains your charts. That allows you to have a handle into changing things in the future. For example, if you decide to reformat them differently, or perhaps make them the same.

The float package can easily create new floats:

enter image description here

\documentclass{article}

\usepackage{float}

\newfloat{chart}{htbp}{loc}
\floatname{chart}{Chart}
\newcommand{\listofcharts}{\listof{chart}{List of Charts}}

\begin{document}

\listoftables
\listofcharts

\section{A section}

This is a \verb|table|:

\begin{table}[h]
  \centering\caption{Example}
\end{table}

And this is a \verb|chart|:

\begin{chart}[h]
  \centering\caption{Example}
\end{chart}

\end{document}

A comparable setup using newfloat (compatible with caption) would be

\usepackage{newfloat}

\DeclareFloatingEnvironment[
  fileext   = loc,
  listname  = List of Charts,
  name      = Chart,
  placement = htbp,
]{chart}
4

You can use the newfloat package that cooperates out of the box with babel and caption.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}

\usepackage{caption,newfloat}

\DeclareFloatingEnvironment[
  fileext=loc,
  listname=Chart, % English name
  name=List of Charts, % English name
  placement=tbp,
]{chart}

\addto\captionsbrazil{% provide translations for Portuguese
  \renewcommand{\chartname}{Gr\'afico}%
  \renewcommand{\listchartname}{Lista de Gr\'aficos}%
}

\begin{document}

\listoftables
\listofcharts

\section{A section}

\begin{table}[h]
    \centering
    \caption{Example}

    \begin{tabular}{l r}
        \hline
        City        &   Habitants   \\
        \hline
        City A      &   2000000 \\
        City B      &   4000000 \\
        City C      &   500000  \\
        \hline
    \end{tabular}
\end{table}

And this is a "chart": %might want to change the word

    \begin{chart}[h]
        \centering
        \caption{Example}

        \begin{tabular}{|c c|}
            \hline
            City        &   Habitants   \\
            \hline
            City A      &   2000000 \\
            \hline
            City B      &   4000000 \\
            \hline
            City C      &   500000  \\
            \hline
        \end{tabular}
    \end{chart}

\end{document}

enter image description here

  • Interesting solution, but are the translations in this line: \addto\captionsbrazil{% provide translations for Portuguese automatic? Because the word "chart" can actually translate into several things in Portuguese. The word "Gráfico" in this case would work best if it were replaced by the word "Quadro". Does your solution allow one to customize such things to avoid these subtle issues? – Guilherme Vargas Sep 14 '16 at 22:58
  • 3
    @GuilhermeVargas I just guessed; type in the appropriate word. – egreg Sep 14 '16 at 22:59

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.