share
TeX - LaTeXHow to draw frame with rounded corners around box
[+39] [3] Dan
[2011-11-08 11:08:45]
[ boxes framed rounded-corners ]
[ https://tex.stackexchange.com/questions/34088/how-to-draw-frame-with-rounded-corners-around-box ]

Is it possible to simply draw a frame around a box which has rounded corners, and be able to control frame width, frame color, frame radius, box background colour (preferably without having to use the complex TikZ package)

eg. (this produces a framed box, but without the required rounded corners)

\documentclass{article}
\usepackage{graphicx}
\usepackage{color}
\usepackage{fancybox}
\begin{document}

\fboxsep=3pt
\fboxrule=2pt
\def\bordercolor{red}
\def\backgroundcolor{white}
\cornersize{0.9}
\fcolorbox{\bordercolor}{\backgroundcolor} {Here is some text}%

\end{document}
(2) TikZ may be complex but a color box is very simple. Have, e.g., a look at Example: Boxes with text and math. - Schweinebacke
It is reasonable simple to create a colored frame around a box with a colored background and control the parameters, but the rounded corners makes everything much more complicated, especially the background. For this you need TikZ or a similar package. - Martin Scharrer
@Schweinebacke thanks, TikZ looks amazing but seems so complicated. Can you recommend a good tutorial on getting started with TikZ? - Dan
@Dan: What's a good tutorial? IMHO this depends not only on the tutorial but also on the student. I like to read examples and usually use the package manuals to modify them. And I like the examples at the pgf manual. BTW: There are many more TikZ examples at texexample.net. - Schweinebacke
@Schweinebacke: thanks, it seems the TikZ manual contains a tutorial media.texample.net/pgf/builds/pgfmanualCVS2010-09-28.pdf - Dan
[+28] [2011-11-08 11:20:43] Seamus [ACCEPTED]

Here's a method that doesn't require loading TikZ explicitly. (Although mdframed [1] uses tikz behind the scenes. This is, however, the package for framing boxes.

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\begin{document}
\begin{mdframed}[roundcorner=10pt]
  \lipsum[1]
\end{mdframed}
\end{document}

If you don't even want to use TikZ as a backend, you could use PSTricks:

\documentclass{article}
\usepackage[framemethod=PStricks]{mdframed}
\usepackage{lipsum}
\begin{document}
\begin{mdframed}[roundcorner=10pt]
  \lipsum[1]
\end{mdframed}
\end{document}

[Note this doesn't seem to be working for me at the moment.]

[1] http://www.ctan.org/pkg/mdframed

I see there is a bug. - Marco Daniel
At the moment I recommend framemethod tikz. - Marco Daniel
@Seamus Looks like I have an old version of mdframed, as your example does not work for me. I'll update the package, and retry, thanks. - Dan
Still have a problem after updating mdframed package to version: 2011-10-10 14:44:36... ! Package keyval Error: framemethod undefined. - Dan
@Dan use \usepackage[style=1]{mdframed} instead. This is the old way of specifying using tikz. - Seamus
@Seamus: thanks, but I got the following error when I tried [style=1]: ! LaTeX Error: File `md-tikz-1.mdf' not found. (I do have the TikZ package installed, at it works) - Dan
@Dan where did you get the version dated 2011-10-10? The version in texlive and the version on CTAN are dated 2011-10-09... - Seamus
Marco Daniel is the author of mdframed, by the way. - Seamus
@MarcoDaniel: Looks like mdframed is what I need, but is there any way I can get the resulting box into a \savebox? - Dan
@Dan: The contents is saved in a savebox? What is the intention of this question - Marco Daniel
@Dan that looks like it might be a separate question. - Seamus
@Seamus: yes, thanks, you are right, I'll create a separate question. Thank you for your help. - Dan
1
[+26] [2016-10-23 10:47:56] Ignasi

Although when seamus wrote his answer, tcolorbox was not in CTAN, it was announced [1] just one month later. And as nobody has written an answer mentioning it, I do it.

So here you have a little code which shows how to declare a framed box with tcolorbox. How to change it's width, frame color, background color, text alignment, space between text and frame border and rounded corners diameter.

For more funny options you can consult tcolorbox documentation [2] or dive here [3]

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}

\begin{tcolorbox}
Here is some text
\end{tcolorbox}

\begin{tcolorbox}[width=5cm]
Here is some text
\end{tcolorbox}

\begin{tcolorbox}[width=.5\textwidth, colframe=red]
Here is some text
\end{tcolorbox}

\begin{tcolorbox}[width=8cm, colframe=red, colback=blue!30, halign=right]
Here is some text
\end{tcolorbox}

\begin{tcolorbox}[width=.5\linewidth, halign=center, colframe=red, colback=blue!30, boxsep=5mm, arc=3mm]
Here is some text
\end{tcolorbox}

\begin{tcolorbox}[width=7cm, colframe=red, colback=blue!30, arc=3mm, sharp corners=east]
Here is some text
\end{tcolorbox}

\end{document}

enter image description here

[1] http://ctan.org/ctan-ann/pkg/tcolorbox
[2] http://texdoc.net/pkg/tcolorbox
[3] https://tex.stackexchange.com/search?q=tcolorbox

2
[+6] [2017-07-18 18:36:17] LCarvalho

This another option:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
    \begin{tikzpicture}[x=0.5mm,y=0.5mm]
    \coordinate (a1);
    \coordinate[right=150 of a1](a2);
    \coordinate[below=90 of a1](a3);
    \coordinate[right=150 of a3](a4);
    %% 
    \draw[ultra thick,rounded corners=10] ($(a4)-(50,20)$) rectangle +(50*2,20*2);%Rectangle rounded
    \end{tikzpicture}
\end{document}

enter image description here


3