tufte-book 类中新浮动标题的放置

tufte-book 类中新浮动标题的放置

我正在使用tufte-book文档类,并尝试创建一个新的浮动环境,例如将在右边距包含类似于表格/图形标题的标题的框。

但是,当我创建新的浮动环境时,标题会出现在左侧浮动的上方。

MWE 包括如下:

\documentclass{tufte-book}
\usepackage{newfloat}
\usepackage{framed, color}
\usepackage{lipsum}

\DeclareFloatingEnvironment[name=Example]{example}

\begin{document}

\begin{example}
\caption{Currently, this caption is left justified above the float, when I would like it to be in the right margin similar to the table caption below.}
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\begin{shaded}
\lipsum[2]
\end{shaded}
\end{example}

\begin{table}
\caption{This is how I want the new float environment caption to behave.}
\centering
\begin{tabular}{llr}
Column 1 & Column 2 & Column 3 \\
Value A1 & Value A2 & Value A3 \\
\end{tabular}
\end{table}

\end{document}

答案1

除了使用newfloat包之外,您还可以使用与类类似的方式创建示例浮动对象tufte;这样您就可以自动继承所需的格式。在下面的例子中,我example使用“方式”从头定义了浮动对象tufte;代码遵循和tufte的定义,可以在文件中找到:我还为可能的做了必要的准备:figuretabletufte-common.def\listofexamples

\documentclass{tufte-book}
\usepackage{framed, color}
\usepackage{lipsum}

\newcounter{example}[chapter]
\newcommand\examplename{Example}
\newcommand\listexamplename{List of Examples}
\makeatletter
\newcommand\listofexamples{%
  \ifthenelse{\equal{\@tufte@class}{book}}%
    {\chapter*{\listexamplename}}%
    {\section*{\listexamplename}}%
%  \begin{fullwidth}%
    \@starttoc{loe}%
%  \end{fullwidth}%
}
\renewcommand\theexample
     {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@example}
\def\fps@example{tbp}
\def\ftype@example{1}
\def\ext@example{loe}
\def\fnum@example{\examplename\nobreakspace\theexample}
\newenvironment{example}[1][htbp]
  {\begin{@tufte@float}[#1]{example}{}}
  {\end{@tufte@float}}
\let\l@example\l@figure
\makeatother

\begin{document}

\begin{example}
\caption{Currently, this caption is in the right margin similar to the table caption below.}
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\begin{shaded}
\lipsum[2]
\end{shaded}
\end{example}

\begin{table}
\caption{This is how I want the new float environment caption to behave.}
\centering
\begin{tabular}{llr}
Column 1 & Column 2 & Column 3 \\
Value A1 & Value A2 & Value A3 \\
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

如果你希望所有example环境都带有彩色背景,则可以在 的定义中直接包含颜色环境example。以下示例说明了这一点,但使用mdframed环境(来自mdframed包)而不是shaded(来自framed包);这可以使对象和标题之间有更好的垂直对齐(与上面的例子比较):

\documentclass{tufte-book}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{lipsum}

\definecolor{shadecolor}{rgb}{1,0.8,0.3}

\newcounter{example}[chapter]
\newcommand\examplename{Example}
\newcommand\listexamplename{List of Examples}
\makeatletter
\newcommand\listofexamples{%
  \ifthenelse{\equal{\@tufte@class}{book}}%
    {\chapter*{\listexamplename}}%
    {\section*{\listexamplename}}%
%  \begin{fullwidth}%
    \@starttoc{loe}%
%  \end{fullwidth}%
}
\renewcommand\theexample
     {\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@example}
\def\fps@example{tbp}
\def\ftype@example{1}
\def\ext@example{loe}
\def\fnum@example{\examplename\nobreakspace\theexample}
\newenvironment{example}[1][htbp]
  {\begin{@tufte@float}[#1]{example}{}
    \begin{mdframed}[backgroundcolor=shadecolor,hidealllines=true]}
  {\end{mdframed}\end{@tufte@float}}
\makeatother

\begin{document}

\begin{example}
\caption{Currently, this caption is in the right margin similar to the table caption below.}
\lipsum[2]
\end{example}

\begin{table}
\caption{This is how I want the new float environment caption to behave.}
\centering
\begin{tabular}{llr}
Column 1 & Column 2 & Column 3 \\
Value A1 & Value A2 & Value A3 \\
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

相关内容