# Dashed border only at a corner with tcolorbox

I wonder if it is possible to create a box with tcolorbox whose border is like the following (i.e. a continuous border with a dashed segment at a specific point):

The dashed part should be either at the upper left corner of the box (to indicate that the content is the continuation of a previous box) or at the bottom right corner (to indicate it continues in the next box/page).

\documentclass{article}
\usepackage[skins]{tcolorbox}
\usetikzlibrary{calc}
\newtcolorbox{contbox1}{enhanced,colback=white,frame code={%
\draw[dashed,line width=1pt,gray!50] (frame.south east) --
($(frame.south east)!0.3!(frame.south west)$);
\draw[line width=1pt,gray!50]  ($(frame.south east)!0.3!(frame.south west)$)
-| (frame.north west) -| (frame.south east) ;
}}
\newtcolorbox{contbox2}{enhanced,colback=white,frame code={%
\draw[dashed,line width=1pt,gray!50] (frame.north west) --
($(frame.north west)!0.3!(frame.north east)$);
\draw[line width=1pt,gray!50]  ($(frame.north west)!0.3!(frame.north east)$)
-| (frame.south east) -| (frame.north west);
}}
\begin{document}
\begin{contbox1}
Some text.
\end{contbox1}
\begin{contbox2}
Some more text.
\end{contbox2}
\end{document}


Following code introduces some changes to user237299 solution.

1. Only one breakable tcolorbox is declared.
2. Dashed fragment is changed to draw correct corner joins.

The use of subskins is based in this example in tcolorbox documentation.

\documentclass{article}
\usepackage[skins, breakable]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{contbox}[1][]{empty,
breakable, colback=white,
%code for unbroken boxes
frame code={\draw[line width=1pt, gray!50] (frame.south east) rectangle (frame.north west);},
%code for first part of broken box
skin first is subskin of={empty}{%
frame code={\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)-|(frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
},
%code for middle part of broken box
skin middle is subskin of={empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
},
%code for last part of broken box
skin last is subskin of={empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)-|(frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);
},
},
#1
}

\begin{document}
\begin{contbox}
\lipsum[1-12]
\end{contbox}
\end{document}


Update: subskin selection

If you need to force a certain aspect on a box with independence of which part of a breakable box is, following code will do it.

It defines three subskins and the optional argument allows to select which one to apply. By default the "normal" behaviour in breakable boxes is applied.

\documentclass{article}
\usepackage[skins, breakable]{tcolorbox}
\usepackage{lipsum}

\tcbsubskin{myfirst}{empty}{%
frame code={\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)-|(frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
}
\tcbsubskin{mymiddle}{empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
}
\tcbsubskin{mylast}{empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)-|(frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);},
}

\newtcolorbox{contbox}[1][]{empty,
breakable, colback=white,
%code for unbroken boxes
frame code={\draw[line width=1pt, gray!50] (frame.south east) rectangle (frame.north west);},
%skins for breakable boxes
skin first=myfirst,
skin middle=mymiddle,
skin last=mylast,
#1
}

\begin{document}
\begin{contbox}[skin=mylast]
\lipsum[2]
\end{contbox}
\begin{contbox}[skin=mymiddle]
\lipsum[2]
\end{contbox}
\begin{contbox}[skin=myfirst]
\lipsum[2]
\end{contbox}
\end{document}


Second Update: using magazine library

As it seems that OP wants to place box fragments into float environments, it's possible to use magazine library to break the box where we need it and select the corresponding aspect (first, middle, last) automatically.

Following example breaks the box in fragments of 3cm and each fragment is placed into a figure environment. As can be seen, every fragment shows the aspect corresponding to a broken box.

\documentclass{article}
\usepackage[skins, breakable, magazine]{tcolorbox}
\usepackage{lipsum}

\tcbsubskin{myfirst}{empty}{%
frame code={\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)-|(frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
}
\tcbsubskin{mymiddle}{empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.south)-| (frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)--++(180:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.south);},
}
\tcbsubskin{mylast}{empty}{%
frame code={%
\draw[line width=1pt, gray!50] (frame.north)-| (frame.south east)-|(frame.north west)--++(0:2pt) coordinate (aux); \draw[dashed, line width=1pt, gray!50](aux)--(frame.north);},
}

\newtcolorbox{contbox}[1][]{empty,
breakable, colback=white,
%code for unbroken boxes
frame code={\draw[line width=1pt, gray!50] (frame.south east) rectangle (frame.north west);},
%skins for breakable boxes
skin first=myfirst,
skin middle=mymiddle,
skin last=mylast,
reset box array,
store to box array,
#1
}

\begin{document}
\begin{contbox}[break at=3cm]
\lipsum[1-5]
\end{contbox}
\boxarraygetsize{\myfragments}

\begin{figure}
\centering
\consumeboxarray{1}
\caption{First fragment}
\end{figure}

\begin{figure}
\centering
\consumeboxarray{\myfragments}
\caption{Last fragment}
\end{figure}

\begin{figure}
\centering
\consumeboxarray{5}
\caption{One middle fragment}
\end{figure}
\end{document}


• Great. However, I think this solution is not suitable for floats, or is it? I need a floating box, so I think the only solution is to break it and mark its continuation "by hand" Mar 17 at 8:08
• @Massimo I don't understand why you want breakable boxes into a floating environment, but the updated answer can help you. By the way, if you want to break a box and select where to put every fragment, you could use magazine library and forget having to manually select the aspect of every fragment. Mar 17 at 10:41
• The reason is that I want the box to be split in a specific point, so I cannot leave the decision on the page break to LaTeX. I use this solution when I have a box larger than a full page, so first I put a full page box, with the text continuing in a smaller box in the next page; but both of them must float. If you have a better solution, I welcome it (I will check magazine). Mar 18 at 15:14
• Another question about your solution: I see that every subskin redraws the entire frame. I guess that it is not possible to redraw just a part of the frame, e.g. the lower or upper border. In this sense, does it make a difference that the frame is defined as a subskin rather than a full skin (or a style)? Mar 18 at 15:27
• @Massimo If you use the magazine solution, don't have to worry about subskins, because the box will break automatically and the aspect according the fragment. Initially I understood that you wanted to select the style for every box. In this case you can declare several newtcolorboxes with different styles or only one box where you can select the style with a parameter. In any case i didn't know about \tcbsubskin until I tried to answer your question. Mar 18 at 19:02