tufte-latex 和 subcaption

tufte-latex 和 subcaption

我尝试使用tufte-latexsubcaptions但似乎总体上存在问题。然而,提到的包兼容模式的解决方法caption仅部分有效:

\documentclass[a4paper, titlepage, twoside, symmetric, justified, nobib]{tufte-book}
\usepackage[utf8x]{inputenc}

% doing this at least the labels are there, but
%   - the caption is bigger
%   - referencing the labels doesn't work
\usepackage{subcaption}
\captionsetup{compatibility=false}

% instead, only to compile without errors
%\newcommand{\subcaption}[1]{}%

\usepackage[]{graphicx}
\usepackage{adjustbox}
\usepackage{lipsum}

\begin{document}

\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image-a}
  \caption{Just a single image}
\label{fig:singleimage}
\end{figure}

% for comparison of font size
\lipsum[1]\footnote[][-20pt]{Note that the figure caption is larger than this
text when \textsf{captionsetup: compatibility=false}}

\begin{figure}[htb]
  \centering
    \adjustbox{minipage=1.5em,raise=-\height}{\subcaption{}\label{fig:smalla}}%
    \raisebox{-\height}{%
  \includegraphics[width=0.4\textwidth]{example-image-a}
    }
    \adjustbox{minipage=1.5em,raise=-\height}{\subcaption{}\label{fig:smallb}}%
    \raisebox{-\height}{%
  \includegraphics[width=0.4\textwidth]{example-image-b}
    }
    \caption{Two images ---- fig.~\ref{fig:smalla} shows an "A",
      fig.~\ref{fig:smallb} shows a "B".
    }
\label{fig:twoimages}
\end{figure}
Outside referencing isn't different:
In fig.~\ref{fig:twoimages}:
Two images --- fig.~\ref{fig:smalla} shows an "A",
fig.~\ref{fig:smallb} shows a "B".

\end{document}

上述代码片段的输出

部分工作

注释掉第一部分,注释掉第二部分——只是为了编译时不出错。现在标题的大小正确了。

没有任何副标题

答案1

由于兼容性问题,我\subcaption用自己的版本替换了它。这个版本不必放在小页面中。另一方面,这些子标题不能显示在\listoffigures(通常它们不会显示)。

我还\label用替换了\normallabel子标题,但继续使用\label来显示图片标题。我不知道 tufte-book 做了什么\label,也不知道为什么。

最后,我在标题中替换了\ref\hypergetref标题被写入 aux 和 lof 文件中,\ref无法很好地处理扩展。

\documentclass[a4paper, titlepage, twoside, symmetric, justified, nobib]{tufte-book}
\usepackage[utf8x]{inputenc}

% doing this at least the labels are there, but
%   - the caption is bigger
%   - referencing the labels doesn't work

\usepackage[]{graphicx}
\usepackage{adjustbox}
\usepackage{lipsum}

\newcounter{subfigure}[figure]
\renewcommand{\thesubfigure}{\alph{subfigure}}
\newcounter{subtable}[table]
\renewcommand{\thesubtable}{\alph{subtable}}

\makeatletter
\newcommand{\subcaption}{\edef\sub@captype{sub\@captype}%
  \refstepcounter{\sub@captype}%
  (\csname the\sub@captype\endcsname)~}
\makeatother

\AtBeginDocument{\let\normallabel=\label}% must be after hyperef

\begin{document}
\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image-a}
  \caption{Just a single image}
\label{fig:singleimage}
\end{figure}

% for comparison of font size
\lipsum[1]\footnote[][-20pt]{Note that the figure caption is larger than this
text when \textsf{captionsetup: compatibility=false}}

\begin{figure}[htb]
  \centering
    \raisebox{-\height}{\subcaption{}\normallabel{fig:smalla}}%
    \raisebox{-\height}{\includegraphics[width=0.4\textwidth]{example-image-a}
    }
    \raisebox{-\height}{\subcaption{}\normallabel{fig:smallb}}%
    \raisebox{-\height}{\includegraphics[width=0.4\textwidth]{example-image-b}
    }
    \caption{Two images ---- fig.~\hypergetref{fig:smalla} shows an "A",
      fig.~\hypergetref{fig:smallb} shows a "B".
    }
\label{fig:twoimages}
\end{figure}
Outside referencing isn't different:
In fig.~\ref{fig:twoimages}:
Two images --- fig.~\ref{fig:smalla} shows an "A",
fig.~\ref{fig:smallb} shows a "B".

\end{document}

答案2

该包captionsubcaption不兼容tufte-book

不过,您可以使用subfig

\documentclass[a4paper, titlepage, twoside, symmetric, justified, nobib]{tufte-book}
\usepackage[utf8]{inputenc}

\usepackage[caption=false]{subfig}

\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{lipsum}

\begin{document}

\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image-a}
  \caption{Just a single image}
\label{fig:singleimage}
\end{figure}

% for comparison of font size
\lipsum*[1]

\begin{figure}[htb]
\centering
\captionsetup{captionskip=0pt,farskip=0pt,nearskip=0pt}

\vspace*{-\abovecaptionskip}

\subfloat[\label{fig:smalla}]{\qquad}
\includegraphics[width=0.4\textwidth,valign=T]{example-image-a}\hfil
\subfloat[\label{fig:smallb}]{\qquad}
\includegraphics[width=0.4\textwidth,valign=T]{example-image-b}

\caption{Two images ---- fig.~\protect\subref{fig:smalla} shows an "A",
      fig.~\protect\subref{fig:smallb} shows a "B".}
\label{fig:twoimages}

\vspace{\abovecaptionskip}
\end{figure}

Outside referencing isn't different:
In fig.~\ref{fig:twoimages}:
Two images --- fig.~\subref{fig:smalla} shows an "A",
fig.~\subref{fig:smallb} shows a "B".

\end{document}

请注意,\subref应该使用 来引用子浮点数,并且在移动参数中应该以\protectif 为前缀,例如 在 中\caption

在此处输入图片描述

答案3

这是一些肮脏的黑客行为,并使用了过时的subfigure软件包:

\documentclass[a4paper, titlepage, twoside, symmetric, justified, nobib]{tufte-book}
\usepackage[utf8x]{inputenc}

\usepackage[FIGTOPCAP,nooneline]{subfigure}
\subfigcaptopadj = -12pt
\subfigcapmargin = -12pt

\usepackage[]{graphicx}
\usepackage{adjustbox}
\usepackage{lipsum}

\begin{document}

\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image-a}
  \caption{Just a single image}
\label{fig:singleimage}
\end{figure}

% for comparison of font size
\lipsum[1]\footnote[][-20pt]{Note that the figure caption is larger than this
text when \textsf{captionsetup: compatibility=false}}

\begin{figure}[htb]
  \vspace{-12pt}
  \centering
  \subfigure[]{%
  \includegraphics[width=0.4\textwidth]{example-image-a}
  \label{fig:smalla}
    }
  \qquad
  \subfigure[]{%
  \includegraphics[width=0.4\textwidth]{example-image-a}
  \label{fig:smallb}
    }
  \caption{Two images --- fig.~\ref{fig:smalla} shows an "A",
    fig.~\ref{fig:smallb} shows a "B".
    }
\label{fig:twoimages}
\end{figure}
Outside referencing isn't different:
In fig.~\ref{fig:twoimages}:
Two images --- fig.~\ref{fig:smalla} shows an "A",
fig.~\ref{fig:smallb} shows a "B".

\end{document}

呈现为: 使用 subfigure 进行肮脏黑客攻击

我愿意接受任何更好的解决方案,特别是因为引用整个图形不再起作用并且枚举似乎被破坏了。

编辑:是的,A /= B ...

相关内容