我正在寻找一种独立于预定义边框边距的居中图像的方法。如您所见,图像 A 相对于文本居中。B 完全错误,或者换句话说,没有忽略文本边距。C 是一个尝试,但我想自动将图像居中(甚至与边距文本重叠)。提前致谢。
\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}
答案1
我相信这个答案与您的要求相关,并相对于文本/页边距居中,即图像平等地进入左/右边距。
\centerline{}
例如添加\centerline{\includegraphics[scale=.8]{example-image-c}}
。
编辑:或者,如果您希望图像从页面边缘跨越到页面边缘(或基于纸张宽度),那么这个答案就是您要找的。您需要根据图形大小进行调整。
这是一个解决方案(我简化了你复杂的“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}\\