Graphics, Figures & TablesUnderlined table caption

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Harmont
Posts: 13
Joined: Tue Aug 31, 2010 3:52 pm

Underlined table caption

Post by Harmont »

Hi Folks,

Does anyone know how to make underlined table caption?

I know that you can do bold but not underlined caption with 'caption' package by:

Code: Select all

\usepackage[format=hang,font={small,bf}]{caption}
I don't know how to do that with help of 'ccaption' or 'caption2' packages either.

What I basically need is the whole caption (caption name, number, delimiter, title, etc..) positioned to the right side of the page and underlined. But only for table caption and not for listings, figures, etc.

Regards,
Nikita

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

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Underlined table caption

Post by meho_r »

A quick (and maybe not very polished) example, just to give you an idea:

Code: Select all

\documentclass{article}

\usepackage{caption}
\usepackage[normalem]{ulem}

\DeclareCaptionFormat{test}{#1#2#3\par}
\DeclareCaptionLabelFormat{test}{\small\uline{#1~#2}}
\DeclareCaptionTextFormat{test}{\small\uline{#1}}
\DeclareCaptionLabelSeparator{test}{\small\uline{:~}}
\DeclareCaptionFont{test}{\bfseries}

\captionsetup[table]{format=hang,labelformat=test,textformat=test,labelseparator=test,labelfont=test,justification=raggedleft,singlelinecheck=false}


\begin{document}

\begin{table}\centering
\caption{A table}
\begin{tabular}{|c|c|}
\hline 
1 & 2\tabularnewline
\hline 
3 & 4\tabularnewline
\hline
\end{tabular}
\end{table}

\begin{figure}\centering
\rule{1cm}{1ex}
\caption{A figure}
\end{figure}

\end{document}

Note: You may have to make manual line break in captions which go over two or more lines.

For details, of course, refer to the manual of caption package, section 4.
Harmont
Posts: 13
Joined: Tue Aug 31, 2010 3:52 pm

Re: Underlined table caption

Post by Harmont »

Thanks. It works! For some reason I had old 'caption' docs and didn't know about these directives.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underlined table caption

Post by localghost »

Now that the problem is solved, please be so kind and mark it accordingly as described in Section 3 of the Board Rules.


Best regards and welcome to the board
Thorsten
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Underlined table caption

Post by meho_r »

A notice: sommerfee came up with a solution for correctly breaking text in more-than-one-line captions. So, the code in the solution above:

Code: Select all

\DeclareCaptionTextFormat{test}{\small\uline{#1}}
should be corrected to this:

Code: Select all

\DeclareCaptionTextFormat{test}{\small\expandafter\uline\expandafter{\expandafter#1}}
Last edited by meho_r on Mon Sep 13, 2010 8:05 pm, edited 1 time in total.
Harmont
Posts: 13
Joined: Tue Aug 31, 2010 3:52 pm

Re: Underlined table caption

Post by Harmont »

meho_r, thank you for the follow-up.
Harmont
Posts: 13
Joined: Tue Aug 31, 2010 3:52 pm

Re: Underlined table caption

Post by Harmont »

localghost, I can't edit my first two messages. Dunno why.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Underlined table caption

Post by localghost »

Harmont wrote:localghost, I can't edit my first two messages. Dunno why.
Time has run out for edtiting. I will do so.
Post Reply