3

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:

Weird page breaking


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

enter image description here


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}
6
  • Can you prepare a complete MWE? I cannot reproduce your problem.
    – Benjamin
    Feb 6, 2016 at 20:55
  • @Benjamin what is an MWE?
    – chamini2
    Feb 6, 2016 at 21:02
  • 1
    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, 2016 at 21:05
  • 2
    Use tcolorbox instead of mdframed. The "breakable" code in tcolorbox is much more reliable, with mdframed a small change can lead to unwanted breaks. Feb 6, 2016 at 22:59
  • @Benjamin, added the MWE.
    – chamini2
    Feb 6, 2016 at 23:13

1 Answer 1

0

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .