2

I trying to adapt the following example: http://www.texample.net/tikz/examples/framed-tikz/

So far I have managed to change the colour scheme and replace the irregular edges with a simple rounded corner border. The final change I am wanting to achieve is to get the title of the box to appear again with the suffix "continued" when the box continues into the next page.

The example applies different styles depending how the box is situated and was hoping to use that same method for the titles but I am having difficulty adding the titles to the macros. Here is what I have so far:

% 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}
4

Instead of framed I'd suggest to use tcolorbox or mdframed to produced framed and breakable boxes. Your example adapted to tcolorbox could be:

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.