Graphics, Figures & Tables\rule inside caption text

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
melanie
Posts: 7
Joined: Fri Feb 16, 2007 11:43 am

\rule inside caption text

Post by melanie »

Hello,

I would like to draw horizontal rules in the caption text of graph figures, with different colors and thicknesses. The command

Code: Select all

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

does not work inside the caption. I have another solution:

Code: Select all

{\color{red}--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\,}
but this is neither elegant nor beautiful... Here is a simple working example:

Code: Select all

\documentclass[a4paper,12pt,oneside]{article}
\usepackage{caption}
\usepackage[final]{pdfpages}
\usepackage{graphicx}	%,amssymb,amsmath,mathrsfs}
\usepackage{amsmath}
     
\begin{document}
\begin{figure}[ht]
	blablabla
	\label{fig:this_figure}
	\caption{Red line: {\color{red}--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\,}, and black blue line: --\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\,.}
\end{figure}

\verb|{\color{red}--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\,}|\\

is not a very elegant way to draw a rule {\color{red}--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\!\!--\,}, but this is impossible to put a rule $\rule[0.5ex]{1cm}{2pt}$ like this inside the caption text.:\\

\verb|\rule[0.5ex]{0.75cm}{0.5pt}|
\end{document}
Does someone have an idea ?
Thanks !
mélanie

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

\rule inside caption text

Post by localghost »

If you could explain the purpose of these rules getting a picture would be much easier. So I simply guess that you want to add a kind of explaining key to your graphs. Perhaps the overpic package is a better solution in this case. It lets you place text or other elements as a kind of overlay on your graphs. Alternatively you can use the pgf/tikZ package to draw such lines also in a caption.


Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Post Reply