# mdframed breaking pages in weird places

I defined a new environment which puts the frame title in the middle of the frame

\newenvironment{coloredframe}[2]{
\mdfsetup{
hidealllines=true,
leftline=true,topline=true,
frametitleaboveskip=-5pt,
linewidth=1.5pt,
frametitle={\colorbox{white}{\space#1\space}},
linecolor=#2
}
\begin{mdframed}
}{
\end{mdframed}
}


The thing is that it looks well, but sometimes it breaks pages in weird places, and if I remove the option frametitleaboveskip=-5pt it breaks pages where is expected.

What can I do to keep the frame title position but avoid the weird page breaks?

An example of the weird page breaking:

And how it looks without the frametitleaboveskip, good page breaks, bad location for the Diseño frame title:

EDIT: MWE

\documentclass[letterpaper, 12pt, oneside, spanish]{tesis}

\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{mdframed}
\usepackage{blindtext}

\newenvironment{coloredframe}[3][]{
\mdfsetup{
hidealllines=true,
leftline=true,topline=true,
frametitleaboveskip=-5pt,
frametitle={\colorbox{white}{\space#2\space}},
linecolor=#3,
#1
}
\begin{mdframed}
}{
\end{mdframed}
}

\newenvironment{investigationfr}[1][]
{\begin{coloredframe}[#1]{Investigación}{blue}}
{\end{coloredframe}}

\begin{document}

\section{Section}

\begin{investigationfr}
\blindtext\\
\blindtext\\
\blindtext\\
\blindtext\\
\end{investigationfr}

\end{document}

• Can you prepare a complete MWE? I cannot reproduce your problem. – Benjamin Feb 6 '16 at 20:55
• @Benjamin what is an MWE? – chamini2 Feb 6 '16 at 21:02
• MWE = minimal working example. A complete document we can copy&paste that demonstrates the problem. You can find more information how to produce a good MWE here: meta.tex.stackexchange.com/questions/228/… – Benjamin Feb 6 '16 at 21:05
• Use tcolorbox instead of mdframed. The "breakable" code in tcolorbox is much more reliable, with mdframed a small change can lead to unwanted breaks. – Ulrike Fischer Feb 6 '16 at 22:59
• @Benjamin, added the MWE. – chamini2 Feb 6 '16 at 23:13

I followed the advise to use tcolorbox and came up with this solution, it works flawlessly:

\tcbuselibrary{skins}
\tcbuselibrary{breakable}

\newtcolorbox{coloredframe}[3][]{
empty,
breakable=true,
sharp corners=all,
top=4mm, left=4mm,
borderline west={1.5pt}{0pt}{#3}, borderline north={1.5pt}{0pt}{#3},
attach boxed title to top left={yshift=-1.75ex,xshift=6ex},
coltitle=black,
colback=white, colbacktitle=white,
fonttitle=\bfseries,
boxed title style={boxrule=0pt,colframe=white},
title=#2,
#1
}


And use it like:

\begin{coloredframe}{Investigation}{blue}
% paragraph
\end{coloredframe}