You could use \captionsetup[<name>]{...} ... \captionsetup{options=<name>}
to define and execute options for custom commands or environments, e.g.:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\addtolength{\evensidemargin}{1.5cm}
\addtolength{\textwidth}{-1.5cm}
\addtolength{\marginparwidth}{20pt}
\addtolength{\marginparsep}{10pt}
\captionsetup[marginfigure]{
justification=raggedright,
font=small}
\newcommand\marginfigure[1]{%
\marginpar{%
\captionsetup{type=figure,options=marginfigure}%
#1}}
\begin{document}
text text text ...
\begin{figure}
\centering
\includegraphics{figure1}
\caption{figure 1 text, which I don't want to have a raggedright justification, since it looks quite good without it due to the many words that I can fit into one line in this type of caption.}
\end{figure}
some
more
text
about
something
\marginfigure{\includegraphics[width=\marginparwidth]{figure2}
\caption{Here for figure 2, the caption will look odd when few words are stretched across the marginparwidth}}
\end{document}
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.
Best Answer
margincap
is not a floating environment:With
you can avoid setting the modification in the
figure
environment.Following Axel Sommerfeldt's suggestion, one can better define a new option: