Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have one table with 2 minipages. I wish to top align the two minipages.

e.g.

\documentclass{standalone}
\usepackage{adjustbox}
\begin{document}

\begin{tabular}{|l|l|} \hline
    \begin{minipage}{.5\linewidth}
        \begin{tabular}{|l|l|} \hline
            1 & 2 \\ \hline
            3 & 4 \\ \hline
            5 & 6 \\ \hline
        \end{tabular}
    \end{minipage} &

    \begin{minipage}{.5\linewidth}
        \begin{tabular}{|l|l|} \hline
            7 & 8 \\ \hline
        \end{tabular}
    \end{minipage} \\ \hline
\end{tabular}

\end{document}

Now the output is as below:

enter image description here

How can we align the second minipage on top? That means "7 8" line aligned with "1 2" line.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

It's not clear to me why you have minipage environments encasing tabular environments. Here's a solution that dispenses with the minipages and top-aligns two tabular environments within a tabularx environment.

To avoid overlaps between the \hlines drawn by the outer tabularx and the inner tabular environments, I've omitted some of your \hline instructions from the inner environments. If you decide to get rid of the outer \hlines, be sure to re-insert the \hlines in the inner tabulars.

enter image description here

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{@{}X@{}X@{}}
  \hline
  \begin{tabular}[t]{|l|l|} 
      1 & 2 \\ \hline
      3 & 4 \\ \hline
      5 & 6 
    \end{tabular}
    &
    \begin{tabular}[t]{|l|l|} 
      7 & 8 \\ \hline
    \end{tabular}\\ \hline
\end{tabularx}
\end{document}

Next, here's a version with three vertical bars drawn by the outer tabularx (far left, middle, and right). To avoid overlap of the vertical lines drawn by the inner and outer table-like environments, it may again be a good idea to omit the first vertical bar from each of the inner tabulars.

enter image description here

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|@{}X|@{}X@{}|}
  \hline
  \begin{tabular}[t]{l|l|} 
      1 & 2 \\ \hline
      3 & 4 \\ \hline
      5 & 6 
    \end{tabular}
    &
    \begin{tabular}[t]{l|l|} 
      7 & 8 \\ \hline
    \end{tabular}\\ \hline
\end{tabularx}
\end{document}

Finally, for the sake of completeness, here's the code that's needed if you wish to use minipage environments after all to typeset the preceding example. Note that it's necessary to use the [t] position specifier for both minipages and both tabulars in order to get the vertical alignment just right. (Not showing a separate screenshot since the result is identical to the one above.)

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|@{}X|@{}X@{}|}
    \hline
    \begin{minipage}[t]{\linewidth}
    \begin{tabular}[t]{l|l|} 
        1 & 2 \\ \hline
        3 & 4 \\ \hline
        5 & 6 
    \end{tabular}
    \end{minipage}
    &
    \begin{minipage}[t]{\linewidth}
    \begin{tabular}[t]{l|l|} 
        7 & 8 \\ \hline
    \end{tabular} 
    \end{minipage}\\
    \hline
\end{tabularx}
\end{document}
share|improve this answer
    
Thanks, I am extract the simple example from a complicate case, so use minipage here. I will try to remove it. now use tabularx package, it works for me. –  Beatlej Sep 1 at 2:03

Not exactly your setup, but it works this way:

\documentclass{article}
\usepackage{array,showframe}   %% remove show frame
\begin{document}
\noindent
{\fboxsep0pt
\fboxrule0.4pt
\fbox{\parbox[t]{\textwidth}{%
        \hspace*{0.5\tabcolsep}
        \begin{tabular}[t]{|l|l|} \hline
            1 & 2 \\ \hline
            3 & 4 \\ \hline
            5 & 6 \\ \hline
        \end{tabular}
        \hfil \vrule\hspace{0.5\tabcolsep}
        \begin{tabular}[t]{|l|l|} \hline
            7 & 8 \\ \hline
        \end{tabular}}}
}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.