21

I am a long time LaTeX user, and recently I needed something which I could not figure out by myself, so I would appreciate anyones time and help.

I need a box with rounded corners, which is easy to do - for example, this thread shows how: How to draw frame with rounded corners around box

and I used the mdframed environment to do it. However, now I want to invert the rounded corners, so that the centre of the circle lies in the corner of the box. Actually, what I am trying to achieve is this:

enter image description here

But I don't know how to do it, so I would like to ask for your help.

Thanks in advance.

20

The lines of code could have been reduced but here it is using tcolorbox:

\documentclass{scrbook}
\usepackage{lipsum}
\usepackage{tcolorbox}

\tcbuselibrary{skins}
\usetikzlibrary{calc}
\pgfdeclarelayer{foreground}
\pgfsetlayers{main,foreground}

\newtcolorbox{mybox}{
  colback=red!5!white,
  %width=\linewidth/2, Change the width 
  left=20pt, % left space between content text and box
  top=20pt,
  bottom=20pt,
  right=20pt,
  skin=freelance,
  frame code={%
    \begin{pgfonlayer}{foreground}  
    \draw[line width = 2pt,color = blue!30] ($(frame.south west) +(-4pt,-4pt)$) rectangle ($(frame.north east)+(4pt,4pt)$); %% outer rectangle
    \clip (frame.south west) rectangle (frame.north east);
    \draw[line width = 2pt,color=red!75!black,fill = white] (frame.south west) circle (25pt);
    \draw[line width = 2pt,color=red!75!black,fill = white] (frame.north west) circle (25pt);
    \draw[line width = 2pt,color=red!75!black,fill = white] (frame.north east) circle (25pt);
    \draw[line width = 2pt,color=red!75!black,fill = white] (frame.south east) circle (25pt);
      \draw[line width = 4pt,color=red!75!black]
           ($(frame.south west) +(0pt,24pt)$) -- ($(frame.north west)+(0pt,-24pt)$)  ; %% west
      \draw[line width = 4pt,color=red!75!black]
           ($(frame.north west) +(24pt,0pt)$) -- ($(frame.north east)+(-24pt,0pt)$)  ; %% north
      \draw[line width = 4pt,color=red!75!black]
           ($(frame.north east) +(0pt,-24pt)$) -- ($(frame.south east)+(0pt,24pt)$)  ; %% east
      \draw[line width = 4pt,color=red!75!black]
           ($(frame.south west) +(24pt,0pt)$) -- ($(frame.south east)+(-24pt,0pt)$)  ; %% south      
    \end{pgfonlayer}
  },
}

\begin{document}

\begin{mybox}
\lipsum[1]
\end{mybox}

\end{document}

enter image description here

  • I was sure you had a good answer for this question ;-) – karlkoeller Sep 15 '13 at 21:49
14

A solution using mdframed and allowing page breaks; simply changing the value for \myRad you can get different separations and values for the radius of the arc:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newlength\myRad
\setlength\myRad{20pt}

\newmdenv[
settings={\tikzset{line cap=rect}},
innerrightmargin=2\myRad,
innerleftmargin=2\myRad,
innertopmargin=2\myRad,
innerbottommargin=2\myRad,
singleextra={
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=-\myRad,xshift=2\myRad]P-|O) -- ([yshift=-\myRad,xshift=-2\myRad]P);
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=-2\myRad,xshift=-\myRad]P) -- ([yshift=2\myRad,xshift=-\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=2\myRad,xshift=\myRad]O) -- ([yshift=-2\myRad,xshift=\myRad]O|-P);
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=\myRad,yshift=-2\myRad]P-|O) arc[start angle=-90,end angle=0] (P-|O); 
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad,yshift=-2\myRad]P) arc[start angle=270,end angle=180] (P); 
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=\myRad,xshift=2\myRad]O) -- ([yshift=\myRad,xshift=-2\myRad]P|-O);
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=\myRad,yshift=2\myRad]O) arc[start angle=90,end angle=0] (O); 
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad,yshift=2\myRad]P|-O) arc[start angle=90,end angle=180] (P|-O); 
  },
middleextra={
  \draw[gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad]P) -- ([xshift=-\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([xshift=\myRad]O) -- ([xshift=\myRad]O|-P);
  },
firstextra={
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=-\myRad,xshift=2\myRad]P-|O) -- ([yshift=-\myRad,xshift=-2\myRad]P);
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=-2\myRad,xshift=-\myRad]P) -- ([xshift=-\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([xshift=\myRad]O) -- ([yshift=-2\myRad,xshift=\myRad]O|-P);
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=\myRad,yshift=-2\myRad]P-|O) arc[start angle=-90,end angle=0] (P-|O); 
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad,yshift=-2\myRad]P) arc[start angle=270,end angle=180] (P); 
  },
secondextra={
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=\myRad,xshift=2\myRad]O) -- ([yshift=\myRad,xshift=-2\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad]P) -- ([yshift=2\myRad,xshift=-\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=2\myRad,xshift=\myRad]O) -- ([xshift=\myRad]O|-P);
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=\myRad,yshift=2\myRad]O) arc[start angle=90,end angle=0] (O); 
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad,yshift=2\myRad]P|-O) arc[start angle=90,end angle=180] (P|-O); 
  }
]{invcor}

\begin{document}

\begin{invcor}
\lipsum[2]
\end{invcor}

\begin{invcor}
\lipsum[1-7]
\end{invcor}

\end{document}

enter image description here

Update:

I introduced three mdf keys myRad, myLineWd, and myLineColor allowing you to further customize the attributes (of course, frames still admit page breaks):

\documentclass[dvipsnames]{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\makeatletter
\newlength\mdf@@myRad
\newlength\mdf@@myLineWd
\define@key{mdf}{myRad}{\global\setlength\mdf@@myRad{#1}}
\define@key{mdf}{myLineWd}{\global\setlength\mdf@@myLineWd{#1}}
\define@key{mdf}{myLineColor}{\global\def\mdf@@myLineColor{#1}}

\newmdenv[
myRad=20pt,
myLineWd=5pt,
myLineColor=gray!30,
innerrightmargin=2\mdf@@myRad,
innerleftmargin=2\mdf@@myRad,
innertopmargin=2\mdf@@myRad,
innerbottommargin=2\mdf@@myRad,
singleextra={
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=-\mdf@@myRad,xshift=2\mdf@@myRad]P-|O) -- ([yshift=-\mdf@@myRad,xshift=-2\mdf@@myRad]P);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=-2\mdf@@myRad,xshift=-\mdf@@myRad]P) -- ([yshift=2\mdf@@myRad,xshift=-\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=2\mdf@@myRad,xshift=\mdf@@myRad]O) -- ([yshift=-2\mdf@@myRad,xshift=\mdf@@myRad]O|-P);
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad,yshift=-2\mdf@@myRad]P-|O) arc[start angle=-90,end angle=0] (P-|O); 
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad,yshift=-2\mdf@@myRad]P) arc[start angle=270,end angle=180] (P); 
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=\mdf@@myRad,xshift=2\mdf@@myRad]O) -- ([yshift=\mdf@@myRad,xshift=-2\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad,yshift=2\mdf@@myRad]O) arc[start angle=90,end angle=0] (O); 
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad,yshift=2\mdf@@myRad]P|-O) arc[start angle=90,end angle=180] (P|-O); 
  },
middleextra={
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad]P) -- ([xshift=-\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad]O) -- ([xshift=\mdf@@myRad]O|-P);
  },
firstextra={
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=-\mdf@@myRad,xshift=2\mdf@@myRad]P-|O) -- ([yshift=-\mdf@@myRad,xshift=-2\mdf@@myRad]P);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=-2\mdf@@myRad,xshift=-\mdf@@myRad]P) -- ([xshift=-\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad]O) -- ([yshift=-2\mdf@@myRad,xshift=\mdf@@myRad]O|-P);
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad,yshift=-2\mdf@@myRad]P-|O) arc[start angle=-90,end angle=0] (P-|O); 
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad,yshift=-2\mdf@@myRad]P) arc[start angle=270,end angle=180] (P); 
  },
secondextra={
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=\mdf@@myRad,xshift=2\mdf@@myRad]O) -- ([yshift=\mdf@@myRad,xshift=-2\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad]P) -- ([yshift=2\mdf@@myRad,xshift=-\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=2\mdf@@myRad,xshift=\mdf@@myRad]O) -- ([xshift=\mdf@@myRad]O|-P);
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad,yshift=2\mdf@@myRad]O) arc[start angle=90,end angle=0] (O); 
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad,yshift=2\mdf@@myRad]P|-O) arc[start angle=90,end angle=180] (P|-O); 
  },
]{invcor}
\makeatother

\begin{document}

\begin{invcor}
\lipsum[4]
\end{invcor}

\begin{invcor}[
myLineColor=Dandelion,
myLineWd=3pt]
\lipsum[4]
\end{invcor}

\begin{invcor}[
myRad=10pt,
innerleftmargin=20pt,
innerrightmargin=20pt,
innertopmargin=20pt,
innerbottommargin=20pt,
myLineColor=Maroon,
linecolor=MidnightBlue,
linewidth=2pt,
myLineWd=3pt]
\lipsum[4]
\end{invcor}

\end{document}

enter image description here

10

Light weight approach using package pict2e: Edit: removed spurious spaces.

Edit 2: in the second approach, it was needed to fill the inside and later draw the border, for \linethickness to play the same rôle as in the first picture.

\documentclass{article}
\usepackage{pict2e}
\usepackage{color}
\usepackage{lipsum}

\begin{document}
\setlength{\unitlength}{1cm}

\begin{picture}(10,5)
  \linethickness {.1\unitlength}%
  \roundcap
  \color[gray]{0.7}%
  \put (0,0){\arc[0,90]{1}}
  \Line (0,1)(0,4)
  \put (0,5){\arc[270,360]{1}}
  \Line (1,5)(9,5)
  \put (10,5){\arc[180,270]{1}}
  \Line (10,4)(10,1)
  \put (10,0){\arc[90,180]{1}}
  \Line (9,0)(1,0)
  \color{black}%
  \put (5,2.5){\makebox(0,0){\Huge\textsc{Albert Einstein}}}
\end{picture}

\bigskip
%alternative syntax allowing filling:
\begin{picture}(10,6)
  \linethickness {.1\unitlength}%
  \def\x {\moveto(1,0)
  \circlearc {0}{0}{1}{0}{90}
  \lineto(0,5)
  \circlearc {0}{6}{1}{-90}{0}
  \lineto(9,6)
  \circlearc {10}{6}{1}{180}{270}
  \lineto(10,1)
  \circlearc {10}{0}{1}{90}{180}
  \lineto(1,0)}%
  \color[rgb]{1,.95,0.95}%
  \x
  \fillpath
  \color[rgb]{0.7,0,0}%
  \x
  \strokepath
  \color{blue}%
  \put (5,3){\makebox(0,0){\parbox {8cm}{\footnotesize\lipsum[1]}}}  
\end{picture}

\end{document}

box with round corners

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.