图像未在全宽偶数页中居中

图像未在全宽偶数页中居中

我的 MWE 是,

\documentclass[a4paper,twoside,openright,11pt]{scrbook}

\usepackage[left=1.5cm,right=1cm,top=3cm,bottom=1.5cm,marginparwidth=5.5cm,marginparsep=1cm,outer=8cm]{geometry}

\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{ifoddpage}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{calc}
\usepackage{showframe}

\newlength\fullwidth\fullwidth=\textwidth \advance\fullwidth by \marginparwidth
\advance\fullwidth by \marginparsep
\newlength\extraWd
\setlength\extraWd{\dimexpr\marginparwidth+\marginparsep\relax}

\begin{document}

\begin{figure}[h]
\captionsetup{margin={0cm,-\extraWd}}
\checkoddpage
\edef\side{\ifoddpage c\else l\fi}
\makebox[\fullwidth][\side]{%
\fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-a}}
}%
\caption{In the previous paragraphs, we mentioned the word “charge”. However, we need to look at its meaning in more detail.}
\end{figure}

\newpage

\begin{figure}[h]
\captionsetup{margin={0cm,-\extraWd}}
\checkoddpage
\edef\side{\ifoddpage c\else l\fi}
\makebox[\fullwidth][\side]{% 
    \fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-a}}
}%
\caption{In the previous paragraphs, we mentioned the word “charge”. However, we need to look at its meaning in more detail.}
\end{figure}

\end{document}

奇数页输出没有问题,精确居中,{左边空间 10cm,右边空间 10cm} 在此处输入图片描述

但是页面也有问题。没有完全居中。{左侧空间 11cm,右侧空间 9cm} 在此处输入图片描述

事实上,图像向左移动了 1 厘米(\marginparwidth)。或者对 \fullwidth 进行居中。我做不到,几天就搞定了。

我确信,这对你来说很容易,但对我来说却不容易。我没有找到另一个重复的问题。我发现类似的问题,无法在我的代码中完全运行。有人知道如何修复它吗?

有关的: 让标题浮动到边距

答案1

让我们分析一下。首先我们\fbox在周围添加一个\makebox,例如:

\fbox{\makebox[\fullwidth][\side]{%
    \fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-a}}
}}%

要得到

在此处输入图片描述

对于奇数页和

在此处输入图片描述

对于偶数页。您可能希望此框覆盖整个宽度,即,\textwidth +\marginparwidth +\marginparsep对于奇数页是正确的,但对于偶数页则不正确。对于偶数页,框从文本区域内开始,文本区域应从 marginpar 区域开始,以便覆盖到文本区域的末尾,并进行c回车对齐。

代码:

\documentclass[a4paper,twoside,openright,11pt]{scrbook}

\usepackage[left=1.5cm,right=1cm,top=3cm,bottom=1.5cm,marginparwidth=5.5cm,marginparsep=1cm,outer=8cm]{geometry}

\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{ifoddpage}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{calc}
\usepackage{showframe}

\newlength\fullwidth
\setlength{\fullwidth}{\dimexpr\textwidth +\marginparwidth +\marginparsep\relax}
\newlength\extraWd
\setlength\extraWd{\dimexpr\marginparwidth+\marginparsep\relax}


\begin{document}

\begin{figure}[h]
\captionsetup{margin={0cm,-\extraWd}}
\checkoddpage
\ifoddpage
\fbox{\makebox[\fullwidth][c]{%
\fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-a}}
}}%
\else
\hspace*{-\extraWd}%
\fbox{\makebox[\fullwidth][c]{%
\fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-a}}
}}%
\fi
\caption{In the previous paragraphs, we mentioned the word “charge”. However, we need to look at its meaning in more detail.}
\end{figure}

\newpage

\begin{figure}[h]
\captionsetup{margin={0cm,-\extraWd}}
\checkoddpage
\ifoddpage
\fbox{\makebox[\fullwidth][c]{%
\fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-a}}
}}%
\else
\hspace*{-\extraWd}%
\fbox{\makebox[\fullwidth][c]{%
\fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-a}}
}}%
\fi
\caption{In the previous paragraphs, we mentioned the word “charge”. However, we need to look at its meaning in more detail.}
\end{figure}

\end{document}

在此处输入图片描述

无外层\fbox

\ifoddpage
\makebox[\fullwidth][c]{%
\fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-a}}
}%
\else
\hspace*{-\extraWd}%
\makebox[\fullwidth][c]{%
\fbox{\includegraphics[keepaspectratio=false,width=6cm]{example-image-b}}
}%
\fi

在此处输入图片描述

相关内容