我想要做的是使用图形、表格和替代图形标题,放置在左侧或右侧,具体取决于当前页面是奇数还是偶数。
感谢用户的大力帮助,回答了我的两个问题floatrow:更改奇数页和偶数页的标题位置和floatrow:更改奇数页和偶数页的标题位置(续),该floatrow
包用于自动定位图形和表格对象的标题。
我也想使用一个新对象,它将包含一张图片,但标题名称不应是“数字”我们可以把它叫做“另类人物”。因此我创建了一个信息框(见下面的代码),我尝试以与图形和表格相同的方式使用它,但它似乎不起作用。
任何想法都将受到赞赏。
\documentclass[12pt]{book}
\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage {atbegshi}
\usepackage[paperheight=24.0cm, paperwidth=20cm, top=1.75cm,bottom=2.0cm,left=2.0cm,right=6.0cm, headsep=0.25cm]{geometry}
\usepackage{floatrow}
\def\mypage{0}
\AtBeginShipout{\ifnum\mypage=0\relax\gdef\mypage{1}%
\else\gdef\mypage{0}\fi}
\expandafter\def\csname floatsetup0\endcsname{%
\floatsetup[widefigure]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}%
\floatsetup[table]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}}
\expandafter\def\csname floatsetup1\endcsname{%
\floatsetup[widefigure]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}%
\floatsetup[table]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}}
\newenvironment{altfig}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{figure*}[#1]}{\end{figure*}}
\newenvironment{alttable}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{table}[#1]}{\end{table}}
%-------------------------------
% INFOBOX
\usepackage{float}
\newfloat{infobox}{tbp}{ext}
\restylefloat*{infobox}
\floatname{infobox}{AlternativeFigure}
\newenvironment{altfigure}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{infobox}[#1]}{\end{infobox}}
%-------------------------------
\begin{document}
\lipsum[66]
\begin{altfig}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is the first caption text}
\end{altfig}
\lipsum[66]
\begin{alttable}[htp]
\begin{tabular}{lll}
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
\end{tabular}
\caption{This is a table text}
\end{alttable}
\lipsum[66]
\begin{infobox}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is an alternative caption text (should be positioned in the right hand side)}
\end{infobox}
\lipsum[66]
\begin{altfig}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is the second caption text}
\end{altfig}
\lipsum[66]
\begin{alttable}[htp]
\begin{tabular}{lll}
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
\end{tabular}
\caption{This is a table text}
\end{alttable}
\lipsum[66]
\begin{infobox}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is an alternative caption text (should be positioned in the left hand side)}
\end{infobox}
\end{document}
答案1
软件包floatrow
文档说不要将它与软件包一起使用float
,但您可以在 MWE 中使用它。以下是摘要的第一句话:“此软件包是作为 float 软件包的扩展而创建的。floatrow 软件包借用了 float 和 rotfloat 软件包的核心代码,因此您不能加载这些软件包。”
因此,要在 的上下文中完成这些事情floatrow
,请参阅第 4.1 节“如何替换\newfloat
为\DeclareNewFloatType
”。结果,我删除了该float
包,并用 替换了您\newfloat
的\DeclareNewFloatType{infobox}{placement=tbp,fileext=ext}
。
最后,您设置了altfigure
环境以利用侧边字幕,但后来却无法使用它……您仍然直接调用环境infobox
。因此,文档调用从infobox
变为 altfigure
。
\documentclass[12pt]{book}
\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage {atbegshi}
\usepackage[paperheight=24.0cm, paperwidth=20cm, top=1.75cm,bottom=2.0cm,left=2.0cm,right=6.0cm, headsep=0.25cm]{geometry}
\usepackage{floatrow}
%-------------------------------
% INFOBOX
\DeclareNewFloatType{infobox}{placement=tbp,fileext=ext}
\restylefloat*{infobox}
\floatname{infobox}{AlternativeFigure}
\newenvironment{altfigure}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{infobox}[#1]}{\end{infobox}}
%-------------------------------
\def\mypage{0}
\AtBeginShipout{\ifnum\mypage=0\relax\gdef\mypage{1}%
\else\gdef\mypage{0}\fi}
\expandafter\def\csname floatsetup0\endcsname{%
\floatsetup[widefigure]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}%
\floatsetup[table]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}%
\floatsetup[infobox]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}}
\expandafter\def\csname floatsetup1\endcsname{%
\floatsetup[widefigure]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}%
\floatsetup[table]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}%
\floatsetup[infobox]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}}
\newenvironment{altfig}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{figure*}[#1]}{\end{figure*}}
\newenvironment{alttable}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{table}[#1]}{\end{table}}
\begin{document}
\lipsum[66]
\begin{altfig}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is the first caption text}
\end{altfig}
\lipsum[66]
\begin{alttable}[htp]
\begin{tabular}{lll}
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
\end{tabular}
\caption{This is a table text}
\end{alttable}
\lipsum[66]
\begin{altfigure}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is an alternative caption text (should be positioned in the right hand side)}
\end{altfigure}
\lipsum[66]
\begin{altfig}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is the second caption text}
\end{altfig}
\lipsum[66]
\begin{alttable}[htp]
\begin{tabular}{lll}
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
\end{tabular}
\caption{This is a table text}
\end{alttable}
\lipsum[66]
\begin{altfigure}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is an alternative caption text (should be positioned in the left hand side)}
\end{altfigure}
\end{document}