0

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}
0

2 Answers 2

0

You can use a single tabularx in place of two tables. By this, you needn't use minipages to spread the tables a part. The columns of tabularx will be the same as your two separate tables plus an X column type at the middle to fill the remaining horizontal space. Note also that I used tabularx for the first table. This enabled us to use \hrulefill directly without \makebox.

\documentclass[12pt]{exam}
\usepackage{tabularx}  % for tabularx
\usepackage[margin=1in]{geometry}

% 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{tabularx}{\linewidth}{@{}p{3.8in} X@{}}
\textbf{class} & \textbf{Name:} \hrulefill \\
\textbf{exam}  &                           \\
\textbf{date}  &                
\end{tabularx}

\addvspace{1em} 
\hrule height .1pt 
\addvspace{1em}

% answer box 
\renewcommand{\arraystretch}{2}
\begin{tabularx}{\linewidth}{|C{1cm}|R{1.5cm}| X |c|R{2cm}|R{1.5cm}|}
    \cline{1-2}\cline{4-6}
    1. &  &  & Multiple Choice & ${}\times(9/7)$ & \\ \cline{1-2}\cline{4-6} 
    2. &  &  & Free Response   & ${}\times1$     & \\ \cline{1-2}\cline{4-6}
    3. &  & \multicolumn{1}{c}{} & \multicolumn{2}{r|}{Your Score out of 18} & \\ \cline{1-2}\cline{6-6}
    4. &   \\ \cline{1-2}
    5. &   \\ \cline{1-2}
    6. &   \\ \cline{1-2}
    7. &   \\ \cline{1-2}  
\end{tabularx} 
\end{table}

\end{document}

enter image description here

Yet another simpler option is to use two tabulars with the [t] alignment option as follows (with the same result as above):

\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}
\hfill
\begin{tabular}[t]{|c|R{2cm}|R{1.5cm}|}
   \hline
   Multiple Choice & ${}\times(9/7)$ & \\ \hline
   Free Response   & ${}\times1$     & \\ \hline
   \multicolumn{2}{r|}{Your Score out of 18} & \\ \cline{3-3}
\end{tabular}
2
  • The first method worked for me! Thank you. I will learn more about the tabularx package now since that was super simple. Additionally, the two tabular methods with [t] did NOT work for me... for some reason. And at this point in my LaTeX education, I am only mildly interested in why it didn't work. However, I am interested in knowing if there is a way to get "Your score out of 18" to wrap so that it isn't multicolumn? This is a curiosity, not something I need for this particular document I'm working on. Thank you!!
    – Jenni
    Commented Jul 31, 2017 at 16:47
  • @Jenni -- As to why the second solution didn't work, we need a complete MWE showing the wrong output you mention to fix it for you. To wrap "Your score out of 18" you may change the third row to 3. & & \multicolumn{2}{c}{} & \vbox to .6cm {Your Score out of 18} & \\ \cline{1-2}\cline{6-6}. I'm too lazy now to explain, but you can understand what this command does with some search.
    – AboAmmar
    Commented Jul 31, 2017 at 19:44
0

Like this:

enter image description here

you were very close to this ... i only change minipage option from b to t and between tables add hfill and delete empty line between minipages:

\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}
\hfill
%scoring box
\begin{minipage}[t]{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}
2
  • Thank you for your encouragement! This solution did not work for me, however :( I had tried this and a few other small tweaks and it just wasn't coming together. I'm not sure why but my output still had the two tables stacked one on top of the other. Odd.
    – Jenni
    Commented Jul 31, 2017 at 16:50
  • @jeni, my answer gives equal result as of aboammar, what then not work to you? you should be more specific and clear what you like to have. sorry.
    – Zarko
    Commented Jul 31, 2017 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .