浮动设置“左侧为图形,右侧为文本,右侧为编号”

浮动设置“左侧为图形,右侧为文本,右侧为编号”

我希望左页有图片,右页有文字,并且只在右页有编号,因此我遵循了以下步骤: 左页有图片,右页有正文,课本上有页码

但是我的一些图形必须是侧面的,因此我想使用 sidewaysfigure 环境,而其他一些图形需要子图:我怎样才能对我的图形使用浮点数?

答案1

这是这是“左页上有图片,右页上有课本上的文字,仅在右页上有编号”的解决方案;请参阅下面的完整代码。

\addfig用以下两行替换

\newcommand\addfig[1]%
  {\g@addto@macro\sos@figures
     {\vbox{\def\@captype{figure}\centering#1}\vfill}%
  }
\newcommand\addtab[1]%
  {\g@addto@macro\sos@figures
     {\vbox{\def\@captype{table}\centering#1}\vfill}%
  }

现在您不再需要加载包caption。对于横向图形,请加载包rotating,对于子图形,请加载包subfigure。在上面引用的示例代码中,这意味着\usepackage{booktabs,caption}

\usepackage{booktabs,rotating,subfigure}

要添加图形或表格,使用

\addfig
  {...code of figure...
   \caption{...caption of figure...}%
   \label{...label of figure ...}%
  }

或者

\addtab
  {...code of table...
   \caption{...caption of table...}%
   \label{...label of table ...}%
  }

对于子图,使用

\addfig
  {\subfigure[...caption of subfigure 1]{...code of subfigure 1...}%
   \subfigure[...caption of subfigure 2]{...code of subfigure 2...}%
   \caption{...main caption...}%
  }

\addtab(表格也同样如此)。

对于横向图形无侧边字幕使用

\addfig
  {\begin{sideways}
   ...code of sideways figure...
   \end{sideways}%
   \caption{...caption of figure...}%
  }

对于横向图形带横向标题使用

\addfig
  {\begin{sideways}
     \begin{minipage}{...width of sideways box...}
     ...code of sideways figure...
     \caption{...sideways caption of sideways figure...}%
     \end{minipage}%
   \end{sideways}%
  }

在此处输入图片描述

为了独立起见,这里是完整的修改后的代码。

\documentclass{book}
\usepackage{atbegshi}
\makeatletter
\newlength{\sos@top}
\newlength{\sos@right}
\newcounter{sos@pages}
\newif\ifSOS
\renewcommand{\thepage}{\the\numexpr\value{page}-\value{sos@pages}\relax}
\newcommand\addfig[1]{\g@addto@macro\sos@figures{\vbox{\def\@captype{figure}\centering#1}\vfill}}
\newcommand\addtab[1]{\g@addto@macro\sos@figures{\vbox{\def\@captype{table}\centering#1}\vfill}}
\newcommand{\sos@reset@figures}
  {\gdef\sos@figures{\sos@reset@figures\vfill}}
\sos@reset@figures
\newcommand{\sos@shipout@figures}
  {%
    \begingroup
      \stepcounter{page}%
      \stepcounter{sos@pages}%
      \let\protect\relax
      \setbox\z@\vbox to\vsize{\sos@figures}%
      \let\protect\string
      \AtBeginShipoutOriginalShipout\vbox
        {\vbox to\sos@top{}\moveright\sos@right\box\z@}%
    \endgroup
  }
\AtBeginShipout{%
  \ifSOS\ifodd\c@page
    \begingroup
      \let\protect\string
      \AtBeginShipoutOriginalShipout\box\AtBeginShipoutBox
      \global\AtBegShi@Discardedtrue
      \sos@shipout@figures
    \endgroup
  \fi\fi
}%
\newcommand{\SOSshipout}{\clearpage\sos@shipout@figures}
\renewcommand{\SOStrue}{\clearpage\global\let\ifSOS\iftrue}
\renewcommand{\SOSfalse}{\clearpage\global\let\ifSOS\iffalse}
\setlength{\sos@top}{2cm}
\setlength{\sos@right}{2cm}
\makeatother

% Test example
\usepackage{booktabs,rotating,subfigure}
\usepackage{lipsum}
\usepackage{hyperref}
\begin{document}

\title{Hello world}
\author{Bruno Le Floch}
\maketitle

\tableofcontents
\listoffigures
\listoftables

\part{Abc}

\SOStrue
\chapter{Hello}

\addtab{\begin{tabular}{p{5cm}p{5cm}}
    \toprule
    Abc def & ghijk lmno pq \\
    \midrule
    \lipsum[1] & \lipsum[2] \\
    \bottomrule
  \end{tabular}
  \caption{\label{tab:atable}A table}}

\addfig{%
  \rule{8cm}{3cm}%
  \caption{A figure}}

\lipsum[1-10]

\addfig{\begin{sideways}\includegraphics[width=5cm]{example-image}\end{sideways}\caption{A sideways figure}}
\addfig{\begin{sideways}\begin{minipage}{5cm}\includegraphics[width=\textwidth]{example-image}\caption{A sideways figure with sideways caption.}\end{minipage}\end{sideways}}
\addfig{%
\subfigure[Image A]{\includegraphics[width=3cm]{example-image-a}}
\subfigure[Image B]{\includegraphics[width=3cm]{example-image-b}}
\caption{Two sub-figures side by side.}}

\chapter{Bye}

\makeatletter
\renewcommand{\lips@par}{ } % now \lipsum[1-10] makes one big par
\makeatother

\addfig{\rule{8cm}{3cm}\caption{That should be figure 5.}}
\addfig{\rule{1cm}{3cm}\caption{Perhaps the sixth}}

\lipsum[1-10]

\addfig{\rule{8cm}{3cm}\caption{Yet another one}}
\addfig{}

\SOSfalse

\chapter{Back to normal}

\addfig{\rule{8cm}{3cm}\caption{That figure won't be lost.}}

\lipsum[11-15]

\addfig{\rule{4cm}{5cm}\caption{Nor will that one.}}

\lipsum[16-20]

\lipsum[21-30]

See Table~\ref{tab:atable}.

\SOSshipout
\SOStrue

\chapter{Figures, again}

\addtab{\rule{5cm}{2cm}\caption{Let's pretend it's a table}}

\lipsum[21-25]

\addtab{\rule{5cm}{2cm}\caption{Let's pretend it's a table}}

\lipsum[26-30]

\addtab{\rule{4cm}{1cm}\caption{Last table}}

\end{document}

相关内容