如何对齐两个表格

如何对齐两个表格
\begin{document}
%first table
\renewcommand{\arraystretch}{1.1}
\centering
  \begin{tabular}{r l l}
  \hline \hline 
    \rowcolor[RGB]{77,77,77}\color {white}BAZA & \color{white}BROJNI SISTEM & \color {white}CIFRE \\ \hline \hline
  \rowcolor[RGB]{255,255,255} 2 &  Binarni C & 0,1 \\
  \rowcolor[RGB]{242,242,242} 3 &  Ternarni & 0,1,2 \\
  \rowcolor[RGB]{255,255,255} 5 &  Kvinarni & 0,1,...,4 \\
  \rowcolor[RGB]{242,242,242} 8 &  Oktalni & 0,1,...,7 \\
  \rowcolor[RGB]{255,255,255} 10  & Dekadski & 0,1,...,9 \\
 \rowcolor[RGB]{242,242,242} 12 & Duodekadni & o,1,...,9,$\alpha,\beta$ \\
  \rowcolor[RGB]{255,255,255} 16 &  Heksadecimalni & 0,1,...,9,A,...,F \\\hline \hline
  \end{tabular}\\
%2nd table
\renewcommand{\arraystretch}{1.1}
\centering
\begin{tabular}{|l|c|r|}
  \hline \hline
    \cellcolor[RGB]{204,255,204}L1 & L2 & L3 \\ \hline 
 \multirow{2}{*}{MR2} & \multicolumn{2}{c|}{MC2} \\ \cline{2-2} & D & \cellcolor[RGB]{255,230,204}E \\ \hline
  G & \cellcolor[RGB]{255,204,204}E & M \\ \hline
  \multicolumn{2}{|c|}{\cellcolor[RGB]{204,204,255}MC1} & \multirow{2}{*}{MR1}  \\ \cline{1-2}
  A & B &  \\\hline \hline
  \end{tabular}\\
\end{document}

我怎样才能像图片中这样垂直对齐这两个表 2

答案1

您需要一个table环境中的两个小页面。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[bosnian]{babel}

\usepackage[table]{xcolor}
\usepackage{multirow}

\begin{document}
%first table

\begin{table}[htp]
\renewcommand{\arraystretch}{1.1}

\begin{minipage}{0.65\textwidth}
\centering

\begin{tabular}{r l l}
\hline \hline 
\rowcolor[RGB]{77,77,77}
\color{white}BAZA &
\color{white}BROJNI SISTEM &
\color {white}CIFRE \\
\hline \hline
\rowcolor[RGB]{255,255,255} 2 &  Binarni C & 0,1 \\
\rowcolor[RGB]{242,242,242} 3 &  Ternarni & 0,1,2 \\
\rowcolor[RGB]{255,255,255} 5 &  Kvinarni & 0,1,\dots,4 \\
\rowcolor[RGB]{242,242,242} 8 &  Oktalni & 0,1,\dots,7 \\
\rowcolor[RGB]{255,255,255} 10  & Dekadski & 0,1,\dots,9 \\
\rowcolor[RGB]{242,242,242} 12 & Duodekadni & o,1,\dots,9,$\alpha,\beta$ \\
\rowcolor[RGB]{255,255,255} 16 &  Heksadecimalni & 0,1,\dots,9,A,\dots,F \\
\hline \hline
\end{tabular}

\caption{Pozicioni brojni sistem}
\end{minipage}%
\hfill
\begin{minipage}{0.35\textwidth}
\centering

\begin{tabular}{|l|c|r|}
\hline \hline
\cellcolor[RGB]{204,255,204}L1 & L2 & L3 \\
\hline 
\multirow{2}{*}{MR2} &
\multicolumn{2}{c|}{MC2} \\
\cline{2-2}
& D & \cellcolor[RGB]{255,230,204}E \\
\hline
G & \cellcolor[RGB]{255,204,204}E & M \\
\hline
\multicolumn{2}{|c|}{\cellcolor[RGB]{204,204,255}MC1} & \multirow{2}{*}{MR1}  \\
\cline{1-2}
A & B & \\
\hline \hline
\end{tabular}

\caption{Spajanje ćelija}
\end{minipage}

\end{table}

\end{document}

在此处输入图片描述

答案2

这个答案与 egreg 的答案相同,但我想表明,使用{NiceTabular}nicematrix您将在 PDF 查看器中获得更好的表格输出(您不会在第一个表格中看到细白线,并且某些规则似乎不会在第二个表格中消失)。

\documentclass{book}
\usepackage[left=3cm,right=3cm]{geometry}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{nicematrix}
\usepackage{float}

\begin{document}

\lipsum[1]

\begin{table}[htp]
\renewcommand{\arraystretch}{1.1}
\begin{minipage}{0.5\textwidth}
\centering
\begin{tabular}{@{}c@{}}
    \hline\noalign{\vspace{\dimexpr\doublerulesep-\arrayrulewidth}}
    \begin{NiceTabular}{rll}
    \CodeBefore
      \rowcolor[RGB]{77,77,77}{1}
      \rowcolors[RGB]{2}{242,242,242}{}
    \Body
    \hline 
    \color{white}BAZA & \color{white}BROJNI SISTEM & \color{white}CIFRE \\ \hline \hline
    2 &  Binarni C & 0,1 \\
    3 &  Ternarni & 0,1,2 \\
    5 &  Kvinarni & 0,1,...,4 \\
    8 &  Oktalni & 0,1,...,7 \\
    10  & Dekadski & 0,1,...,9 \\
    12 & Duodekadni & 0,1,...,9,$\alpha,\beta$ \\
    16 &  Heksadecimalni & 0,1,...,9,A,...,F \\
    \hline 
    \end{NiceTabular} \\ \noalign{\vspace{\dimexpr\doublerulesep-\arrayrulewidth}}
    \hline
\end{tabular}
\caption{Pozicioni bronji}
\end{minipage}\ignorespaces\hspace{12pt}\ignorespaces
%2nd table
\begin{minipage}[t]{0.5\textwidth}
\centering
\begin{tabular}{@{}c@{}}
    \hline\noalign{\vspace{\dimexpr\doublerulesep-\arrayrulewidth}}
    \begin{NiceTabular}{lcr}[colortbl-like,hvlines]
    \cellcolor[RGB]{204,255,204}L1 & L2 & L3 \\ 
    \Block{2-1}{MR2} & \Block{1-2}{MC2} \\ 
    & D & \cellcolor[RGB]{255,230,204}E \\ 
    G & \cellcolor[RGB]{255,204,204}E & M \\ 
    \Block[fill=[RGB]{204,204,255}]{1-2}{MC1} & & \Block{2-1}{MR1}  \\ 
    A & B &  \\
    \end{NiceTabular} \\
    \hline
\end{tabular}
\caption{Spajanje deijia}
\end{minipage}
\end{table}
\end{document}

上述代码的输出

答案3

希望这会对你有帮助:

\documentclass{book}
\usepackage{xcolor}
\usepackage{multirow,colortbl}
\usepackage{float}
\begin{document}
%first table
\begin{minipage}[t]{0.65\textwidth}
\begin{table}[H]
\renewcommand{\arraystretch}{1.1}
\centering
  \begin{tabular}{r l l}
  \hline \hline 
    \rowcolor[RGB]{77,77,77}\color {white}BAZA & \color{white}BROJNI SISTEM & \color {white}CIFRE \\ \hline \hline
  \rowcolor[RGB]{255,255,255} 2 &  Binarni C & 0,1 \\
  \rowcolor[RGB]{242,242,242} 3 &  Ternarni & 0,1,2 \\
  \rowcolor[RGB]{255,255,255} 5 &  Kvinarni & 0,1,...,4 \\
  \rowcolor[RGB]{242,242,242} 8 &  Oktalni & 0,1,...,7 \\
  \rowcolor[RGB]{255,255,255} 10  & Dekadski & 0,1,...,9 \\
 \rowcolor[RGB]{242,242,242} 12 & Duodekadni & o,1,...,9,$\alpha,\beta$ \\
  \rowcolor[RGB]{255,255,255} 16 &  Heksadecimalni & 0,1,...,9,A,...,F \\\hline \hline
  \end{tabular}
\caption{Pozicioni bronji}
\end{table}
\end{minipage}\ignorespaces\hspace{12pt}\ignorespaces
%2nd table
\begin{minipage}[t]{0.35\textwidth}
\begin{table}[H]
\renewcommand{\arraystretch}{1.1}
\centering
\begin{tabular}{|l|c|r|}
  \hline \hline
    \cellcolor[RGB]{204,255,204}L1 & L2 & L3 \\ \hline 
 \multirow{2}{*}{MR2} & \multicolumn{2}{c|}{MC2} \\ \cline{2-2} & D & \cellcolor[RGB]{255,230,204}E \\ \hline
  G & \cellcolor[RGB]{255,204,204}E & M \\ \hline
  \multicolumn{2}{|c|}{\cellcolor[RGB]{204,204,255}MC1} & \multirow{2}{*}{MR1}  \\ \cline{1-2}
  A & B &  \\\hline \hline
  \end{tabular}
\caption{Spajanje deijia}
\end{table}
\end{minipage}
\end{document}

由于您没有提到任何类文件名,因此我使用标准文件名......

相关内容