调整字幕位置

调整字幕位置

我改编了 Springer 的 SVMONO 代码,允许\sidecaption在普通图形环境中使用该命令。然后标题将放置在图形旁边而不是图形下方。此外,还有选项 [t] 将侧标题放在底部。示例:

在此处输入图片描述 在此处输入图片描述

我读过一些排版规则,其中规定如果图形位于页面顶部,则标题应位于顶部;如果图形靠近页面底部,则标题应位于底部。我喜欢侧标题,但在撰写文档时,我通常不知道图形是位于页面顶部还是底部。我想知道是否有某种宏技术可以检查图形在页面上的位置,然后根据图形是靠近顶部还是底部,将 转换\sidecaption\sidecaption[t]

答案1

由于没有 mwe 或无法访问 SVMONO,我创建了自己的 \SideCaption 宏。此版本比较了图形的中心与文本区域的中心。我不确定奇数/偶数页规则。顺便说一句,需要运行两次才能知道tikzpicture它在页面上的位置。

\documentclass{book}
\usepackage{tikzpagenodes}
\usepackage{caption}
\usepackage{mwe}% for \lipsum and \blindtext

\makeatletter
\newcommand{\SideCaption}[2]% #1 = image, #2 = caption
{\sbox0{#1}%
 \sbox1{\begin{minipage}{\dimexpr \textwidth-\wd0-\columnsep}
   \captionsetup{singlelinecheck=off,skip=0pt}%
   \caption{#2}%
 \end{minipage}}
 \@tempdima=\dimexpr \ht0+\dp0\relax% could be a tabular
 \@tempdimb=\dimexpr \ht1+\dp1\relax%
 \ifdim\@tempdima<\@tempdimb
   \raisebox{-\height}{\usebox1}\hfill\raisebox{-\height}{\usebox0}
 \else
   \begin{tikzpicture}[remember picture]
     \node(frame) [minimum height=\@tempdima,text width=\textwidth,inner sep=0pt] {};
     \pgfextracty{\@tempdimb}{\pgfpointdiff{\pgfpointanchor{current page text area}{center}}%
       {\pgfpointanchor{frame}{center}}}%
     \ifoddpageoroneside
       \ifdim\@tempdimb>0pt% above center
         \node[below right,inner sep=0pt] at (frame.north west) {\usebox1};
       \else
         \node[above right,inner sep=0pt] at (frame.south west) {\usebox1};
       \fi
       \node[left,inner sep=0pt] at (frame.east) {\usebox0};
     \else
       \ifdim\@tempdimb>0pt% above center
         \node[below left,inner sep=0pt] at (frame.north east) {\usebox1};
       \else
         \node[above left,inner sep=0pt] at (frame.south east) {\usebox1};
       \fi
       \node[right,inner sep=0pt] at (frame.west) {\usebox0};
     \fi
   \end{tikzpicture}
 \fi}
\makeatother

\def\bottomfraction{0.7}% allow large bottom figures

\begin{document}

\begin{figure}[t]
\SideCaption{\includegraphics[scale=0.5]{example-image}}{Top caption}
\end{figure}
\begin{figure}[b]
\SideCaption{\includegraphics[scale=0.5]{example-image}}{Bottom caption}
\end{figure}
\begin{figure}[t]
\SideCaption{\includegraphics[scale=0.5]{example-image}}{Top caption}
\end{figure}
\begin{figure}[b]
\SideCaption{\includegraphics[scale=0.5]{example-image}}{Bottom caption}
\end{figure}
\begin{figure}[t]
\SideCaption{\includegraphics[scale=0.5]{example-image}}{\blindtext}
\end{figure}

\lipsum[1-5]

\end{document}

两页

相关内容