使用 tikz 和 framed 将“连续”文本添加到框架段落

使用 tikz 和 framed 将“连续”文本添加到框架段落

我尝试改编以下示例: http://www.texample.net/tikz/examples/framed-tikz/

到目前为止,我已经成功更改了配色方案,并用简单的圆角边框替换了不规则的边缘。我想要实现的最后一个更改是让框的标题在框继续进入下一页时再次出现,并带有后缀“继续”。

该示例根据框的位置应用了不同的样式,并希望对标题使用相同的方法,但我在将标题添加到宏时遇到了困难。以下是我目前所拥有的:

% Nice shaded/framed paragraphs using tikz and framed
% Author: Jose Luis Diaz
\documentclass[a5paper]{article}
\usepackage{lipsum}   % To generate test text 
\usepackage{framed}
\usepackage{tikz}
\usetikzlibrary{shapes}
\pgfmathsetseed{1} % To have predictable results
% Define a background layer, in which the parchment shape is drawn
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

% Define Colour Styles
\definecolor{Border}{HTML}{204C82}
\definecolor{Background}{HTML}{D2DBE6}

% define styles for the normal border and the torn border
\tikzset{
    mybox/.style={
        draw=Border,
        fill=Background,
        very thick,
        rectangle,
        rounded corners,
        inner sep=10pt,
        inner ysep=20pt
    },
    fancytitle/.style={
        draw=Border,
        fill=Background,
        rounded corners
    }
}

% Macro to draw the shape behind the text, when it fits completly in the
% page
\def\parchmentframe#1{
\tikz{
  \node[inner sep=2em] (A) {#1};  % Draw the text of the node
  \begin{pgfonlayer}{background}  % Draw the shape behind
  \fill[mybox] 
        (A.south east) -- (A.south west) -- 
        (A.north west) -- (A.north east) -- cycle;
  \end{pgfonlayer}}}

% Macro to draw the shape, when the text will continue in next page
\def\parchmentframetop#1{
\tikz{
  \node[inner sep=2em] (A) {#1};    % Draw the text of the node
  \begin{pgfonlayer}{background}    
  \fill[mybox]              % Draw the ``complete shape'' behind
        (A.south east) -- (A.south west) -- 
        (A.north west) -- (A.north east) -- cycle;
  \end{pgfonlayer}}}

% Macro to draw the shape, when the text continues from previous page
\def\parchmentframebottom#1{
\tikz{
  \node[inner sep=2em] (A) {#1};   % Draw the text of the node
  \begin{pgfonlayer}{background}   
  \fill[mybox]             % Draw the ``complete shape'' behind
        (A.south east) -- (A.south west) -- 
        (A.north west) -- (A.north east) -- cycle;
  \end{pgfonlayer}}}

% Macro to draw the shape, when both the text continues from previous page
% and it will continue in next page
\def\parchmentframemiddle#1{
\tikz{
  \node[inner sep=2em] (A) {#1};   % Draw the text of the node
  \begin{pgfonlayer}{background}   
  \fill[mybox]             % Draw the ``complete shape'' behind
        (A.south east) -- (A.south west) -- 
        (A.north west) -- (A.north east) -- cycle;
  \end{pgfonlayer}}}

% Define the environment which puts the frame
% In this case, the environment also accepts an argument with an optional
% title (which defaults to ``Example'', which is typeset in a box overlaid
% on the top border
\newenvironment{parchment}[1][Example]{%
  \def\FrameCommand{\parchmentframe}%
  \def\FirstFrameCommand{\parchmentframetop}%
  \def\LastFrameCommand{\parchmentframebottom}%
  \def\MidFrameCommand{\parchmentframemiddle}%
  \vskip\baselineskip
  \MakeFramed {\FrameRestore}
  % Looks like I need to remove this and place it within a macro above somehow
  \noindent\tikz\node[fancytitle, inner sep=1ex, right=10pt, anchor=west, overlay] at (0em, 2em) {#1};\par% 
}
{\endMakeFramed}

% Main document, example of usage
\pagestyle{empty}
\begin{document}
\begin{parchment}[Short text]
  \lipsum[11]
\end{parchment}
\lipsum[11]
\begin{parchment}[Long text spanning over pages]
\lipsum[11]
  \begin{itemize}
    \item \lipsum[14]
  \end{itemize}
\lipsum
\end{parchment}
\end{document}

答案1

我建议不要framed使用tcolorbox或者mdframed制作框架和易碎的盒子。您的示例tcolorbox可以适应以下情况:

\documentclass[a5paper]{article}
\usepackage{lipsum}   % To generate test text 
\usepackage[breakable,skins]{tcolorbox}

% Define Colour Styles
\definecolor{Border}{HTML}{204C82}
\definecolor{Background}{HTML}{D2DBE6}

\newtcolorbox{parchment}[2][]{%
    breakable,
    enhanced,
    colback=Background,
    colframe=Border,
    top=4mm,
    enlarge top by=\baselineskip/2+1mm,
    pad at break=\baselineskip,
    fontupper=\normalsize,
    overlay unbroken and first={%
        \node[rectangle, rounded corners, 
              draw=Border, fill=Background,
             inner sep=1mm, anchor=west, font=\small]
       at ([xshift=4.5mm]frame.north west) {\strut\textbf{#2}};},
    overlay middle and last={%
       \node[rectangle, rounded corners, 
             draw=Border, fill=Background,
             inner sep=1mm, anchor=west, font=\small]
       at ([xshift=4.5mm]frame.north west)
          {\strut\textbf{Continue from previous page}};},
#1}%

\begin{document}
\begin{parchment}{Short text}
  \lipsum[11]
\end{parchment}
\lipsum[11]
\begin{parchment}{Long text spanning over pages}
\lipsum[11]
  \begin{itemize}
    \item \lipsum[14]
  \end{itemize}
\lipsum
\end{parchment}
\end{document}

在此处输入图片描述

相关内容