[Tex/LaTex] Tight box around text using mdframed

boxesmdframed

Do you know how to force mdframed to frame text more tightly? It seems, that it is just framing the whole line. But my goual is to have just framed text, so that the finished boxes will have different width on the basis of text. If you look on the picture, you will understand, what I mean. Thanks alot for help!

\mdfdefinestyle{MyFrame}{%
    linecolor=black,
    outerlinewidth=2pt,
    %roundcorner=20pt,
    innertopmargin=4pt,
    innerbottommargin=4pt,
    innerrightmargin=4pt,
    innerleftmargin=4pt,
        leftmargin = 4pt,
        rightmargin = 4pt
    %backgroundcolor=gray!50!white}
        }

% text
\begin{mdframed}[style=MyFrame,nobreak=true]
\begin{center}
\textbf{THIS TEXT SHOULD BE MORE TIGHTLY FRAMED }
\end{center}
\end{mdframed}

% sipka
\begin{figure}[h!]
\centering
\includegraphics[width=.1\textwidth]{sipka3.pdf}
\end{figure}
% arrow
\begin{mdframed}[style=MyFrame,nobreak=true]
\lipsum[2]
\end{mdframed}

% sipka
\begin{figure}[h!]
\centering
\includegraphics[width=.1\textwidth]{sipka3.pdf}
\end{figure}
% arrow
\begin{mdframed}[style=MyFrame,nobreak=true]
\lipsum[1]
\end{mdframed}

enter image description here

Best Answer

You can use the mdframed options align=center,userdefinedwidth=....

enter image description here

\documentclass{article}
\usepackage{mdframed,lipsum}
\begin{document}
\mdfdefinestyle{MyFrame}{%
    linecolor=black,
    outerlinewidth=2pt,
    %roundcorner=20pt,
    innertopmargin=4pt,
    innerbottommargin=4pt,
    innerrightmargin=4pt,
    innerleftmargin=4pt,
        leftmargin = 4pt,
        rightmargin = 4pt
    %backgroundcolor=gray!50!white}
        }

% text
\lipsum[1]
\begin{mdframed}[style=MyFrame,nobreak=true,align=center,userdefinedwidth=30em]
\textbf{THIS TEXT SHOULD BE MORE TIGHTLY FRAMED}
\end{mdframed}
\lipsum[2]
\end{document}