与 Tufte 类似的设计,带有跨分页符的旁注,或者:使用 KOMA-Script 制作的 Tufte

与 Tufte 类似的设计,带有跨分页符的旁注,或者:使用 KOMA-Script 制作的 Tufte

据我所知(如果我错了请纠正我),tufte 类的一个缺点是旁注不能跨越分页符。旁注必须在其开始的那一页结束。

我意识到 KOMA-Script 的最新版本包含一个包scrlayer-notecolumn,它解决了这个问题:我们可以独立于分页符添加旁注。

旁注甚至可以在浮点数内起作用,但旁注的编号是一个问题。

我们可以在页边空白处放置表格和图形,但是页边空白处的每个命令都需要一个\protect

问题:如何编写margintabular类似 tufte 类的环境?我们还需要做些什么来改进该scrlayer-notecolumn软件包中的 Tufte 样式文档?

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{scrlayer-scrpage, scrlayer-notecolumn, lmodern, blindtext,
ragged2e}

%% step 1: counter
\newcounter{snmark}
\setcounter{snmark}{0}


%% step 2: hanging sidenotes, definition from tugboat
\makeatletter
\newcommand*{\hangfrom}[1]{%
  \setbox\@tempboxa\hbox{{#1}}%
  \hangindent \wd\@tempboxa
  \noindent\box\@tempboxa}
\makeatletter

%% step 3: define sidenote marks in the text
\newcommand{\makesidenotemark}{%
  \textsuperscript{\thesnmark}
}%


%% step 4: and now the definition of sidenotes
\newcommand{\sidenote}[1]{%
  \refstepcounter{snmark}% Zähler erhöhen
  \makesidenotemark{}% Nummer im Text setzen.
  \makenote[paragraphs]{%
    \hangfrom{%
      \makebox[1em][l]{%
        \thesnmark}
            }
        \protect\RaggedRight{} #1}% Text setzen im Rand
}


%% this is, except for the values (».7«) from scrguide.pdf to define
%% the notecolumn.

\newlength{\paragraphscolwidth}
\AfterCalculatingTypearea{%
\setlength{\paragraphscolwidth}{.4\textwidth}%
\addtolength{\paragraphscolwidth}{-\marginparsep}%
}
\recalctypearea
\DeclareNewNoteColumn[%
position=\oddsidemargin+1in
+.7\textwidth
+\marginparsep,
width=\paragraphscolwidth,
font=\footnotesize
]{paragraphs}





%% Delete all sidenotes:
%\renewcommand{\sidenote}[1]{\relax}

\begin{document}
\begin{addmargin}[0pt]{.3\textwidth}
  This is the text with a \sidenote{See here.\blindtext}.
  \blindtext


  And here we have a second paragraph and a second
  sidenote\sidenote{\blindtext}.
  \blindtext

  And this is the big hit: We can have sidenotes which include
  pagebreaks!\sidenote{Proof of concept: \blindtext{}}


  \syncwithnotecolumns[paragraphs]

      And now we somewhere have a table:
  \begin{table}[b]
    \centering
    \begin{tabular}{ll}
      Proof\sidenote{From inside the float} & of concept\\
    \end{tabular}
    \caption{This is a table}
    \label{tab:table}
  \end{table}

Besides that, we even can have tabulars in the margin\sidenote{%
  Tabular in the margin:

  \protect\begin{tabular}{|l|l|}\protect\hline
    a& b\\\protect\hline
    a& b\\\protect\hline
    a& b\\\protect\hline
  \protect\end{tabular}
}, but they have
to be narrow and well protected.

\end{addmargin}


\end{document}

答案1

要在边注内添加表格,您可以创建一种非浮动表格环境,例如

\usepackage{environ}
\makeatletter
\NewEnviron{margintable}{%
  \expandafter\@margintable\expandafter{\BODY}%
}
\newcommand*\@margintable[1]{%
  \makenote[paragraphs]{%
    \protect\begin{nonfloattable}\detokenize{#1}\protect\end{nonfloattable}
  }%
}
\newenvironment{nonfloattable}{%
  \par\noindent\begin{minipage}{\linewidth}
    \def\@captype{table}%
}{%
  \end{minipage}\par
}

但有一个问题:似乎aux从注释中向文件写入标签不起作用,因此在环境\label{tab:secondtable}内部margintable不会产生标签。

奇怪:将标题写入aux文件确实有效。

我目前不知道为什么将标签写入文件aux不起作用,但将lot条目写入文件却起作用。不过,你可以在使用时(而不是在做笔记时)aux使用 hack 将标签信息写入-file:auxmargintable

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{scrlayer-scrpage, scrlayer-notecolumn, lmodern, blindtext,
ragged2e}

%% step 1: counter
\newcounter{snmark}
\setcounter{snmark}{0}


%% step 2: hanging sidenotes, definition from tugboat
\makeatletter
\newcommand*{\hangfrom}[1]{%
  \setbox\@tempboxa\hbox{{#1}}%
  \hangindent \wd\@tempboxa
  \noindent\box\@tempboxa}
\makeatletter

%% step 3: define sidenote marks in the text
\newcommand{\makesidenotemark}{%
  \textsuperscript{\thesnmark}
}%


%% step 4: and now the definition of sidenotes
\newcommand{\sidenote}[1]{%
  \refstepcounter{snmark}% Zähler erhöhen
  \makesidenotemark{}% Nummer im Text setzen.
  \makenote[paragraphs]{%
    \hangfrom{%
      \makebox[1em][l]{%
        \thesnmark}
            }
        \protect\RaggedRight{} #1}% Text setzen im Rand
}


%% this is, except for the values (».7«) from scrguide.pdf to define
%% the notecolumn.

\newlength{\paragraphscolwidth}
\AfterCalculatingTypearea{%
\setlength{\paragraphscolwidth}{.4\textwidth}%
\addtolength{\paragraphscolwidth}{-\marginparsep}%
}
\recalctypearea
\DeclareNewNoteColumn[%
position=\oddsidemargin+1in
+.7\textwidth
+\marginparsep,
width=\paragraphscolwidth,
font=\footnotesize
]{paragraphs}

\usepackage{environ}
\makeatletter
\NewEnviron{margintable}{%
  \expandafter\@margintable\expandafter{\BODY}%
}
\newcommand*\@margintable[1]{%
  \global\let\labeltoset\@empty
  \@tempcnta\value{table}%
  \begin{lrbox}{\@tempboxa}
    \begin{minipage}{\paragraphscolwidth}
      \def\label##1{%
        \xdef\labeltoset{%
          \labeltoset
          \noexpand\protected@write\noexpand\@auxout{}{%
            \noexpand\string\noexpand\newlabel{##1}{{\@currentlabel}{\thepage}}}%
        }%
      }%
      \def\@captype{table}%
      #1%
    \end{minipage}
  \end{lrbox}%
  \setcounter{table}{\@tempcnta}%
  \makenote[paragraphs]{%
    \protect\begin{nonfloattable}\detokenize{#1}\protect\end{nonfloattable}
  }%
  \labeltoset
}
\newenvironment{nonfloattable}{%
  \par\noindent\begin{minipage}{\linewidth}
    \def\@captype{table}%
}{%
  \end{minipage}\par
}

%% Delete all sidenotes:
%\renewcommand{\sidenote}[1]{\relax}

\begin{document}
\begin{addmargin}[0pt]{.3\textwidth}
  This is the text with a \sidenote{See here.\blindtext}.
  \blindtext


  And here we have a second paragraph and a second
  sidenote\sidenote{\blindtext}.
  \blindtext

  And this is the big hit: We can have sidenotes which include
  pagebreaks!\sidenote{Proof of concept: \blindtext{}}


  \syncwithnotecolumns[paragraphs]

      And now we somewhere have a table:
  \begin{table}[b]
    \centering
    \begin{tabular}{ll}
      Proof\sidenote{From inside the float} & of concept\\
    \end{tabular}
    \caption{This is a table}
    \label{tab:table}
  \end{table}

Besides that, we even can have tabulars in the margin\sidenote{%
  Tabular in the margin:

  \protect\begin{tabular}{|l|l|}\protect\hline
    a& b\\\protect\hline
    a& b\\\protect\hline
    a& b\\\protect\hline
  \protect\end{tabular}
}, but they have
to be narrow and well protected.

\begin{margintable}
  \centering
  \begin{tabular}{|l|l|}\hline
    a& b\\\hline
    a& b\\\hline
    a& b\\\hline
  \end{tabular}
  \caption{This is a second table}%
  \label{tab:secondtable}
\end{margintable}

See also table~\ref{tab:secondtable}.

\end{addmargin}

\listoftables

\end{document}

但请注意,还存在一个问题:如果注释移动到另一页,则标签的页码将是错误的。


更新:从scrlayer-notecolumn0.1.2583 开始KOMA 脚本 3.23.2583 \label在注释中确实按预期工作。有了新版本,\makenote*您不再需要所有这些\protect。因此,以下操作确实有效:

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{scrlayer-scrpage, scrlayer-notecolumn, lmodern, blindtext,
ragged2e}

%% step 1: counter
\newcounter{snmark}
\setcounter{snmark}{0}


%% step 2: hanging sidenotes, definition from tugboat
\makeatletter
\newcommand*{\hangfrom}[1]{%
  \setbox\@tempboxa\hbox{{#1}}%
  \hangindent \wd\@tempboxa
  \noindent\box\@tempboxa}
\makeatletter

%% step 3: define sidenote marks in the text
\newcommand{\makesidenotemark}{%
  \textsuperscript{\thesnmark}%
}%


%% step 4: and now the definition of sidenotes
\newcommand{\sidenote}[1]{%
  \refstepcounter{snmark}% Zähler erhöhen
  \makesidenotemark{}% Nummer im Text setzen.
  \makenote[paragraphs]{%
    \hangfrom{%
      \makebox[1em][l]{%
        \thesnmark}%
    }%
    \protect\RaggedRight\detokenize{#1}}% Text setzen im Rand
}


%% this is, except for the values (».7«) from scrguide.pdf to define
%% the notecolumn.

\newlength{\paragraphscolwidth}
\AfterCalculatingTypearea{%
\setlength{\paragraphscolwidth}{.4\textwidth}%
\addtolength{\paragraphscolwidth}{-\marginparsep}%
}
\recalctypearea
\DeclareNewNoteColumn[%
position=\oddsidemargin+1in
+.7\textwidth
+\marginparsep,
width=\paragraphscolwidth,
font=\footnotesize
]{paragraphs}

\usepackage{environ}
\makeatletter
\NewEnviron{margintable}{%
  \expandafter\@margintable\expandafter{\BODY}%
}
\newcommand*\@margintable[1]{%
  \makenote*[paragraphs]{%
    \begin{nonfloattable}#1\end{nonfloattable}%
  }%
}
\newenvironment{nonfloattable}{%
  \par\noindent\begin{minipage}{\linewidth}
    \def\@captype{table}%
}{%
  \end{minipage}\par
}
\usepackage{makeidx}

%% Delete all sidenotes:
%\renewcommand{\sidenote}[1]{\relax}

\begin{document}
\begin{addmargin}[0pt]{.3\textwidth}
  This is the text with a sidenote\sidenote{See here.\blindtext}.
  \blindtext


  And here we have a second paragraph and a second
  sidenote\sidenote{\blindtext}.
  \blindtext

  And this is the big hit: We can have sidenotes which include
  pagebreaks!\sidenote{Proof of concept: \blindtext{}}


  \syncwithnotecolumns[paragraphs]

      And now we somewhere have a table:
  \begin{table}[b]
    \centering
    \begin{tabular}{ll}
      Proof\sidenote{From inside the float} & of concept\\
    \end{tabular}
    \caption{This is a table}
    \label{tab:table}
  \end{table}

Besides that, we even can have tabulars in the margin\sidenote{%
  Tabular in the margin:

  \begin{tabular}{|l|l|}\hline
    a& b\\\hline
    a& b\\\hline
    a& b\\\hline
  \end{tabular}%
}, but they have
to be narrow and well protected.

\begin{margintable}
  \centering
  \begin{tabular}{|l|l|}\hline
    a& b\\\hline
    a& b\\\hline
    a& b\\\hline
  \end{tabular}
  \caption{This is a second table}%
  \label{tab:secondtable}
\end{margintable}

See also table~\ref{tab:secondtable}.
\listoftables

\end{addmargin}


\end{document}

因为\sidenote不能使用\makenote*,所以\thesnmark需要立即展开。但是你可以使用你自己\detokenize的技巧,\makenote*如上例所示。

顺便说一句:在上面的代码中我已经修复了几个空格错误。

相关内容