我正在使用sidecpation
该sidenotes
包将标题排版到页边距中。我希望这些标题与浮动顶部对齐。
可以简单地将sidecaption
命令放在浮动的开头。但是,与子图结合使用时,这会破坏编号(这里)。由于这个问题,我将命令放在sidecaption
最后,并使用可选offset
参数重新定位它。手动执行此操作并为大量图形实现一致的布局非常困难,我希望实现自动化。
将当前图形的高度作为偏移量,可以以简单直接的方式解决这个问题。但我如何获得这个长度呢?
请注意,我感兴趣的不是单张图片的高度,而是整个浮动的高度,浮动高度可能由subfigure
具有单独子标题的环境中的多张图片组成。如果该方法还涵盖,那将是一个加分项tabulars
。
也可以使用其他选项来将侧标题顶部对齐。但它们应该满足所述要求这里。
简短的 MWE:
\documentclass[a4paper,11pt]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{blindtext}
% \usepackage{etoolbox}
% \usepackage{calc}
\usepackage{geometry}
\geometry{a4paper, top=10mm, left=33mm, right=46mm, bottom=46mm, headsep=\baselineskip,
marginparwidth=43mm, marginparsep=1em}
% ********************************************************************
% captions, taking use of the margins
% ********************************************************************
\usepackage{ragged2e}
\usepackage{sidenotes}
\DeclareCaptionStyle{stdstyle}{
format=hang, % caption hangs behind label
justification=justified,
labelsep=quad, % quad separator behind label
font=footnotesize % all in small font size
}
\DeclareCaptionJustification{outerragged}{\ifthispageodd{\RaggedRight}{\RaggedLeft}}
\DeclareCaptionStyle{sidestyle}{
format=plain, %indention=2em, % whole line for caption, with indent after first
justification=outerragged, % caption is a normal paragraph
labelsep=newline, % quad separator behind label
font=footnotesize % all in small font size
}
\DeclareCaptionStyle{sidecaption}{
style = sidestyle,
format=plain,
labelsep=newline
}
\usepackage[style = stdstyle]{caption}
\usepackage[
format=hang,
justification=raggedright
]{subcaption}
\begin{document}
\chapter{for the numbers}
\begin{figure}
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\columnwidth]{example-image-a}%
\caption{some text for a}
\label{fig:3:a}
\end{subfigure}%
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\columnwidth]{example-image-b}
\caption{some text for b}
\label{fig:3:b}
\end{subfigure}%
\sidecaption[LoF][-2em]{I want to be aligned at the top of the float
\label{fig:3}
}
\end{figure}
\end{document}
答案1
如果要将\sidecaption
与整个浮动对齐,只需将内容(除\sidecaption
)放入小页面,然后使用\raisebox
移动基线,
\strut
通过测量标题内部的高度获得了 7.69997pt 的值。
\documentclass[a4paper,11pt]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{blindtext}
% \usepackage{etoolbox}
% \usepackage{calc}
\usepackage{geometry}
\geometry{a4paper, top=10mm, left=33mm, right=46mm, bottom=46mm, headsep=\baselineskip,
marginparwidth=43mm, marginparsep=1em}
% ********************************************************************
% captions, taking use of the margins
% ********************************************************************
\usepackage{ragged2e}
\usepackage{sidenotes}
\DeclareCaptionStyle{stdstyle}{
format=hang, % caption hangs behind label
justification=justified,
labelsep=quad, % quad separator behind label
font=footnotesize % all in small font size
}
\DeclareCaptionJustification{outerragged}{\ifthispageodd{\RaggedRight}{\RaggedLeft}}
\DeclareCaptionStyle{sidestyle}{
format=plain, %indention=2em, % whole line for caption, with indent after first
justification=outerragged, % caption is a normal paragraph
labelsep=newline, % quad separator behind label
font=footnotesize % all in small font size
}
\DeclareCaptionStyle{sidecaption}{
style = sidestyle,
format=plain,
labelsep=newline
}
\usepackage[style = stdstyle]{caption}
\usepackage[
format=hang,
justification=raggedright
]{subcaption}
\begin{document}
\chapter{for the numbers}
\begin{figure}
\raisebox{\dimexpr 7.69997pt-\height}{\begin{minipage}{\textwidth}
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\columnwidth]{example-image-a}
\caption{some text for a}
\label{fig:3:a}
\end{subfigure}%
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\columnwidth]{example-image-b}
\caption{some text for b}
\label{fig:3:b}
\end{subfigure}%
\end{minipage}}\nobreak
\sidecaption[LoF][-2em]{I want to be aligned at the top of the float
\label{fig:3}
}
\end{figure}
\end{document}