[Tex/LaTex] How to make a caption (table and figure) left justified

captionsfloatshorizontal alignment

How do I make my captions both for table and figures left aligned. I tried using \usepackage[justification=justified,singlelinecheck=false]{caption}.
But the caption is aligned with the page and not with the figure or table.

\documentclass[journal]{IEEEtran}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage[justification=justified,singlelinecheck=false]{caption}

\begin{document}
\begin{figure}[h!]
    \centering
    \includegraphics[height=2.1in,width=3.3in]{FPR_PpuCmpr}
\caption{False Positive Rate (FPR) Vs $P_{pu}$ (Majority Rule) }
\label{figureFPR_PpuCmpr}
\end{figure}

\end{document}

Best Answer

When using the caption package with the IEEEtran class you receive the following package warning:

Package caption Warning: Unsupported document class (or package) detected,
(caption)                usage of the caption package is not recommended.
See the caption package documentation for explanation.

So let's not use caption.

You can set the image-and-caption inside a minipage of fixed width. This fixed width would match what you want the image width to be, and then set width=\linewidth for your \includegraphics. This will ensure that the image is the same width as the width specified for the minipage:

enter image description here

\documentclass[journal]{IEEEtran}
\usepackage{graphicx,lipsum}

\begin{document}

\lipsum[1]

\begin{figure}[h!]
  \centering
  \begin{minipage}{2.5in}
    \includegraphics[height=2.1in,width=\linewidth]{example-image}
    \caption{This is some figure caption}
  \end{minipage}
\end{figure}

\lipsum[2]

\end{document}

When working with a table that you want the same to happen, you could use the varwidth package's varwidth environment; use \columnwidth as your "fixed-width specification". It's similar to minipage, but will shrink if the contents is narrower than specified.