为了撰写我的硕士论文,我有一张横向图像,当最终将其打印在书中时,需要正确定位。
如果图片所在的页面在左侧(偶数页),则需要将图片旋转 90 度;如果图片所在的页面在右侧(奇数页),则需要将图片旋转 -90 度。在这两种情况下,图片的底部都需要靠近书脊。
有没有办法自动完成此操作,而不必每次都检查图像方向是否正确?我正在使用 documentclass report
,如果有帮助的话。
答案1
让包为你完成这些艰苦的工作(这也是它们被编写的原因之一)。rotating
套餐为您提供sidewaysfigure
(和sidewaystable
):
\documentclass{book}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{graphicx}
\usepackage{rotating}
\begin{document}
.\clearpage% just for the example
\begin{sidewaysfigure}
\centering
\includegraphics[width=8cm]{example-image-a}
\caption{rotated image}
\end{sidewaysfigure}
\begin{sidewaysfigure}
\centering
\includegraphics[width=8cm]{example-image-a}
\caption{rotated image}
\end{sidewaysfigure}
\end{document}
该代码需要运行两次才能确定正确的位置。
来自包装文档:
如果
twoside
已将选项提供给主文档类(无论是显式的还是隐式的,如类的默认设置book
),则包将根据页码横向旋转图形(这需要至少两次通过 LaTeX)。如果您想要该twoside
选项,但希望图形始终朝一个方向,请使用包的figuresright
或选项。figuresleft
现在我重新阅读了这个问题,似乎方向应该是这样的,即旋转图形的底部应该靠近书脊;这在某种程度上违背了公认的做法,即旋转图形的顶部应该靠近书脊;旋转包没有为这种情况实现选项,因此需要进行一些重新定义:
\documentclass{book}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{graphicx}
\usepackage{rotating}
\makeatletter
\def\end@rotfloat{%
\end{minipage}\end{lrbox}%
\stepcounter{r@tfl@t}%
\rot@label{RF\ther@tfl@t}%
\rot@pageref{RF\ther@tfl@t}{\R@@page}%
\edef\@tempa{Adding sideways \@captype\space on page \R@@page\space}
\rot@mess@toks\expandafter{\@tempa}
\wd\rot@float@box\z@
\ht\rot@float@box\z@
\dp\rot@float@box\z@
\vbox to \textheight{%
\setkeys{Grot}{units=360}%
\if@rot@twoside
\else
\let\R@@page\rot@LR
\fi
\ifthenelse{\isodd{\R@@page}}{%
\if@rot@twoside
\rot@mess@toks\expandafter{\the\rot@mess@toks (right hand page)}%
\fi
\@@line{%
\hskip\rotFPbot
\rotatebox{-90}{\box\rot@float@box}%
\hskip\rotFPtop
}%
\vfill
}{%
\if@rot@twoside
\rot@mess@toks\expandafter{\the\rot@mess@toks (left hand page)}%
\fi
\vfill
\@@line{%
\hskip\rotFPtop
\rotatebox{90}{\box\rot@float@box}%
\hskip\rotFPbot
}%
}%
\rot@message{\the\rot@mess@toks}
}%
\end@float
}
\let\endsidewaysfigure\end@rotfloat
\let\endsidewaystable\end@rotfloat
\makeatother
\begin{document}
.\clearpage% just for the example
\begin{sidewaysfigure}
\centering
\includegraphics[width=8cm]{example-image-a}
\caption{rotated image}
\end{sidewaysfigure}
\begin{sidewaysfigure}
\centering
\includegraphics[width=8cm]{example-image-a}
\caption{rotated image}
\end{sidewaysfigure}
\end{document}
答案2
您可以扩展方法
在此处保存用于奇数页和偶数页的顶部、底部和浮动的 8 个版本的图像,并选择在将浮动添加到该区域时使用哪个版本。
\documentclass{article}
\usepackage{color}
\usepackage{graphicx}
\def\a{One two three four five six. }
\def\b{Apple, Pear, Banana, Orange. }
\def\c{\a\a\b\par\b\b\b\a\b\par\b\b\b\par}
\makeatletter
\def\floatswitch#1#2#3#4#5#6#7#8{%
\def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
\edef\FS@ckpt{\cl@@ckpt}%
\let\@elt\relax
\hbox to 3sp{%
\vbox{{\FS@ckpt#1\par}}%
\vbox{{\FS@ckpt#2\par}}%
\vbox{{\FS@ckpt#3\par}}%
\vbox{{\FS@ckpt#4\par}}%
\vbox{{\FS@ckpt#5\par}}%
\vbox{{\FS@ckpt#6\par}}%
\vbox{{\FS@ckpt#7\par}}%
\vbox{{\FS@ckpt#8\par}}%
\hss}\aftergroup\break}
\tracingonline2
\showboxdepth1
\showboxbreadth25
\errorcontextlines\maxdimen
\def\FS@checkswitch#1{%
\ifdim\wd#1=3sp %
\setbox\z@\box#1%
\begingroup
\vbadness\maxdimen
\setbox\z@\vsplit\z@ to \textheight
\setbox\z@\vbox{\unvbox\z@\global\setbox\@ne\lastbox}%
\setbox\z@\vbox{\unvbox\@ne\unskip\global\setbox\@ne\lastbox}
\setbox\z@\hbox{\unhbox\@ne\unskip
\FS@junk
\global\setbox\@ne\lastbox}%
\endgroup
\else
\global\setbox\@ne\box#1%
\fi}
\def\@comflelt#1{%
\FS@checkswitch#1%
\setbox\@tempboxa
\vbox{\unvbox\@tempboxa\box\@ne\vskip\floatsep}}
\let\saved@cflt\@cflt
\def\@cflt{%
\def\FS@junk{%
\setbox\z@\lastbox\setbox\z@\lastbox\setbox\z@\lastbox
\setbox\z@\lastbox\setbox\z@\lastbox\setbox\z@\lastbox
\ifodd\c@page\setbox\z@\lastbox\fi
}%
\saved@cflt}
\let\FS@junk\relax
\let\saved@cflb\@cflb
\def\@cflb{%
\def\FS@junk{%
\setbox\z@\lastbox\setbox\z@\lastbox
\setbox\z@\lastbox\setbox\z@\lastbox
\ifodd\c@page\setbox\z@\lastbox\fi
}%
\saved@cflb}
\def\foo#1\box\@currbox#2!!{%
\def\@addtocurcol{%
#1%
\def\FS@junk{%
\ifodd\c@page\setbox\z@\lastbox\fi
}
\FS@checkswitch\@currbox
\box\@ne
#2}}%
\expandafter\foo\@addtocurcol!!
\def\@wtryfc #1{%
\global\setbox\@outputbox\vbox{%
\unvbox\@outputbox
\vskip\@fpsep
\def\FS@junk{%
\setbox\z@\lastbox
\setbox\z@\lastbox
\ifodd\c@page\setbox\z@\lastbox\fi
}%
\FS@checkswitch#1%
\box\@ne}}
\makeatother
\begin{document}
\c
\def\fig#1{%
\begin{figure}#1
\floatswitch
{%
\color{red}\centering\rotatebox{90}{\fbox{$\frac{123456}{\frac{1}{2}}$}}
\caption{odd t floats are red}}
{%
\color{red}\centering\rotatebox{-90}{\fbox{$\frac{123456}{\frac{1}{2}}$}}
\caption{even t floats are red}}
%
{%
\color{blue}\centering\rotatebox{90}{\fbox{$\frac{123456}{\frac{1}{2}}$}}
\caption{odd b floats are blue}}
{%
\color{blue}\centering\rotatebox{-90}{\fbox{$\frac{123456}{\frac{1}{2}}$}}
\caption{even b floats are blue}}
%
{%
\color{green}\centering\rotatebox{90}{\fbox{$\frac{123456}{\frac{1}{2}}$}}
\caption{odd p floats are green}}
{%
\color{green}\centering\rotatebox{-90}{\fbox{$\frac{123456}{\frac{1}{2}}$}}
\caption{even p floats are green}}
%
{%
\color{yellow}\centering\rotatebox{90}{\fbox{$\frac{123456}{\frac{1}{2}}$}}
\caption{odd h floats are yellow!}}
{%
\color{yellow}\centering\rotatebox{-90}{\fbox{$\frac{123456}{\frac{1}{2}}$}}
\caption{even h floats are yellow??}}
\end{figure}%
}
%
\clearpage
\fig{}
\c
\fig{[!h]}
\fig{[b]}
\c
\fig{[p]}
\begin{figure}
\centering
\fbox{NO SWITCH}
\caption{no switch}
\end{figure}
\c
\clearpage
\mbox{zzz}
\clearpage
\fig{}
\c
\fig{[!h]}
\fig{[b]}
\c
\fig{[p]}
\begin{figure}
\centering
\fbox{NO SWITCH}
\caption{no switch}
\end{figure}
\c
\end{document}
答案3
因为没有关于标题的内容,所以应该足够了(graphicx
必须加载包):
\def\mygr#1{\ifodd\value{page} \includegraphics[angle=-90]{#1}
\else \includegraphics[angle=90]{#1} \fi}
有一个明显的用法:\mygr{nameofpicture}
。