4

I'm using this template to write my report. I'm trying to add a listoffigures so I added those lines in the .cls file:

\newlength{\lofsep} 
\setlength\lofsep{2pc}

\contentsmargin{0cm}
\titlecontents{figure}[\lofsep]
  {\addvspace{4pt}\color{color1}\bfseries\sffamily}
  {\contentslabel[\thecontentslabel]{\lofsep}}
  {}
  {\ \titlerule*[.5pc]{.}\ \thecontentspage}
  []

… and it works fine !

The thing is that I want my caption to be in two parts :

  • The actual caption
  • The author credit

It would be nice if I could get something like that :

1 My caption - John Smith ........................... 5

OR

1 My caption ................................................. 5

John Smith

because for now it's just :

1 My caption - John Smith ............................. 5

and it's not really readable.

So I thought I could split the \contentslabel in \tiltecontents but it appears that \contentslabel is not given in \tiltecontents.

Hope it's clear enough, thanks a lot !

Fritzip
  • 249
  • 1
  • 5
  • Welcome to the site! Could you provide some information on how you would mark it up in the code; for example, do you want to use \caption[\author{<author name>}-\mycapt{Caption}]{Actual caption}... – cmhughes Jul 30 '14 at 18:36
  • Yes ! That solution would be really nice ! I thought about it but I really don't know where to start. I'm just beginning with those "advanced LaTeX technics" ! – Fritzip Jul 31 '14 at 07:47
  • Does anyone has some starting points/websites to look at ? Thanks – Fritzip Aug 11 '14 at 10:25

1 Answers1

4

Here's a solution that defines the command \mycaption that has the following syntax

\mycaption[author=<name>,toc=<caption for toc>]{<caption>}

The default value for <author> is Friedrich, and the default value for the <toc> key is <caption>. For a very thorough tutorial on the keyval package see the documentation and How to create a command with key values?, for example.

screenshot

You might prefer to renew the caption command, but you'd have to be careful if you were going to load either the caption or hyperref packages, which is why I left it alone.

% arara: pdflatex
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{keyval}% http://ctan.org/pkg/keyval

\makeatletter
% ========= KEY DEFINITIONS =========
\define@key{mycaption}{toc}{\def\friedrich@toc{#1}}
\define@key{mycaption}{author}{\def\friedrich@author{#1}}
% ========= KEY DEFAULTS =========
\setkeys{mycaption}{toc={},author=Friedrich}%
% ========= MYCAPTION COMMAND  =========
\newcommand{\mycaption}[2][]{%
    \ifx\\#1\\% check if #1 is empty
        \caption{#2} % just a regular caption
    \else
        \setkeys{mycaption}{#1}% Set new keys
        \ifx\friedrich@toc\empty
            \def\friedrich@toc{#2}
        \fi
        \caption[{\bfseries\friedrich@toc}-{\itshape\friedrich@author}]{#2}%
    \fi
}
\makeatother

\begin{document}

\listoffigures
\begin{figure}[!htp]
    \mycaption[toc=caption for toc,author=Fried]{actual caption}
\end{figure}

\begin{figure}[!htp]
    \mycaption[toc=caption for toc (note the default author)]{actual caption}
\end{figure}

\begin{figure}[!htp]
    \mycaption[author=cmh]{actual caption (used in toc and caption)}
\end{figure}

\begin{figure}[!htp]
    \mycaption{actual caption (no keys specified)}
\end{figure}

\begin{figure}[!htp]
  \mycaption[toc={group the caption to use $=$}]{actual caption (used in toc and caption)}
\end{figure}

\end{document}
cmhughes
  • 100,947