# Increasing the size of a minipage proportional to the contain

I am trying to create a simple environment. The enviroment contains a minipage that is surrounded but a dashed box.

\NewEnviron{Notes}{
\par
\begin{tikzpicture}
\node[rectangle,minimum width=0.95\textwidth] (m) {
\begin{minipage} {0.75\textwidth}
\color{red}\BODY
\end{minipage}
};
\draw[dashed] (m.south west) rectangle (m.north east);
\end{tikzpicture}\\
}


Essentially, I would like to increase the size of the box proportional to its contain. So, something like: \vspace{0.2*\BODYHeight}

What's the best way of doing this?

-
 the height of the box proportional to the height of its contain ? because the width is fixed 0.75\textwidth ! – Alain Matthes Feb 24 '12 at 23:16 Sorry, I don't understand what you mean. Where does fixing the width present a problem for height? – csgillespie Feb 25 '12 at 2:00 a box has 2 dimensions : width and height. If a box is proportional to another, height and width of the first box must be proportional to the height and width of the second one and I'm not sure that you want. In my answer, only heights are proportional.. The width is fixed by 0.75 \textwidth . – Alain Matthes Feb 25 '12 at 5:28 A bad question, sorry. I meant that keeping the textwidth fixed and adjusting the height. – csgillespie Feb 26 '12 at 20:02

What you can do is to enclose the \BODY with the necessary spacing. Here is a MWE.

\documentclass{article}
\usepackage{environ}
\usepackage{tikz}
\usepackage{lipsum}
\begin{document}
\NewEnviron{Notes}{
\par
\begin{tikzpicture}
\node[rectangle,minimum width=0.95\textwidth] (m) {
\begin{minipage} {0.75\textwidth}
\vspace*{0.1\textwidth}
\color{red}\BODY
\vspace{0.1\textwidth}
\end{minipage}
};
\draw[dashed] (m.south west) rectangle (m.north east);
\end{tikzpicture}\\
}

\begin{Notes}
\lipsum[1]
\end{Notes}
\end{document}


A better approach is to rather use a fixed amount of padding:

\documentclass{article}
\usepackage{environ}
\usepackage{tikz}
\usepackage{lipsum}
\begin{document}
\NewEnviron{Notes}{
\par
\begin{tikzpicture}
\node[rectangle,minimum width=0.5\textwidth] (m) {
\fbox{\begin{minipage} {0.5\textwidth}
\color{red}\BODY
\end{minipage}}
};
\draw[dashed] (m.south west) rectangle (m.north east);
\end{tikzpicture}\\
}

\begin{Notes}
\lipsum[1]
\end{Notes}
\end{document}


if you add \fboxsep0pt, the inner rule will not be shown. Padding can be increased using a suitable value of \fboxsep. I think this is a much better solution in terms of typography and scales well. Non-linear scaling of the vertical spacing is also possible and one could employ a technique I first encountered in amsgen, latex amsgen.dtx and look up the definition of \compute@ex@. The difficulty is to find an acceptable formula to describe the aesthetics of such spacing. The formula should include for such variables as textwidth, height, font-size and the relationships to the rest of the text.

-
 Thanks, but the gap isn't proportional to the amount of text in the environment. For example, \begin{Notes}Test\end{Notes} should only have a small gap around it. – csgillespie Feb 24 '12 at 21:56 @csgillespie Based on what formula? If the text is very large, it will yield a larger space? A better approach is to use a fixed amount of padding. I will expand in the post. – Yiannis Lazarides Feb 25 '12 at 7:23

Not exactly proportional because eI added 2pt to avoid very small values . It's possible to change .05\htbox with .1\htbox but now the problem comes from big values.

\documentclass{article}
\usepackage{environ}
\usepackage{tikz}
\usepackage{lipsum}
\begin{document}

\newbox\mybox
\newdimen\htbox
\newdimen\innersep
\NewEnviron{Notes}{%
\setbox\mybox=\vbox{%
\begin{minipage} {0.75\textwidth}
\color{red}\BODY
\end{minipage}}%
\htbox\ht\mybox
\innersep=.05\htbox
\par
\begin{tikzpicture}
\node[draw,inner sep=\innersep,rectangle,
text width=0.95\textwidth-2\innersep] (m) {\unvcopy\mybox};
\end{tikzpicture}\\
}

\begin{Notes}
Texte
\end{Notes}

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

\end{document}


-
 Nice solution. See the additional notes in my answer regarding proportional spacing. – Yiannis Lazarides Feb 25 '12 at 7:44 Yes I saw your comment and I agree with you, a fixed amount of padding is preferable but perhaps I don't understand the aim of the requirement about proportionality. – Alain Matthes Feb 25 '12 at 8:21 I am not sure either, but whatever it shouldn't be a linear function. – Yiannis Lazarides Feb 25 '12 at 8:44