Graphics, Figures & Tables ⇒ Underlining the Figure in the Figure
Underlining the Figure in the Figure
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
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
Underlining the Figure in the Figure
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}
Underlining the Figure in the Figure
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: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).
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}
Underlining the Figure in the Figure
Re: Underlining the Figure in the Figure

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Underlining the Figure in the Figure
Best regards
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Underlining the Figure in the Figure
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?
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Underlining the Figure in the Figure
This sounds very much like a solved problem. Otherwise you shouldn't use such expressions.samness25 wrote:Thank you all so much! Worked perfectly :)
You got the code from sommerfee. Just drop the optional argument for the \captionsetup command and it should work.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?
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.
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10