[Tex/LaTex] Problem with command \captionsetup from package caption

captionsmemoirnaming

The following MWE:

\documentclass[11pt]{memoir}

\usepackage{caption}

\captionsetup[table]{
         listformat=empty,
         tablename=Table,
         justification=justified,
         labelsep=quad,
         position=above,
         skip=\onelineskip,
         width=\linewidth,
         labelfont={small},
         font={small}
         }

\begin{document}

    \begin{table}
        \caption{A table.}
    \end{table}

\end{document}

generates the error message ! Package caption Error: Can be used only in preamble. If I comment the \captionsetup command, there is no such error message. I know the class memoir provides its own tools for captions, but I'd rather use the package caption for them. Anyone could possibly shed some light on this issue?

EDIT: As soon as I comment the key tablename, the problem disappears. But even though it works, I wouldn't call it precisely a satisfactory solution.

Best Answer

Edit: Thanks to Gonzalo Medina, I think I have an explanation. :)

tablename and figurename are indeed valid entries for \captionsetup, as long as you are using it without the optional argument. The idea: \captionsetup without the optional argument works globally, so it makes sense to set both figure and table names via figurename and tablename respectivelly.

The following code works:

\captionsetup{
   tablename=Table,
   listformat=empty,
   justification=justified,
   labelsep=quad,
   position=above,
   skip=\onelineskip,
   width=\linewidth,
   labelfont={small},
   font={small}
}

We are setting the caption layout globally.

Now, when we provide the optional argument, we are limiting our scope to the float we are setting up. Say, if we use \captionsetup[table]{...}, we are configuring the captions within the table scope, so there's no point of using tablename, but only name.

We can use the name key instead of tablename, since we are configuring table:

\documentclass[11pt]{memoir}

\usepackage{caption}

\captionsetup[table]{
   name=Table,
   listformat=empty,
   justification=justified,
   labelsep=quad,
   position=above,
   skip=\onelineskip,
   width=\linewidth,
   labelfont={small},
   font={small}
}

\begin{document}

\begin{table}
\caption{A table.}
\end{table}

\end{document}

If we want to use tablename instead, we must use \captionsetup without the optional argument:

\documentclass[11pt]{memoir}

\usepackage{caption}

\captionsetup{
   tablename=Table,
   listformat=empty,
   justification=justified,
   labelsep=quad,
   position=above,
   skip=\onelineskip,
   width=\linewidth,
   labelfont={small},
   font={small}
}

\begin{document}

\begin{table}
\caption{A table.}
\end{table}

\end{document}

Just for reference, another way to rename the table name is with \renewcommand{\tablename}{Table}. However, as AstroPig mentioned in the comments, it doesn't work if we use babel with the french language.