使用 parcolumns 打破 tcolorboxes

使用 parcolumns 打破 tcolorboxes

我尝试延长这个班带有易碎的 tcolorboxes。出于某种原因,这根本不起作用。

这是我标记更改的 .cls 文件:

\ProvidesClass{cornell}
\LoadClass[a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins,xparse}
\usepackage{parcolumns} % Used to create two columns
\usepackage{bookmark} % Add bookmarks to the resulting PDF
\usepackage[margin=2cm]{geometry} % Change geometry of pages
\usepackage{hyperref} % Default hyperref setup
\hypersetup{
    colorlinks   = true, % Colour links instead of ugly boxes
    urlcolor     = blue, % Colour for external hyperlinks
    linkcolor    = blue, % Colour of internal links
    citecolor    = red   % Colour of citations
}

\date{}

\renewcommand{\maketitle}{%
    \vspace{-3em}
    \pdfbookmark[0]{\@title}{title}
    \begin{tcolorbox}[width=\textwidth,lowerbox=invisible]
        \Huge\sffamily \@title
    \end{tcolorbox}
    \vspace{2em}
}

\DeclareDocumentCommand\preread{ m m }
{
    \pdfbookmark[1]{Introduction}{intro}
    \begin{tcolorbox}[width=\textwidth]
        #1
        \tcblower
        #2
    \end{tcolorbox}
}

\DeclareDocumentCommand\note{ o m }
{
    \IfNoValueT{#1} {
        \vspace{-1.5em}
    }{}
    \begin{parcolumns}[colwidths={1=.33\textwidth},nofirstindent]{2}
        \colchunk{
            \IfNoValueF{#1} {
                \pdfbookmark[1]{#1}{note}
                \begin{tcolorbox}[lowerbox=invisible,box align=top]
                    #1
                \end{tcolorbox}
            }{}
        }
        \colchunk{
            \begin{tcolorbox}[enhanced,lowerbox=invisible,box align=top,breakable] % <<< HERE I ADDED BREAKABLE
                #2
            \end{tcolorbox}
        }
    \end{parcolumns}
}
\DeclareDocumentCommand\summary{ m }
{
    \vfill
    \pdfbookmark[1]{Summary}{summary}
    \begin{tcolorbox}[
        enhanced,
        floatplacement=!b,
        float,
        colframe=black,
        colupper=black,
        opacitybacktitle=1,
        opacitytext=1,
        segmentation style={black!55,solid,opacity=0,line width=3pt},
        title=Summary,
        fonttitle=\large\bfseries\sffamily]
        #1
    \end{tcolorbox}
}

以下是示例文件:

\documentclass{cornell}

\usepackage{lipsum}

\title{A topic we're taking notes on}

\begin{document}
\maketitle

\preread
    {Questions}
    {
        \begin{enumerate}
            \item{What's the first question this section will answer?}
            \item{What's the second question?}
        \end{enumerate}
    }

\note[Some key term]
{
    \begin{itemize}
        \item{A cool thing}
        \item{Another cool thing}
        \item{Not all things are cool}
    \end{itemize}
}

\note[Another term]
{
    \lipsum[4]
}
\note{\lipsum[5]}
\note{\lipsum[6-7]}

\summary{A fabulous summary.}

\note{\lipsum[6]}
\note{\lipsum[9-12]}
\note{\lipsum[10-20]}

\end{document}

当编译这个时,结果确实很尴尬。

这两页之间应该有一个分界:

无跨页

以下是单个页面内的实际分隔符:

同一页内有分页符

有谁知道如何解决这个问题?

答案1

我建议用into替换parcolumns包。paracolcornell.cls

可能您需要进行一些调整,但以下代码对我有用:

\ProvidesClass{cornell}
\LoadClass[a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins,xparse}
\usepackage{paracol} % Used to create two columns
\usepackage{bookmark} % Add bookmarks to the resulting PDF
\usepackage[margin=2cm]{geometry} % Change geometry of pages
\usepackage{hyperref} % Default hyperref setup
\hypersetup{
    colorlinks   = true, % Colour links instead of ugly boxes
    urlcolor     = blue, % Colour for external hyperlinks
    linkcolor    = blue, % Colour of internal links
    citecolor    = red   % Colour of citations
}

\date{}

\renewcommand{\maketitle}{%
    \vspace{-3em}
    \pdfbookmark[0]{\@title}{title}
    \begin{tcolorbox}[width=\textwidth,lowerbox=invisible]
        \Huge\sffamily \@title
    \end{tcolorbox}
    \vspace{2em}
}

\DeclareDocumentCommand\preread{ m m }
{
    \pdfbookmark[1]{Introduction}{intro}
    \begin{tcolorbox}[width=\textwidth]
        #1
        \tcblower
        #2
    \end{tcolorbox}
}

\DeclareDocumentCommand\note{ o m }
{
% The original `cornell.cls` has these lines uncommented. They cut the
% space between fragments (`notes`).
%    \IfNoValueT{#1} {
%        \vspace{-1.5em}
%    }{}
    \columnratio{.33}
    \begin{paracol}{2}
        \begin{leftcolumn}
            \IfNoValueF{#1} {
                \pdfbookmark[1]{#1}{note}
                \begin{tcolorbox}[lowerbox=invisible,box align=top]
                    #1
                \end{tcolorbox}
            }{}
        \end{leftcolumn}
        \begin{rightcolumn}
            \begin{tcolorbox}[enhanced,lowerbox=invisible,box align=top,breakable] % <<< HERE I ADDED BREAKABLE
                #2
            \end{tcolorbox}
        \end{rightcolumn}
    \end{paracol}
}
\DeclareDocumentCommand\summary{ m }
{
    \vfill
    \pdfbookmark[1]{Summary}{summary}
    \begin{tcolorbox}[
        enhanced,
        floatplacement=!b,
        float,
        colframe=black,
        colupper=black,
        opacitybacktitle=1,
        opacitytext=1,
        segmentation style={black!55,solid,opacity=0,line width=3pt},
        title=Summary,
        fonttitle=\large\bfseries\sffamily]
        #1
    \end{tcolorbox}
}

与上一节课一样,结果如下:

在此处输入图片描述

第二种解决方案

如果所有左列盒子都像标签或只有几个字,那么也可以忘记包装paracol,只使用易碎且狭窄的盒子,tcolorbox并在左侧附上另一个盒子。

note命令可以是:

\DeclareDocumentCommand\note{ o m }
{
%    \IfNoValueT{#1} {
%        \vspace{-1.5em}
%    }{}
    \begin{tcolorbox}[enhanced, breakable,
        enlarge left by=.34\textwidth, width=.66\textwidth,
        overlay={
            \IfNoValueF{#1} {
                \pdfbookmark[1]{#1}{note}
                \node[anchor=north west, outer sep=0pt, inner sep=0pt] at ([xshift=-.34\textwidth]frame.north west) {\begin{tcolorbox}[width=.325\textwidth]#1\end{tcolorbox}};
            }{}
        }
        ]
    #2
    \end{tcolorbox}
}

需要对盒子尺寸和盒子间空间进行一些调整,但结果非常相似:

在此处输入图片描述

相关内容