I am struggling to get two tables aligned at the top (horizontal alignment). I have consulted Align the top of two tables horizontally (side-by-side with minipage), How can I have two tables side by side?, Make two figures aligned at top, Top-align two parboxes with tables, and many, many more. I have tried \parbox and \minipage but haven't had any luck. When I comment out the \minipage code, I get the same thing that I do when the \minipage code is in there. What's really odd is that I had it aligned using \parbox, except the second table was aligned with the center of the first table. When I thought I found a fix for it (using \parbox[t]{} ), the tables were then outputted as table 1 (answer box) and then table 2 (scoring box) below it (instead of next to it). When I removed the [t], nothing changed… the two tables are now stubbornly stacked on top of each other instead of next to each other. I have been working between \minipage and \parbox as I research new solutions on here, but I am still coming up empty.
(Does the document class have anything to do with it? Most of the document classes I've found on here are {article} and not {exam}?)
I am relatively new to LaTeX! Thank you for your patience.
\documentclass[12pt]{exam}
\usepackage{multirow} % for tables
\pagestyle{headandfoot}
\usepackage[margin=1in]{geometry}
\singlespacing
%to make cells in table have decent spacing
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{table}
%heading
\begin{flushright}
\begin{tabular}[t]{p{3.8in} r l}
\textbf{class} & \textbf{Name:} & \makebox[2in]{\hrulefill}\\
\textbf{exam} &&\\
\textbf{date} &&
\end{tabular}
\end{flushright}
\rule[1ex]{\textwidth}{.1pt}
%answer box
\begin{minipage}[t]{0.45\linewidth}
\begin{tabular}[t]{ | C{1cm} | R{1.5cm} | }
\hline
1. & \\
& \\ \hline
2. & \\
& \\ \hline
3. & \\
& \\ \hline
4. & \\
& \\ \hline
5. & \\
& \\ \hline
6. & \\
& \\ \hline
7. & \\
& \\ \hline
\end{tabular}
\end{minipage}
%scoring box
\begin{minipage}[b]{0.45\linewidth}
\begin{tabular}[t]{ | c | R{2cm} | R{1.5cm} | }
\hline
\multirow{2}{*}{Multiple Choice} & x $(9/7)$ & \\
& & \\ \hline
\multirow{2}{*}{Free Response} & x 1 & \\
& & \\ \hline
\multicolumn{1}{ c }{} & Your Score out of 18 & \\ \cline{3-3}
\end{tabular} \\
\end{minipage}
\end{table}
\end{document}
Best Answer
You can use a single
tabularx
in place of two tables. By this, you needn't useminipage
s to spread the tables a part. The columns oftabularx
will be the same as your two separate tables plus anX
column type at the middle to fill the remaining horizontal space. Note also that I usedtabularx
for the first table. This enabled us to use\hrulefill
directly without\makebox
.Yet another simpler option is to use two
tabular
s with the[t]
alignment option as follows (with the same result as above):