我正在寻找一个命令或环境,用于将后面的内容向页面内侧对齐/对齐。(当然,这只对双面文档有意义。)更具体地说,我想将我的图形对齐到页面的内边缘。
是否存在这样的命令或环境?
梅威瑟:
\documentclass[a4paper, draft]{scrbook}
\usepackage{todonotes}
\begin{document}
\begin{figure}
%\begin{flushinner} ??
\missingfigure[figwidth=6cm, figheight=15cm]{}
%\end{flushinner}
\caption{This figure should be aligned to the left because it is on a "right page"}
\end{figure}
\begin{figure}
%\begin{flushinner} ??
\missingfigure[figwidth=6cm, figheight=15cm]{}
%\end{flushinner}
\caption{This figure should be aligned to the right because it is on a "left page"}
\end{figure}
\end{document}
答案1
KoMa 课程提供\ifthispageodd
(它使用标签,因此需要多次运行才能工作)。
\documentclass[a4paper,draft]{scrbook}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\ifthispageodd{\ignorespaces}{\hfill}
\includegraphics[width=6cm,height=15cm]{example-image-a}
\caption{This figure should be aligned to the left because it is on a recto page. Text text text.}
\end{figure}
\begin{figure}
\ifthispageodd{\ignorespaces}{\hfill}
\includegraphics[width=6cm,height=15cm]{example-image-b}
\caption{This figure should be aligned to the right because it is on a verso page. Text text text.}
\end{figure}
\end{document}
答案2
感谢 David Carlisle 和 campa,这里有一个可行的解决方案:
\documentclass[a4paper]{scrbook}
\usepackage{graphicx}
\newenvironment{flushinner}{
\ifthispageodd{
\begin{flushleft}
}{
\begin{flushright}
}
}{
\ifthispageodd{
\end{flushleft}
}{
\end{flushright}
}
}
\begin{document}
\begin{figure}
\begin{flushinner}
\includegraphics[height=15cm]{some-figure}
\end{flushinner}
\caption{This figure should be aligned to the left}
\end{figure}
\begin{figure}
\begin{flushinner}
\includegraphics[height=15cm]{some-figure}
\end{flushinner}
\caption{This figure should be aligned to the right}
\end{figure}
\end{document}