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

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
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¹
Post Reply