1

I'm trying to position the table such that the top of the table would have the same height as the text next to it, but there's always an exceedingly annoying line that I can't seem to get rid of.

Basically, I just want the table to move up a height of one line.

\item \begin{minipage}[t]{0.5\textwidth} Multiply the value of each region with its
corresponding probability,  then sum up the results. \end{minipage} \begin{minipage}
[t]{4cm} \begin{tabular}[t]{|r|l|} \hline Probability & Region \\ \hline 0.0077 & -3 \\
\hline 0.0462 & -2 \\ \hline 0.2462 & -1 \\ \hline 0.4077 & 0 \\ \hline 0.2385 & 1 \\
\hline 0.0462 & 2 \\ \hline 0.0077 & 3 \\ \hline \end{tabular} \end{minipage}
  • 3
    use array package and \firsthline instead of \hline for the top rule. Please always post complete small document not just a fragment. (also you don't need the minipage around the tabular – David Carlisle Nov 11 '13 at 22:19
4

You can use the adjustbox package in the following manner:

\documentclass{article}
\usepackage{array}
\usepackage{adjustbox}
\begin{document}
\begin{enumerate}
    \item test
    \item \begin{minipage}[t]{0.5\textwidth} 
          Multiply the value of each region with its corresponding probability,  then sum up the results. 
          \end{minipage}
          \begin{adjustbox}{valign=t}                % Comment if using the option below.
          %\begin{adjustbox}{valign=t,raise=0.125ex} % Uncomment to get the baseline of the text and the first line of the table aligned.
          \begin{tabular}{|r|l|} 
          \hline Probability & Region \\ \hline 
          0.0077 & -3 \\ \hline 
          0.0462 & -2 \\ \hline 
          0.2462 & -1 \\ \hline 
          0.4077 & 0 \\ \hline 
          0.2385 & 1 \\ \hline 
          0.0462 & 2 \\ \hline 
          0.0077 & 3 \\ \hline 
          \end{tabular}
          \end{adjustbox}
\end{enumerate}
\end{document}

enter image description here

  • it would be nicer if the baseline of the text and the first line of the table were aligned. the table is just a bit lower. – barbara beeton Nov 12 '13 at 15:33
  • @barbarabeeton See updated answer, even though I am not content about how I got the 0.125ex to raise by. I would want to do this automatically. – azetina Nov 12 '13 at 19:09
2

I omit the tabular's lines at the top, bottom, left and right. Then use the [t] option of tabular to force alignment on the first line. Finally, put the surrounding lines back with \fbox, which preserves the baseline:

\documentclass{article}
\begin{document}
\begin{enumerate}
\item test
\item \begin{minipage}[t]{0.5\textwidth}
        Multiply the value of each region with its corresponding
        probability,  then sum up the results.
      \end{minipage}
{\fboxsep0pt
\fbox{\begin{tabular}[t]{r|l}
    Probability & Region \\ \hline
    0.0077 & -3 \\ \hline
    0.0462 & -2 \\ \hline
    0.2462 & -1
  \end{tabular}}}
\end{enumerate}
\end{document}

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.