5

how can I easily make a box like this, set its width and the white border around it?

enter image description here

(Ignore the text inside.)

Arun Debray
  • 7,126
  • 2
  • 30
  • 54

2 Answers2

6

Here is way with tcolorbox and the borderline= option.

\documentclass{article}

\usepackage[most]{tcolorbox}
\usepackage{blindtext}
\begin{document}

\begin{tcolorbox}[enhanced jigsaw,
    sharp corners,
    boxrule=0.5pt, 
    colback=red!30!white,   
    borderline={0.5pt}{-2pt}{black,solid} % 0.5pt linewith, -2pt outside, black solid linestyle
 ]
\blindtext
\end{tcolorbox}

\end{document}

enter image description here

2

Here is a basic implementation that uses a key-value approach to setting the width and background colour:

enter image description here

\documentclass{article}
\usepackage{xcolor,keyval}
\usepackage[nopar]{lipsum}% Just for this example

\makeatletter \definecolor{pinkish}{rgb}{0.96,0.80,0.80} \newlength{@mcb@width} \define@key{mcb}{bg}{\def@mcb@bg{#1}} \define@key{mcb}{width}{\setlength@mcb@width{#1}} \newcommand{\mycolorbox}[2][]{{% \setkeys{mcb}{width=0.5\linewidth,bg=pinkish,#1}% \fbox{\colorbox{@mcb@bg}{\begin{minipage}{@mcb@width} \strut#2\strut \end{minipage}}} }} \makeatother

\begin{document}

\mycolorbox{something}

\mycolorbox[width=.3\linewidth]{something}

\mycolorbox[bg=blue!40!white]{something}

\mycolorbox[bg=green!15!white,width=.7\linewidth]{\lipsum[1]}

\end{document}

\struts are used in an attempt to achieve a more consistent baseline height/depth at the top/bottom of the minipage construction.

One could also use a tabular construction, if needed.

Werner
  • 603,163