Graphics, Figures & TablesUnderlining the Figure in the Figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
samness25
Posts: 8
Joined: Sat Apr 03, 2010 10:29 pm

Underlining the Figure in the Figure

Post by samness25 »

Hi all

I was wondering if anyone knew how to underline the figure in the figure, like

Picture is here
Figure 3.1: Picture

I've played around with latex and I can get the caption to underline but not the Figure 3.1 and then I found I can also get the number to underline but not the Figure. So basically it looks like

Figure 3.1: Picture

Anyone have any ideas? It's be much appreciated!
Thanks
Last edited by samness25 on Mon Sep 13, 2010 5:59 pm, edited 2 times in total.

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Underlining the Figure in the Figure

Post by gmedina »

Hi,

perhaps not the most elegant solution:

Code: Select all

\documentclass{article} 
\usepackage{ulem}
\usepackage{caption}

\DeclareCaptionLabelFormat{underlcap}{\uline{#1 #2}}
\captionsetup[figure]{labelformat=underlcap}

\begin{document}

\begin{figure}[!ht]
  \centering
  \rule{3cm}{4cm}% to simulate an actual figure
  \caption[test figure]{\hspace*{-7pt}\uline{\hspace*{7pt}test figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure}}
  \label{fig:test}
\end{figure}

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Underlining the Figure in the Figure

Post by sommerfee »

meho_r wrote:if I may, I'd also add to the example a custom separator definition and remove manual \hspace commands from caption:

\DeclareCaptionLabelSeparator{underlcap}{\uline{:~}}

This way there's no small gap at the separator (colon).
When using caption package v3.1 one can add a (tricky) \DeclareCaptionTextFormat, too, so there is no need anymore to use \uline within the caption:

Code: Select all

\documentclass{article} 
\usepackage{ulem}
\usepackage{caption}[2007/09/01] % needs v3.1 or newer

\DeclareCaptionLabelFormat{underlcap}{\uline{#1 #2}}
\DeclareCaptionLabelSeparator{underlcap}{\uline{:~}}
\DeclareCaptionTextFormat{underlcap}{\expandafter\uline\expandafter{\expandafter#1}}

\captionsetup[figure]{%
  labelformat=underlcap,labelseparator=underlcap,textformat=underlcap}

\begin{document}

\begin{figure}[!ht]
  \centering
  \rule{3cm}{4cm}% to simulate an actual figure
  \caption{test figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure figure}
  \label{fig:test}
\end{figure}

\end{document}
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Underlining the Figure in the Figure

Post by meho_r »

Sorry for accidental deletion of my post. However, this solution is great and contains my suggestion, so no harm done. I'll link it to another thread about underlining since it solves the problem with more-than-one-line captions. Thanks for the solution.
samness25
Posts: 8
Joined: Sat Apr 03, 2010 10:29 pm

Re: Underlining the Figure in the Figure

Post by samness25 »

Thank you all so much! Worked perfectly :)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underlining the Figure in the Figure

Post by localghost »

Now that the problem is obviously solved, please be so kind and mark the topic accordingly as clearly written in Section 3 of the Board Rules (to be read before posting).


Best regards
Thorsten
samness25
Posts: 8
Joined: Sat Apr 03, 2010 10:29 pm

Re: Underlining the Figure in the Figure

Post by samness25 »

Wow, sorry. But it's not quite solved.

I suppose it would have been easier to have included tables in my question. The code works for figures and my partner and I have tried to rework it for tables but it has been unsuccessful, is there a different code for tables?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underlining the Figure in the Figure

Post by localghost »

samness25 wrote:Thank you all so much! Worked perfectly :)
This sounds very much like a solved problem. Otherwise you shouldn't use such expressions.
samness25 wrote:[…] I suppose it would have been easier to have included tables in my question. The code works for figures and my partner and I have tried to rework it for tables but it has been unsuccessful, is there a different code for tables?
You got the code from sommerfee. Just drop the optional argument for the \captionsetup command and it should work.

Finally just a general remark. If code is not working, a simple phrase like »was not successful« is not very helpful. Provide a minimal example and explain exactly what is not working and echo corresponding error messages.
Post Reply