\begin{figure}[h!]
\hspace{2cm}
\centering
\includegraphics[width=5in]{image}
\caption{Original target}
\label{fig:side:a}
\end{figure}
正如我\hspace
之前使用的图像一样,我希望我的标题也能如此\hspace{2cm}
,这样它就会位于图像的中心。
我如何才能改变标题的位置?
答案1
也许是这样的?
\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}