[Tex/LaTex] How to position the caption at a customized place

captionshorizontal alignment

\begin{figure}[h!]
\hspace{2cm}
\centering
\includegraphics[width=5in]{image}
\caption{Original target}
\label{fig:side:a}
\end{figure}

As I used \hspace before the image, I would like my caption to \hspace{2cm} as well, so it would look at the center of the image.

How can I change the position of caption?

Best Answer

Maybe something like this?

\documentclass[12pt]{article}
\usepackage{graphicx,mwe}% mwe provides `example-image`

\newlength\myoffset \setlength{\myoffset}{2cm}

\newcommand\sometext{As I used hspace before the image, I
  would like my caption to hspace\{2cm\} as well, so it would
  look at the center of the image.  How can I change the position of
  caption?}

\begin{document}
\parindent 0pt % just for this example

\sometext
%
\begin{figure}[h!]
  \centering
  \framebox{\includegraphics[height=3cm]{example-image}}
  \caption{No offset}
  \label{fig:side:a}
\end{figure}
%
\sometext
%
\begin{figure}[h!]
  \hspace{\myoffset}%
  \begin{minipage}{\dimexpr\textwidth - \myoffset\relax}
    \centering \framebox{\includegraphics[height=3cm]{example-image}}
    \caption{Offset \& minipage}
    \label{fig:side:b}
  \end{minipage}
\end{figure}
%
\sometext
%
\begin{figure}[h!]
  \hspace{\myoffset}%
  \centering
  \framebox{\includegraphics[height=3cm]{example-image}}
  \caption{Original example}
  \label{fig:side:c}
\end{figure}
%
\sometext

\end{document}
Related Question