1

I would like to know how to keep a whole framed box on the same page. I am finishing a manuscript and I am quite afraid to move the text before/after to check this.

I take this example, from here.

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\mdfdefinestyle{MyFrame}{%
    linecolor=blue,
    outerlinewidth=2pt,
    roundcorner=20pt,
    innertopmargin=\baselineskip,
    innerbottommargin=\baselineskip,
    innerrightmargin=20pt,
    innerleftmargin=20pt,
    backgroundcolor=gray!50!white}

\begin{document}

\begin{mdframed}[style=MyFrame]
\lipsum[1]
\begin{equation}
 f(x) = \sin(x)
\end{equation}
\lipsum[2]
\end{mdframed}
\end{document}

I know that in the figures, you can put a "H", like this:

\begin{figure}[H]
    \centering
    \includegraphics[width=0.8\linewidth]{image}
    \caption{This is the caption.}
    \label{fig:label_image}
\end{figure}

Is it possible to do so with framed box ? And/or fix at the page number 2 ?

1

Just put in inside a parbox:

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\mdfdefinestyle{MyFrame}{%
    linecolor=blue,
    outerlinewidth=2pt,
    roundcorner=20pt,
    innertopmargin=\baselineskip,
    innerbottommargin=\baselineskip,
    innerrightmargin=20pt,
    innerleftmargin=20pt,
    backgroundcolor=gray!50!white}

\begin{document}
\lipsum[1-3]
\parbox{\textwidth}{\begin{mdframed}[style=MyFrame] %Added "\parbox{\textwidth}{"
\lipsum[1]
\begin{equation}
 f(x) = \sin(x)
\end{equation}
\lipsum[2]
\end{mdframed}} %Added a closing "}" here
\end{document}
  • It doesn't work for me... lot of message error ! What is \textwidth ? @koleygr – Agape Gal'lo Oct 23 '18 at 17:11
  • Did you copy pasted this code as an example? It shouldn't give errors and it is your own example. \textwidth is the width of the text that will be used for the width of the parbox. Please try it again or edit your question with a real example (that gave you the error). I edited to show you the changes needed (in comments) because you possibly missed something – koleygr Oct 23 '18 at 17:15
  • Sorry ! I missed the final "}". Your code works perfectly ! – Agape Gal'lo Oct 23 '18 at 18:03
  • I supposed that this was your error because could not imagine something else and was somehow hidden. This is the reason I added the comments. Welcome and happy TeXing – koleygr Oct 23 '18 at 18:04
  • I know it's a quite old question, but I have just noticed that the framed box are aligned on the right, even above the text width. Do you have a solution for it ? @koleygr – Agape Gal'lo Dec 12 '18 at 22:14

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.