![双列文档中的浮动行和旁边的标题](https://linux22.com/image/350408/%E5%8F%8C%E5%88%97%E6%96%87%E6%A1%A3%E4%B8%AD%E7%9A%84%E6%B5%AE%E5%8A%A8%E8%A1%8C%E5%92%8C%E6%97%81%E8%BE%B9%E7%9A%84%E6%A0%87%E9%A2%98.png)
请看以下例子:
\documentclass[a4paper, landscape, twoside, twocolumn]{book}
\usepackage[a4paper, landscape, twoside, twocolumn, top=0.8cm, bottom=1cm, bindingoffset=1.5cm, inner=6mm, outer=6mm, includemp, includeheadfoot, marginparwidth=3.5cm, marginparsep=4mm, headheight=16pt, showframe=true]{geometry}
\usepackage{floatrow}
\usepackage{blindtext}
\DeclareFloatSeparators{marginparsep}{\hskip\marginparsep}
\floatsetup[figure]{facing=yes, capposition=beside, capbesidewidth=\marginparwidth, capbesideposition={bottom, outside}, capbesidesep=marginparsep, floatwidth=\textwidth, margins=hangoutside}
\begin{document}
\begin{figure}
\centering
\rule{3cm}{2cm}
\caption{This is a needlessly long caption to which runs at least two lines.}
\end{figure}
\blindtext
\newpage% makes a new column
\blindtext
\begin{figure}
\centering
\rule{3cm}{2cm}
\caption{This is a needlessly long caption to which runs at least two lines.}
\end{figure}
\end{document}
对于单列文档来说,这是一个完美的解决方案,因为标题会出现在页边距中。但是,如果您编译此示例,您会发现这对双列文档不起作用。第一列中的图形的标题会出现在第二列中。但它应该放在左边距中。
我知道以下选项
capbesideposition={bottom, outside}
是问题所在。但我不知道如何告诉 floatrow 它必须检查图形放在哪一列。
您有什么想法可以解决这个问题吗?
谢谢。
答案1
我不确定我是否理解了您想要的文档布局...像这样?
\documentclass[a4paper, landscape, twoside, twocolumn]{book}
\usepackage{graphicx}
\usepackage[a4paper, landscape, twoside, twocolumn, top=0.8cm, bottom=1cm, bindingoffset=1.5cm, inner=6mm, outer=6mm, includemp, includeheadfoot, marginparwidth=3.5cm, marginparsep=4mm, headheight=16pt, showframe]{geometry}
\usepackage{floatrow}
\usepackage{blindtext}
\floatsetup[figure]{margins=hangleft,capposition=beside,
capbesideposition={top,left},floatwidth=\linewidth}
\begin{document}
\begin{figure}
\includegraphics[width=\linewidth]{example-image-a}
\caption{This is the A needlessly long caption to which runs at least two lines.}
\end{figure}
\blindtext
\newpage
\blindtext
\floatsetup[figure]{margins=hangright, capbesideposition={right}}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{This is the B needlessly long caption to which runs at least two lines.}
\end{figure}
\end{document}
要自动更改设置,您可以使用\if@firstcolumn
宏(\xxx
在下一个示例中将其更改为更有意义的设置)。
\documentclass[a4paper, landscape, twoside, twocolumn]{book}
\usepackage{graphicx}
\usepackage[a4paper, landscape, twoside, twocolumn, top=0.8cm, bottom=1cm, bindingoffset=1.5cm, inner=6mm, outer=6mm, includemp, includeheadfoot, marginparwidth=3.5cm, marginparsep=4mm, headheight=16pt]{geometry}
\usepackage{floatrow}
\usepackage{lipsum}
\floatsetup[figure]{capposition=beside,
capbesideposition={top},floatwidth=\linewidth}
\makeatletter
\def\xxx#1#2{\if@firstcolumn
\floatsetup[figure]{margins=hangleft, capbesideposition={left}}
\begin{figure}[hbtp]
\centering
\includegraphics[width=\linewidth]{#1}
\caption{#2}
\end{figure}
\else
\floatsetup[figure]{margins=hangright, capbesideposition={right}}
\begin{figure}[btp]
\centering
\includegraphics[width=\linewidth]{#1}
\caption{#2}
\end{figure}
\fi}%
\makeatother
\begin{document}
\xxx{example-image-a}{This is the A needlessly long caption to which runs at least two lines.}
\lipsum[1-2]
\xxx{example-image-b}{This is the B needlessly long caption to which runs at least two lines.}
\lipsum[3-8]
\xxx{example-image-c}{This is the B needlessly long caption to which runs at least two lines.}
\lipsum[9]
\end{document}
但是,如果浮动元素没有移动到列的顶部或底部,而是跳转到下一列或下一页,这种方法可能会失败。解决这种情况的一个选项是将宏移动到真正会出现的列的文本之间,或者允许该选项h
(此处)或者...可以使用不带浮动元素的方法。