# centering image relative to page (skipping margins)

I am looking for a way to center images independent of the predefined border margins. As you can see, image A is centered relative to the text. B is somthing wrong completly or in other words does not ignore the text-margin. C is a try but I would like to auto center the image (even overlapping the margin text). Thanks in Advance.

\documentclass[twoside]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[paperheight=28cm, paperwidth=14cm,%
top=2cm, bottom=2cm, left=1cm, right=2.5cm,%
]{geometry}

\usepackage{xcolor}
\usepackage{scrlayer}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{pdfpages}
\usepackage{blindtext}

\newcommand{\grey}[1]{\textcolor[gray]{.66}{#1}}

\DeclareNewLayer[
background,
evenpage,
leftmargin,
contents={%
\vfil\hfil\rotatebox{90}{%
\fontsize{60}{100}\selectfont\grey\leftmark%
}\hfil\vfil
}]{markmargin-left}
\DeclareNewLayer[
background,
oddpage,
rightmargin,
contents={%
\vfil\hfil\rotatebox{-90}{%
\fontsize{60}{100}\selectfont\grey\rightmark%
}\hfil\vfil
}]{markmargin-right}

\DeclareNewPageStyleByLayers{markmargin}{markmargin-left,markmargin-right}
\pagestyle{markmargin}

%\automark[section]{section}
\manualmark
\renewcommand\section[1]{%
\clearpage%
\markboth{\textit{#1}}{\textit{#1}}
}

\parindent0pt

\begin{document}
\section{A.1 test page}
\blindtext
\begin{figure}[!ht]
\centering
\includegraphics[scale=.8]{example-image-a}
\end{figure}

\clearpage
\section{A.2 test page}
\blindtext
\begin{figure}[!ht]
\centering
\includegraphics[scale=.8]{example-image-a}
\end{figure}

\clearpage
\section{B.1 test page}
\blindtext
\begin{figure}[!ht]
\makebox[\paperwidth][c]{\includegraphics[scale=.8]{example-image-b}}
\end{figure}

\clearpage
\section{B.2 test page}
\blindtext
\begin{figure}[!ht]
\makebox[\paperwidth][c]{\includegraphics[scale=.8]{example-image-b}}
\end{figure}

\clearpage
\section{C.1 test page}
\blindtext
\begin{figure}[!ht]
\hspace{1.3cm}
\includegraphics[scale=.8]{example-image-c}
\end{figure}

\clearpage
\section{C.2 test page}
\blindtext
\begin{figure}[!ht]
%       \hspace{-1.5cm}
\includegraphics[scale=.8]{example-image-c}
\end{figure}
\end{document}

• Please see my answer below and clarify which option you want. – AML Apr 24 '18 at 17:05
• Done. Sorry for the delay. – Pratched Apr 25 '18 at 17:22

I believe this answer is relevant to what you asked and centers relative to the text/page margins, i.e, the images enters the left/right margins equally.

Add \centerline{}, for example \centerline{\includegraphics[scale=.8]{example-image-c}}.

Edit: Alternatively, if you want the image to span from page edge to page edge (or based on paperwidth), then this answer is what you're looking for. You'll need to adjust based on figure size.

Here is a solution (I simplified your complicated "MWE"):

\documentclass[twoside]{scrartcl}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[paperheight=28cm, paperwidth=14cm,%
top=2cm, bottom=2cm, left=1cm, right=2.5cm,showframe
]{geometry}

\begin{document}

\lipsum[1]
\noindent\makebox[\textwidth][l]{%
\hspace{\dimexpr\oddsidemargin+1.9cm}%
\includegraphics[width=0.8\paperwidth]{example-image-a}%
}

\newpage
\lipsum[2]
\noindent\makebox[\textwidth][l]{%
\hspace{-\dimexpr\evensidemargin+1.15cm}%
\includegraphics[width=0.8\paperwidth]{example-image-b}%
}

\newpage
\lipsum[3]
\noindent\makebox[\textwidth][l]{%
\hspace{\dimexpr\oddsidemargin+1.9cm}%
\includegraphics[width=0.8\paperwidth]{example-image-c}%
}

\newpage
\lipsum[4]
\noindent\makebox[\textwidth][l]{%
\hspace{-\dimexpr\evensidemargin+1.15cm}%
\includegraphics[width=0.8\paperwidth]{example-image}%
}

\end{document}\\

• mhmm...Well at first, thanks for your response to my issue. And I am sorry for the late response to that. Maybe I didnt understand your solution, but using \centerline{} is resulting in an equal positioning as \centering. Which is not what I am after. Both options are centering the image in relation to the text and its width. – Pratched Apr 25 '18 at 16:59
• I want to center the image in relation to the actual page, unrelated to the margin definied by the rotated border text. Furthermore I dont intend to spread the image from edge to edge without any border. I want the image centered with the same margin on the right and the left side ONLY in relation to the actual paperwidth defined with the geometry package. – Pratched Apr 25 '18 at 16:59
• @Djiwahwah I updated my answer. The new solution gives you what you want. But if you want an automated version, then I suggest you post a new question from the answer I gave. – AML Apr 25 '18 at 18:13