[Tex/LaTex] Legend in caption (dotted, chain, dashed lines, …) in pdflatex

captionslegendpstricks

My goal is to include a legend in a caption in Latex. This legend would include symbols of a full line, dotted line, chain line, …
However, I would like to do this, without "messing" with the fonts of the IEEEtran document class.

My first idea was to use the pstricks package:

\documentclass[journal]{IEEEtran}
\usepackage{pstricks}
\newbox{\full}
\savebox{\full}{(
\begin{pspicture}(0,0)(0.6,0)
\psline[linewidth=0.04,linecolor=black](0,0.1)(0.6,0.1)
\end{pspicture})}

\newbox{\dotted}
\savebox{\dotted}{
    (\begin{pspicture}(0,0)(0.6,0)
    \psline\[linestyle=dashed,dash=1pt 2pt,linewidth=0.04,linecolor=black\](0,0.1)(0.6,0.1)
    \end{pspicture})}
\newbox{\dashed}
\savebox{\dashed}{
    (\begin{pspicture}(0,0)(0.6,0)
    \psline\[linewidth=0.04,linecolor=black\](0,0.1)(0.15,0.1)
    \psline\[linewidth=0.04,linecolor=black\](0.2,0.1)(0.4,0.1)
    \psline\[linewidth=0.04,linecolor=black\](0.45,0.1)(0.6,0.1)
    \end{pspicture})}

\newbox{\chain}
\savebox{\chain}{
    (\begin{pspicture}(0,0)(0.6,0)
    \psline\[linewidth=0.04,linecolor=black\](0,0.1)(0.15,0.1)
    \psline\[linewidth=0.04,linestyle=dashed,dash=1pt 2pt,linecolor=black\](0.2,0.1)(0.4,0.1)
    \psline\[linewidth=0.04,linecolor=black\](0.45,0.1)(0.6,0.1)
    \end{pspicture})}
\begin{document}
\title{Title}
\author{Authors}
\maketitle
\begin{abstract}
LOREM IPSUM.
\end{abstract}
\begin{IEEEkeywords}
Keywords.
\end{IEEEkeywords}

\section{Introduction}
TEST: Dashed: \usebox{\dashed}, Chain: \usebox{\chain}, full: \usebox{\full}, dotted: \usebox{\dotted}.
\end{document}

This yields this result if compiled with xelatex:

enter image description here

However, the fonts of the IEEEtran document class are altered. Ideally, I would like to create these legend symbols or similar, without altering the fonts of the document class (probably only possible with the pdflatex compiler?) and I'm looking for a way to do this.

Best Answer

One possibility is to use tikz; compile with pdflatex, xelatex or lualatex.

enter image description here

\documentclass[journal]{IEEEtran}
\usepackage{tikz}
\DeclareRobustCommand\full  {\tikz[baseline=-0.6ex]\draw[thick] (0,0)--(0.5,0);}
\DeclareRobustCommand\dotted{\tikz[baseline=-0.6ex]\draw[thick,dotted] (0,0)--(0.54,0);}
\DeclareRobustCommand\dashed{\tikz[baseline=-0.6ex]\draw[thick,dashed] (0,0)--(0.54,0);}
\DeclareRobustCommand\chain {\tikz[baseline=-0.6ex]\draw[thick,dash dot dot] (0,0)--(0.5,0);}
\begin{document}
\title{Title}
\author{Authors}
\maketitle
\begin{abstract}
LOREM IPSUM.
\end{abstract}
\begin{IEEEkeywords}
Keywords.
\end{IEEEkeywords}

\listoffigures

\section{Introduction}
TEST: Dashed (\dashed), chain (\chain), full (\full), dotted (\dotted).
\begin{figure}
\includegraphics[width=4cm]{example-image}
\caption{\full, \dashed, \chain, and \dotted}
\end{figure}
\end{document}