# Are three boxes inside a box possible?

I am making a yes or no question inside a box and I have difficulty on creating the command for it. Would you mind to help me make something that will output this:

-
In its current form, your question might not receive many answers. Please take a look at the How to Ask-page and try to improve your question according to the guidance found there. This may require you to show some effort on your part in terms of attempting a solution. If you have questions about what to do or if you don't quite understand what this means, please ask for clarification using the add comment function. –  egreg Nov 24 '12 at 17:43
You can pretty much have as many nested boxes as you want. See for example: Define a command (possibly recursively) to wrap text in a command n times. –  Peter Grill Nov 25 '12 at 0:56

As I said in Define a command (possibly recursively) to wrap text in a command n times, when it comes to drawing boxes, tikz is the way to go.

Here is a macro version that accepts four mandatory parameters for each of the text elements. So with

\BoxedQuestion{Is this what you are looking for?}{YES}{NO}{NONE}


you get your plain vanilla box:

However, it also accepts two optional parameters that allow you to style the outer and inner boxes. This illustrates just a few of the various options you can tweak where you can adjust alignment, draw and fill colors:

## Box Width:

To control the width of the box, you can add the text width=<length> option:

## Horizontal Spacing between Boxes:

A macro has been defined to specify the horizontal spacing. It is currently defined to \hfill which will even space out the three boxes. You can adjust this if you do prefer them separated by a fixed amount of space. So with this defined as

\newcommand*{\HorizontalSpacing}{\hspace*{2.0cm}}


you get:

Note that a fixed distance for horizontal separation requires some care as illustrated by the 4th box above.

Also, this necessitated a slightly different use mode in terms of how the alignment of the first line is controlled: Instead of the tikz options I used a \fill on the appropriate side.

## Code: Boxes Evenly Distributed

\documentclass{article}
\usepackage{tikz}
\usepackage{xparse}

\newcommand*{\HorizontalSpacing}{\hfill}% equally spaced boxes
%\newcommand*{\HorizontalSpacing}{\hspace*{2.0cm}}% fixed space boxes

\newlength{\InnerSep}
\setlength{\InnerSep}{0.1cm}

\newcommand{\Boxed}[2][]{%
% #1 = box draw/fill options
% #2 = text
\begin{tikzpicture}[baseline, inner sep=2pt, outer sep=0]
\node [#1] (Origin) {#2};
\draw [thick, draw=black, #1]
(Origin.south west) rectangle (Origin.north east) ;
\end{tikzpicture}%
}

\tikzset{Outer Box Style/.style={align=center}}
\tikzset{Inner Box Style/.style={
inner sep=2pt, yshift=0.7ex,
text width=1ex, minimum height=2ex
}
}

\newlength{\BoxWidth}
\NewDocumentCommand{\BoxedQuestion}{O{} O{} m m m m}{
% #1 = optional draw options for outer box
% #2 = optional draw options for inner boxes
% #3 = text of question
% #4 = choice 1
% #5 = choice 2
% #6 = choice 3
\setlength{\BoxWidth}{\dimexpr\linewidth-2\InnerSep-2\pgflinewidth\relax}%
\par\noindent\Boxed[Outer Box Style, text width=\BoxWidth, #1]{%
#3\strut%
\par\bigskip\noindent%
\hspace*{\InnerSep}\Boxed[Inner Box Style, #2]{}\,#4%
\HorizontalSpacing\Boxed[Inner Box Style, #2]{}\,#5%
\HorizontalSpacing\Boxed[Inner Box Style, #2]{}\,#6%
\hspace*{\InnerSep}\null%
}%
}%

\begin{document}
\BoxedQuestion
{Is this what you are looking for?}
{YES}{NO}{NONE}

\medskip
\BoxedQuestion[draw=red, align=left][draw=blue, fill=yellow!50]
{Is this what you are looking for?}
{YES}{NO}{NONE}

\medskip
\BoxedQuestion
[draw=red, ultra thick, loosely dotted, align=right,
fill=green!30, fill opacity=0.2, text opacity=1]
[solid, ultra thick, draw=blue, fill=orange!50]
{Is this what you are looking for?}
{YES}{NO}{NONE}

\medskip
\BoxedQuestion[text width=6cm]
[solid, ultra thick, draw=blue, fill=orange!50]
{Is this what you are looking for?}
{YES}{NO}{NONE}

\BoxedQuestion[text width=8cm]
[solid, ultra thick, draw=blue, fill=orange!50]
{Is this what you are looking for?}
{YES}{NO}{NONE}
\end{document}


## Code: Fixed Horizontal Spacing

\documentclass{article}
\usepackage{tikz}
\usepackage{xparse}

%\newcommand*{\HorizontalSpacing}{\hfill}% equally spaced boxes
\newcommand*{\HorizontalSpacing}{\hspace*{2.0cm}}% fixed space boxes

\newlength{\InnerSep}
\setlength{\InnerSep}{0.1cm}

\newcommand{\Boxed}[2][]{%
% #1 = box draw/fill options
% #2 = text
\begin{tikzpicture}[baseline, inner sep=2pt, outer sep=0]
\node [#1] (Origin) {#2};
\draw [thick, draw=black, #1]
(Origin.south west) rectangle (Origin.north east) ;
\end{tikzpicture}%
}

\tikzset{Outer Box Style/.style={align=center}}
\tikzset{Inner Box Style/.style={
inner sep=2pt, yshift=0.7ex,
text width=1ex, minimum height=2ex
}
}

\newlength{\BoxWidth}
\NewDocumentCommand{\BoxedQuestion}{O{} O{} m m m m}{
% #1 = optional draw options for outer box
% #2 = optional draw options for inner boxes
% #3 = text of question
% #4 = choice 1
% #5 = choice 2
% #6 = choice 3
\setlength{\BoxWidth}{\dimexpr\linewidth-2\InnerSep-2\pgflinewidth\relax}%
\par\noindent\Boxed[Outer Box Style, text width=\BoxWidth, #1]{%
#3\strut%
\par\bigskip\noindent%
\hspace*{\InnerSep}\Boxed[Inner Box Style, #2]{}\,#4%
\HorizontalSpacing\Boxed[Inner Box Style, #2]{}\,#5%
\HorizontalSpacing\Boxed[Inner Box Style, #2]{}\,#6%
\hspace*{\InnerSep}%
}%
}%

\begin{document}
\BoxedQuestion
{Is this what you are looking for?}
{YES}{NO}{NONE}

\medskip
\BoxedQuestion[draw=red][draw=blue, fill=yellow!50]
{Is this what you are looking for?\hfill }
{YES}{NO}{NONE}

\medskip
\BoxedQuestion
[draw=red, ultra thick, loosely dotted,
fill=green!30, fill opacity=0.2, text opacity=1]
[solid, ultra thick, draw=blue, fill=orange!50]
{\hfill Is this what you are looking for?}
{YES}{NO}{NONE}

\medskip
\BoxedQuestion[text width=6cm]
[solid, ultra thick, draw=blue, fill=orange!50]
{Is this what you are looking for?}
{YES}{NO}{NONE}

\BoxedQuestion[text width=8cm]
[solid, ultra thick, draw=blue, fill=orange!50]
{Is this what you are looking for?}
{YES}{NO}{NONE}
\end{document}

-
how can i lessen the spaces between the boxes? –  Kayla Nov 25 '12 at 5:25
@kayla: If you want to adjust the horizontal spacing you can replace the hfill with something like \hspace*{2.0cm}. But in this case, what do you want to happen to the surrounding box? Should it still occupy the full \linewidth, or should it shrink? Perhaps the real question is: Do you want to control the spacing between the boxes, or do you want equal spacing and control the horizontal dimension of the outer box? All are possible, just need to know how you actually want to use it. –  Peter Grill Nov 25 '12 at 5:34
@Peter.. i prefer to have an equal horizontal spacing between the three inner boxes :) –  Kayla Nov 25 '12 at 5:51
@kayla: Sorry I did not see this message for a while. You need to use the full userid, otherwise I do not get a notification. Have updated solution as requested. –  Peter Grill Nov 25 '12 at 8:10
This is really a big help for me. Glad you answer me back. :) –  Kayla Nov 25 '12 at 9:40

Yes. Boxes can be nested.

\documentclass{article}
\usepackage{calc}
\pagestyle{empty}
\begin{document}

\fbox{\begin{minipage}{\textwidth-2\fboxrule-2\fboxsep}
\centering
Is this what you're looking for?
\vspace{3ex}

\fbox{\rule{1em}{0pt}\rule{0pt}{1em}} YES \hspace*{\fill}
\fbox{\rule{1em}{0pt}\rule{0pt}{1em}} NO  \hspace*{\fill}
\fbox{\rule{1em}{0pt}\rule{0pt}{1em}} NONE
\end{minipage}}

\end{document}


-