Graphics, Figures & TablesCaption aligned to left Side of Figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jlatex
Posts: 4
Joined: Wed Aug 03, 2011 9:22 pm

Caption aligned to left Side of Figure

Post by jlatex »

I would like to make my caption aligned below the left side of the figure such as:

Code: Select all

      |_______________________________|
      Figure 1: This is my caption
instead of

Code: Select all

|_______________________________|
Figure 1: This is my caption
or

Code: Select all

          |_______________________________|
Figure 1: This is my caption
I have tried looking at the caption package but I can only get the caption to be left justified with the margin not the figure.

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

Caption aligned to left Side of Figure

Post by localghost »

You could use the threeparttable package. It provides also the measuredfigure environment which allows to do what you want.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{threeparttable}

\captionsetup{%
  font=small,
  labelfont=bf,
  singlelinecheck=false,
  tableposition=top
}

\begin{document}
  \begin{figure}[!ht]
    \centering
    \begin{measuredfigure}
      \rule{6.4cm}{3.6cm}
      \caption{Dummy figure}\label{fig:dummy}
    \end{measuredfigure}
  \end{figure}
\end{document}
The floatrow package has similar capabilities (and much more beyond that).


Thorsten
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Caption aligned to left Side of Figure

Post by shadgrind »

You could use the boxhandler package, which uses left-aligned captions by default:

Code: Select all

\documentclass{article}
\usepackage{boxhandler}
\usepackage{graphicx}
\begin{document}
This is a paragraph of text, followed by a
centered figure with a left-justified caption,
called Figure \ref{fig:somepic}.

\begin{center}
\bxfigure[h]{\label{fig:somepic}Some figure}{
 \includegraphics{picture.png}
}
\end{center}
\end{document}
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

Re: Caption aligned to left Side of Figure

Post by daviddoria »

shadgrind, if I change

\includegraphics{picture.png}

to

\fbox{Dummy figure}

so I can try it without a picture.png, the output is not what I would expect (see attached).
Attachments
dummy.jpg
dummy.jpg (6.19 KiB) Viewed 66059 times
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

Caption aligned to left Side of Figure

Post by daviddoria »

localghost - I tried doing this with floatrow as you suggested, but it doesn't seem to respect the 'width' option of includegraphics.

Here is a demo without includegraphics to show that it works:

Code: Select all

\documentclass{article}
\usepackage{floatrow}
\usepackage{graphicx}
\begin{document}

\begin{figure}
\ffigbox[\FBwidth]
{\caption{caption text caption text caption text caption text 
caption text caption text caption text caption text 
caption text caption text caption text caption text }\label{...}}
{\fbox{Dummy Figure}}
\end{figure}

\end{document}

And then this works correctly (though you need a dummy.png in the folder, but as that is the part I'm troubleshooting I can't make a MWE without it):

Code: Select all

\documentclass{article}
\usepackage{floatrow}
\usepackage{graphicx}
\begin{document}

\begin{figure}
\ffigbox[\FBwidth]
{\caption{caption text caption text caption text caption text 
caption text caption text caption text caption text 
caption text caption text caption text caption text }\label{...}}
{\includegraphics{dummy}}
\end{figure}

\end{document}

Then finally, this does not work correctly - the caption is wider than the image:

Code: Select all

\documentclass{article}
\usepackage{floatrow}
\usepackage{graphicx}
\begin{document}

\begin{figure}
\ffigbox[\FBwidth]
{\caption{caption text caption text caption text caption text 
caption text caption text caption text caption text 
caption text caption text caption text caption text }\label{...}}
{\fbox{Dummy Figure}} % replace this with the includegraphics line as below
{\includegraphics[width=.4\linewidth]{dummy}} % the caption does not respect the 'width'
\end{figure}

\end{document}

Any suggestions?

Thanks,

David
Post Reply