# exam class - align problems horizontally using probsoln

I would like to create worksheets with problems filled by rows instead of columns. I am using probsoln to store and call the problems, but they always end up filling the worksheet vertically. I tried putting them in a table, but I can't get that to work.

\documentclass[letter]{article}

\usepackage{probsoln}
\usepackage{amsmath}
\usepackage{multicol}

\PSNrandseed{2004}

\begin{document}

\begin{tabular}{lllll}
\foreachproblem{\thisproblem\\}%
\end{tabular}

\end{document}


I would like to be able to pull one or two rows of problems from each file as needed. I would like to use exam class if possible.

Test Database

\newproblem{addfractions:1212}
{$\frac{1}{2} + \frac{1}{2} =$}
{$\frac{1}{2} + \frac{1}{2} = \frac{2}{2} = 1$}

{$\frac{1}{2} + \frac{1}{3} =$}
{$\frac{1}{2} + \frac{1}{3} = \frac{3}{6} + \frac{2}{6} = \frac{5}{6}$}

{$\frac{1}{2} + \frac{2}{3} =$}
{$\frac{1}{2} + \frac{2}{3} = \frac{3}{6} + \frac{4}{6} = \frac{7}{6} = 1 \frac{1}{6}$}

{$\frac{1}{2} + \frac{1}{4} =$}
{$\frac{1}{2} + \frac{1}{4} = \frac{2}{4} + \frac{1}{4} = \frac{3}{4}$}

{$\frac{1}{2} + \frac{1}{6} =$}
{$\frac{1}{2} + \frac{1}{6} = \frac{3}{6} + \frac{1}{6} = \frac{4}{6} = \frac{2}{3}$}

{$\frac{1}{2} + \frac{5}{6} =$}
{$\frac{1}{2} + \frac{5}{6} = \frac{3}{6} + \frac{5}{6} = \frac{8}{6} = 1 \frac{2}{6} = 1 \frac{1}{3}$}

{$\frac{1}{2} + \frac{1}{7} =$}
{$\frac{1}{2} + \frac{1}{7} = \frac{7}{14} + \frac{2}{14} = \frac{9}{14}$}

{$\frac{1}{2} + \frac{2}{7} =$}
{$\frac{1}{2} + \frac{2}{7} = \frac{7}{14} + \frac{4}{14} = \frac{11}{14}$}

{$\frac{1}{2} + \frac{3}{7} =$}
{$\frac{1}{2} + \frac{3}{7} = \frac{7}{14} + \frac{6}{14} = \frac{13}{14}$}

{$\frac{1}{2} + \frac{4}{7} =$}
{$\frac{1}{2} + \frac{4}{7} = \frac{7}{14} + \frac{8}{14} = \frac{15}{14} = 1 \frac{1}{14}$}

{$\frac{1}{2} + \frac{5}{7} =$}
{$\frac{1}{2} + \frac{5}{7} = \frac{7}{14} + \frac{10}{14} = \frac{17}{14} = 1 \frac{3}{14}$}

{$\frac{1}{2} + \frac{6}{7} =$}
{$\frac{1}{2} + \frac{6}{7} = \frac{7}{14} + \frac{12}{14} = \frac{19}{14} = 1 \frac{5}{14}$}

{$\frac{1}{2} + \frac{1}{8} =$}
{$\frac{1}{2} + \frac{1}{8} = \frac{4}{8} + \frac{1}{8} = \frac{5}{8}$}

{$\frac{1}{2} + \frac{3}{8}=$}
{$\frac{1}{2} + \frac{3}{8} = \frac{4}{8} + \frac{3}{8} = \frac{7}{8}$}

{$\frac{1}{2} + \frac{5}{8}=$}
{$\frac{1}{2} + \frac{5}{8} = \frac{4}{8} + \frac{5}{8} = \frac{9}{8} = 1 \frac{1}{8}$}

{$\frac{1}{2} + \frac{7}{8}=$}
{$\frac{1}{2} + \frac{7}{8} = \frac{4}{8} + \frac{7}{8} = \frac{11}{8} = 1 \frac{3}{8}$}

{$\frac{1}{2} + \frac{1}{9}=$}
{$\frac{1}{2} + \frac{1}{9} = \frac{9}{18} + \frac{2}{18} = \frac{11}{18}$}

• Can you add some example problems? It's difficult to test without a database to load. May 15 '13 at 19:39
• \newproblem{addfractions:1212} {$\frac{1}{2} + \frac{1}{2} =$} {$\frac{1}{2} + \frac{1}{2} = \frac{2}{2} = 1$} \newproblem{addfractions:1213} {$\frac{1}{2} + \frac{1}{3} =$} {$\frac{1}{2} + \frac{1}{3} = \frac{3}{6} + \frac{2}{6} = \frac{5}{6}$} \newproblem{addfractions:1223} {$\frac{1}{2} + \frac{2}{3} =$} {$\frac{1}{2} + \frac{2}{3} = \frac{3}{6} + \frac{4}{6} = \frac{7}{6} = 1 \frac{1}{6}$} \newproblem{addfractions:1214} {$\frac{1}{2} + \frac{1}{4} =$} {$\frac{1}{2} + \frac{1}{4} = \frac{2}{4} + \frac{1}{4} = \frac{3}{4}$} May 15 '13 at 22:34
• @NicoleMathisen Updated the question with the test database. In future do update in question rather than in comments to make question stand on it's own irrespective of comments, as comments don't have any backups(without UPS :) ). May 16 '13 at 2:13
• Note that the exam class has its own mechanism for recording solutions. May 16 '13 at 3:17

You can achieve it by keeping track of which column you are in as follows:

\documentclass{article}

\usepackage{etoolbox}
\usepackage{probsoln}
\usepackage{amsmath}
\usepackage{multicol}

\PSNrandseed{2004}

\begin{document}

\newcounter{colcount}
\begin{tabular}{lllll}
\foreachproblem{\thisproblem
\global\stepcounter{colcount}%
\ifnumless{\value{colcount}}{4}{&}{\global\setcounter{colcount}{0}\\}%
}%
\end{tabular}

\end{document}


Result: