8
$\begingroup$

I want to create a multiple choice question paper and list the options horizontally. I am only looking at very simple document with horizontal list. What I want:

  1. What is 1+1?

    a) 2 b) 4 c) 3 d) 7

Is there any correct way to do it with cells other than manually using spacebars?

$\endgroup$
  • 2
    $\begingroup$ Did you have a look at Grid, Row and such? Might come in handy... $\endgroup$ – Yves Klett Jul 17 '12 at 6:18
10
$\begingroup$

To give you an idea how to go about that:

ans = {2, 4, 3, 7};

Row[Flatten[
  MapIndexed[{FromCharacterCode[#2[[1]] + 96] <> ") ", #1, 
     Spacer[20]} &, ans]]]

Mathematica graphics

or

Grid[{Flatten@
   MapIndexed[{FromCharacterCode[#2[[1]] + 96] <> ")", #1, 
      Spacer[10]} &, ans]}]

Mathematica graphics

Row and Grid behave differently regarding linewrapping, and Grid can of course be extended to 2D.

$\endgroup$
  • $\begingroup$ That is what I'm looking for. Thanks. $\endgroup$ – Standstill Jul 17 '12 at 13:35
8
$\begingroup$

You could use TableForm, e.g.

TableForm[{{"a)", 2, "b)", 4, "c)", 3, "d)", 7}},
 TableSpacing -> {1, 2}]

enter image description here

$\endgroup$
6
$\begingroup$

A list of questions and answers:

questionsAndAnswers = StringJoin /@ {"question" ~~ #[[1]], "answer" ~~ #[[1]] ~~ #[[2]], "answer" ~~ #[[1]] ~~ #[[3]], "answer" ~~ #[[1]] ~~ #[[4]], 
 "answer" ~~ #[[1]] ~~ #[[5]]} & /@ (Join @@ # & /@ 
Thread[{List /@ ToString /@ Range[5], CharacterRange["a", "d"]}, List, 1])
(*{{"question1", "answer1a", "answer1b", "answer1c", "answer1d"},
  {"question2", "answer2a", "answer2b", "answer2c", "answer2d"},
  {"question3", "answer3a", "answer3b", "answer3c", "answer3d"},
  {"question4", "answer4a", "answer4b", "answer4c", "answer4d"},
  {"question5", "answer5a", "answer5b", "answer5c", "answer5d"}} *)

Using Grid:

Column[Grid[#, Spacings -> {2, Automatic}, Alignment -> Left] & /@ 
MapIndexed[{{First@#2 , #1[[1]]},
 {"", Row[{"a)", #1[[2]], "b)", #1[[3]], "c)", #1[[4]], "d)", #1[[5]]}, Spacer[5]]}} &, questionsAndAnswers]]

enter image description here

Using StringForm:

Column[StringForm["`1` \t`2` \n\t  `3`) `4`\t `5`) `6`\t `7`) `8`\t `9`) `10`", 
Sequence @@ (Riffle[#, CharacterRange["a", "d"], {3, -1, 2}])] & /@
MapIndexed[Join @@ {#2, #1} &, questionsAndAnswers]]

enter image description here

$\endgroup$
5
$\begingroup$

You may try

Dynamic@x
Row[{"What is 1+1", Spacer[10], Control[{x, {2, 4, 7}}]}]
$\endgroup$

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.