The width=
setting of the caption
package will always center its caption with respect to the \textwidth
, so width=1.2\textwidth
will give you infact a left and right margin of -0.1\textwidth
.
For manipulating its margins, better use margin=
instead, since it offers discrete values for left and right margin. For example:
\documentclass{scrartcl} % KOMA-Script article
\usepackage{lipsum}
\usepackage[english]{babel}
\usepackage{graphicx}\graphicspath{Figures}
\usepackage[format=plain,justification=raggedright,font={small}]{caption}
% uncomment this if the setting should affect all figures
%\captionsetup[figure]{margin={0pt,-0.2\textwidth}}
\begin{document}
\lipsum[120]
\begin{figure}[thbp]
\includegraphics[draft,width=1.2\textwidth]{Figures/foo.pdf}%
\captionsetup{margin={0pt,-0.2\textwidth}}% only for this figure
\caption{Caption that has the same width as the figure, but should be aligned to the left as everything else, but should spill out of the right margin}
\label{fig:key}
\end{figure}
\lipsum[120]
\end{document}
As an alternative, one could put the whole figure contents inside a minipage with the desired width, this way both the content and the caption will be adjusted to the new width:
\documentclass{scrartcl} % KOMA-Script article
\usepackage{lipsum}
\usepackage[english]{babel}
\usepackage{graphicx}\graphicspath{Figures}
\usepackage[format=plain,justification=raggedright,font={small}]{caption}
\begin{document}
\lipsum[120]
\begin{figure}[thbp]
\begin{minipage}{1.2\textwidth}
\includegraphics[draft,width=\textwidth]{Figures/foo.pdf}%
\caption{Caption that has the same width as the figure, but should be aligned to the left as everything else, but should spill out of the right margin}
\label{fig:key}
\end{minipage}
\end{figure}
\lipsum[120]
\end{document}
Both should give identical results:
For one sided setting you just have to take account of \oddsidemargin
and the default 1in
offset:
\documentclass[10pt,a4paper,oneside]{report}
\usepackage{blindtext}
\usepackage[demo]{graphicx}
\usepackage[bottom=1in,left=1.22in,right=1.63in]{geometry}
\begin{document}
\blindtext
%desired output: equal whitespace both sides
\begin{figure}
\hspace*{-\dimexpr\oddsidemargin+1in\relax}\makebox[\paperwidth]{%
\includegraphics[width=1.4\textwidth,height=4cm]{myPictureName.png}}\hspace*{-\paperwidth}
\end{figure}
\end{document}
Best Answer
Put the content of your
figure
environment into a\makebox[\textwidth][c]{...}
macro. This will center its content to the normal text width even if it is wider than that. See also my similar answer to Place figures side by side, spill into outer margin.The image can also be aligned to the left and right using
[l]
and[r]
, which makes the image lap into the right or left margin, respectively.Example:
Starting from 2011/08/13 you can also use
adjustbox
package for such alignments. For centering use thecenter=<length>
which centers the content in the given length. The length is optional and defaults to\linewidth
which is normally identical to\textwidth
. There is alsoleft
andright
as well asinner
andouter
.