Graphics, Figures & TablesLegend inside caption

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jhapk
Posts: 81
Joined: Tue Apr 20, 2010 9:33 pm

Legend inside caption

Post by jhapk »

Hi,

I have a figure like this
figure.png
figure.png (51.1 KiB) Viewed 9417 times
Instead of having the legend in the figure, I want to have it in the caption, like

Code: Select all

[draw red line] FPI- Method 1, [draw green line] FPI- Method 2
Is it possible?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

achim
Posts: 49
Joined: Wed Aug 05, 2009 2:29 pm

Legend inside caption

Post by achim »

The easiest way would probably be just to use a dash (or two for a dashed line).

Code: Select all

\caption{blablabla. {\red -}: $\mu=1$, {\green -}: $\mu=2$, {\blue -}: $\mu=3$, {\red --}: $\mu=4$, {\green --}: $\mu=5$ \dots
Or: Use pspicture (or some other package) to actually draw a line.
Or2: save the line separately and use it in line with \includefigure[height=1em]{Images/line}

I too wish there was an easier way to do this...
OS: Kubuntu
Distribution: TexLive
Editor: Kile
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Legend inside caption

Post by localghost »

I think that shifting the legend to the caption is not so good. There are other possibilities for tweaks which might look better.

You could decrease the font size of the legend to reduce its size so it doesn't cover so much of the plot area. Moreover you can place the legend somewhere else inside as well as outside the plot area. Both methods are described in the pgfplots manual.

Finally a tip that is not problem related. Perhaps you should think about placing the y-axis label a bit further to the left. It interferes with tick labels. The manual shows you how to do that.


Thorsten
jhapk
Posts: 81
Joined: Tue Apr 20, 2010 9:33 pm

Re: Legend inside caption

Post by jhapk »

Thanks localghost. Your suggestion made sense. I used the "legend pos" command explained in pgfplots and I could position my legend easily.
zaparoli
Posts: 1
Joined: Wed Apr 06, 2022 9:36 am

Legend inside caption

Post by zaparoli »

You can use tikz package with protect, as suggested in
https://tex.stackexchange.com/questions/115352/tikzpicture-within-figure-caption

Code: Select all

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{figure}[h]
-- This is a figure --
\caption{Figure within caption {\protect\tikz \protect\draw[thick, color=blue, fill=blue] plot[mark=*, mark options={scale=1.3}] (0,0);} }
\end{figure}

\end{document}
Post Reply