[Tex/LaTex] Horizontal and Dashed lines in caption

captionsrules

What I'm looking to do is caption a graph with something like

"It can be seen from x (solid line) and y (dashed line)"

Where "solid line" and "dashed line" are replaced by two solid and dashed lines centered vertically inline with the text of the caption.

Using

\protect\rule{1cm}{.4pt}

Gives a solid line, but it is not centered with respect to the height of the text.

Is this possible?

Best Answer

The rule command has a "raise" optional argument:

\rule[0.5ex]{1cm}{0.4pt}

You can define

\newcommand\solidrule[1][1cm]{\rule[0.5ex]{#1}{.4pt}}
\newcommand\dashedrule{\mbox{%
  \solidrule[2mm]\hspace{2mm}\solidrule[2mm]\hspace{2mm}\solidrule[2mm]}}

and then use

It can be seen from x (\solidrule) and y (\protect\dashedrule)