5

I am entering the following code in more than 180 times after each \subsubsection.

Is there any way to automate \caption{subsubsection title}?

I tried with \caption{\subsubsectiontitlename} but it does not work.

%%%%%%%%

\begin{figure}[H]
\caption{títol \subsubsection}
\subfloat[Mostres absolutes]{
\includegraphics[width=0.50\linewidth]{Columna_34_absol.jpg}}
\subfloat[Mostres ponderades]{
\includegraphics[width=0.50\linewidth]{Columna_34_pond.jpg}}
\\
\subfloat[]{
\includegraphics[scale=0.1]{Formatge_34_preg.jpg}}
\subfloat[]{\includegraphics[width=0.33\linewidth]{Formatge_34_absol.jpg}}
\hfil
\subfloat[]{\includegraphics[width=0.33\linewidth]{Formatge_34_pond.jpg}}\hfil
}
\end{figure}

%%%%%%%%%%%%%%%%

2 Answers 2

4

Use a personal environment:

\newenvironment{subsectionfigure}[1]
  {\subsection{#1}\begin{figure}[H]\caption{#1}}
  {\end{figure}}

and then

\begin{subsectionfigure}{Title of this subsection}
\subfloat[Mostres absolutes]{
\includegraphics[width=0.50\linewidth]{Columna_34_absol.jpg}}
\subfloat[Mostres ponderades]{
\includegraphics[width=0.50\linewidth]{Columna_34_pond.jpg}}
\\
\subfloat[]{
\includegraphics[scale=0.1]{Formatge_34_preg.jpg}}
\subfloat[]{\includegraphics[width=0.33\linewidth]{Formatge_34_absol.jpg}}
\hfil
\subfloat[]{\includegraphics[width=0.33\linewidth]{Formatge_34_pond.jpg}}\hfil
}
\end{subsectionfigure}

In the argument of the newly defined argument you put the subsection title, which will be repeated in the caption (although it seems a useless repetition).

2
  • @egreg I'm having trouble seeing how this automates the process of repeatedly typing the title of the subsubsection. Won't he still have to type the title of the subsubsection for every single figure?
    – JohnReed
    Commented Apr 27, 2012 at 4:35
  • @JohnReed I assumed that each subsection has its own title.
    – egreg
    Commented Apr 27, 2012 at 8:08
2

Here a solution that works by modifying the subsubsection command. Note: this only works properly if the figure is inside of a subsubsection.

Add these lines to your preamble:

\let\oldsubsubsection\subsubsection
\newcommand\ssv{}
\newcommand\tempcommand[1]{%
\renewcommand\ssv{#1}%
\oldsubsubsection{#1}}
\renewcommand\subsubsection\tempcommand

Then, for your captions in your figures you can use \caption{\ssv}. This should output the name of the current subsubsection title in the caption.

1
  • Thanks John Reed,thanks a lot for your help! This code works perfectly. Commented Apr 26, 2012 at 21:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .