Como posso alinhar corretamente duas minipáginas em uma tabela?

Como posso alinhar corretamente duas minipáginas em uma tabela?

Tenho uma mesa e quero colocar duas legendas embaixo dela. Estas são minipáginas (não encontrei outra maneira de fazer isso), mas estou tendo dificuldade em alinhá-las no centro da página e na mesma altura. vspace e hspace não movem a minipágina em questão para cima ou para baixo (ou para a esquerda ou para a direita), mas fazem as coisas saltarem pela página de forma imprevisível. Como posso alinhá-los corretamente.

\documentclass{article}
\usepackage[table]{xcolor}
\def\hbar#1#2{%%
   {\color{#2}\rule{4mm}{#1mm}}}
\def\legbox#1#2{%%
   {\color{#1}\rule{4mm}{4mm}} \hspace{0.4mm}#2 \hspace{3mm}\\}

\begin{document}

\begin{figure}[h!]
  \vspace*{-4.0cm}
  \hspace*{-4.2cm}
  \centering
  {\setlength{\extrarowheight}{50pt}%
  \begin{tabular}{lllccl}
  \arrayrulecolor{gray}\hline
  \hline
    Item Description Name & Most Recent Update & State District & Governmental Body & Bars & More bars \\
    \hline
      Item 1 & Jan 1, 2010 & District 1 & GB 3 &
      \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
      \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
      \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}    \\   
      Item 2 & Jan 1, 2010 & District 1 & GB 3 &
      \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
      \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
      \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}      \\ 
      Item 3 & Jan 1, 2010 & District 1 & GB 3 &
      \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
      \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
      \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}       \\
      Item 4 & Jan 1, 2010 & District 1 & GB 3 &
      \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
      \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
      \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}       \\
      Item 5 & Jan 1, 2010 & District 1 & GB 3 &
      \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
      \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
      \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}       \\
  \end{tabular}
  }
  \caption{Here goes a table caption to describe the table}
\hspace{-10cm}
\begin{minipage}[t]{5cm}
\vspace{1cm}
 \textbf{Legend 1} \\
\legbox{black}{Long Label 1}
\legbox{blue}{Label 2}
\legbox{black}{Long Label 3}
\legbox{blue}{Label 4}
\legbox{black}{Long Label 5}
\legbox{blue}{Label 6}
\legbox{black}{Long Label 7}
\end{minipage}

\begin{minipage}{6cm}
\hspace{8cm}
\vspace{-4.7cm}
\\\textbf{Legend 2} \\

\legbox{blue}{Another label}
\legbox{black}{Mini}
\legbox{green}{A pretty long label}
\legbox{green}{A label}
\end{minipage}

\end{figure}
\end{document}

Aqui está como parece:

Layout atual

E aqui está como eu gostaria que fosse (linha apenas para fins ilustrativos):

Layout preferido

Responder1

Talvez seja isso que você espera:

\documentclass{article}
\usepackage[table]{xcolor}
\def\hbar#1#2{%%
   {\color{#2}\rule{4mm}{#1mm}}}
\def\legbox#1#2{%%
   {\color{#1}\rule{4mm}{4mm}} \hspace{0.4mm}#2 \hspace{3mm}\\}

\begin{document}

\begin{figure}[h!]
  \centering
  \makebox[0pt]
  {%%
    \setlength{\extrarowheight}{50pt}%
    \begin{tabular}{lllccl}
    \arrayrulecolor{gray}\hline
    \hline
      Item Description Name & Most Recent Update & State District & Governmental Body & Bars & More bars \\
      \hline
        Item 1 & Jan 1, 2010 & District 1 & GB 3 &
        \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
        \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
        \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}    \\   
        Item 2 & Jan 1, 2010 & District 1 & GB 3 &
        \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
        \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
        \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}      \\ 
        Item 3 & Jan 1, 2010 & District 1 & GB 3 &
        \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
        \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
        \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}       \\
        Item 4 & Jan 1, 2010 & District 1 & GB 3 &
        \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
        \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
        \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}       \\
        Item 5 & Jan 1, 2010 & District 1 & GB 3 &
        \hbar{14}{green} \hbar{20}{green} \hbar{10}{green} \hbar{15}{red}
        \hbar{19}{red} \hbar{6}{red} \hbar{10}{red}  &
        \hbar{15}{red} \hbar{19}{red} \hbar{6}{red}       \\
    \end{tabular}
  }
  \caption{Here goes a table caption to describe the table}
  \vspace{2ex}\par
  \begin{minipage}[t]{5cm}
    {\centering\textbf{Legend 1}}%%

    \legbox{black}{Long Label 1}
    \legbox{blue}{Label 2}
    \legbox{black}{Long Label 3}
    \legbox{blue}{Label 4}
    \legbox{black}{Long Label 5}
    \legbox{blue}{Label 6}
    \legbox{black}{Long Label 7}
  \end{minipage}%%
  \hspace{\fill}
  \begin{minipage}[t]{6cm}
    {\centering\textbf{Legend 2}}%%

    \legbox{blue}{Another label}
    \legbox{black}{Mini}
    \legbox{green}{A pretty long label}
    \legbox{green}{A label}
  \end{minipage}%%
\end{figure}
\end{document}

insira a descrição da imagem aqui

Sou capaz de eliminar a maioria dos seus comandos \hspacee \vspace.

Sua tabela é maior do que a geometria da página permite. Você pode centralizá-lo na página colocando seu corpo em uma largura \makeboxmaior 0pt. Essencialmente, substituo seu código:

\begin{figure}[h!]
  \vspace*{-4.0cm}
  \hspace*{-4.2cm}
  \centering
  {\setlength{\extrarowheight}{50pt}%

com o seguinte código:

\begin{figure}[h!]
  \centering
  \makebox[0pt]
  {%%
    \setlength{\extrarowheight}{50pt}%

Você também está usando \hspacemuito \vspacesuas lendas de uma maneira que parece desnecessária. Aqui estão alguns ajustes que fiz:

  • Depois \captionadicionei um espaço vertical para controlar melhor o espaço entre a legenda e as legendas em vez de adicionar o espaço vertical dentro dos minipages.
  • Dentro da minipagelegenda, não tenho certeza do que você está tentando realizar com seus comandos \hspacee . \vspaceParece que você pode evitá-los completamente fazendo uma quebra de parágrafo entre o título e o corpo da legenda e centralizando o título.

Responder2

A tabela, como está, não pode caber em nenhuma largura de página razoável, então a reduzi.

Para a legenda, basta usar alguns arquivos tabular.

Também mudei \defpara \newcommande \hbarpara \HBarnão entrar em conflito com um comando já existente. Sermuitocuidado com \def.

\documentclass{article}
\usepackage{booktabs,makecell}
\usepackage[table]{xcolor}

\newcommand\HBar[2]{%%
   {\color{#2}\rule{3mm}{#1mm}}%
}
\newcommand\legbox[2]{%%
   {\color{#1}\rule{4mm}{4mm}}\hspace{0.4mm}#2\hspace{3mm}%
}

\begin{document}

\begin{figure}[htp]
\centering
\begingroup\small
\addtolength{\tabcolsep}{-2.8pt}
\begin{tabular}{@{}lllccc@{}}
\toprule
\makecell{Item \\ Description \\ Name} &
  \makecell{Most Recent \\ Update} &
  \makecell{State \\ District} &
  \makecell{Governmental \\ Body} &
  Bars &
  More bars \\
\midrule
\addlinespace
Item 1 & Jan 1, 2010 & District 1 & GB 3 &
\HBar{14}{green} \HBar{20}{green} \HBar{10}{green} \HBar{15}{red}
\HBar{19}{red} \HBar{6}{red} \HBar{10}{red}  &
\HBar{15}{red} \HBar{19}{red} \HBar{6}{red}    \\
\addlinespace
Item 2 & Jan 1, 2010 & District 1 & GB 3 &
\HBar{14}{green} \HBar{20}{green} \HBar{10}{green} \HBar{15}{red}
\HBar{19}{red} \HBar{6}{red} \HBar{10}{red}  &
\HBar{15}{red} \HBar{19}{red} \HBar{6}{red}      \\ 
\addlinespace
Item 3 & Jan 1, 2010 & District 1 & GB 3 &
\HBar{14}{green} \HBar{20}{green} \HBar{10}{green} \HBar{15}{red}
\HBar{19}{red} \HBar{6}{red} \HBar{10}{red}  &
\HBar{15}{red} \HBar{19}{red} \HBar{6}{red}       \\
\addlinespace
Item 4 & Jan 1, 2010 & District 1 & GB 3 &
\HBar{14}{green} \HBar{20}{green} \HBar{10}{green} \HBar{15}{red}
\HBar{19}{red} \HBar{6}{red} \HBar{10}{red}  &
\HBar{15}{red} \HBar{19}{red} \HBar{6}{red}       \\
\addlinespace
Item 5 & Jan 1, 2010 & District 1 & GB 3 &
\HBar{14}{green} \HBar{20}{green} \HBar{10}{green} \HBar{15}{red}
\HBar{19}{red} \HBar{6}{red} \HBar{10}{red}  &
\HBar{15}{red} \HBar{19}{red} \HBar{6}{red}       \\
\bottomrule
\end{tabular}
\endgroup

\caption{Here goes a table caption to describe the table}

\bigskip

\begin{tabular}[t]{@{}l@{}}
\multicolumn{1}{c}{\textbf{Legend 1}} \\
\legbox{black}{Long Label 1} \\
\legbox{blue}{Label 2} \\
\legbox{black}{Long Label 3} \\
\legbox{blue}{Label 4} \\
\legbox{black}{Long Label 5} \\
\legbox{blue}{Label 6} \\
\legbox{black}{Long Label 7} \\
\end{tabular}%
\hspace{1cm}
\begin{tabular}[t]{@{}l@{}}
\multicolumn{1}{c}{\textbf{Legend 2}} \\
\legbox{blue}{Another label} \\
\legbox{black}{Mini} \\
\legbox{green}{A pretty long label} \\
\legbox{green}{A label} \\
\end{tabular}

\end{figure}
\end{document}

insira a descrição da imagem aqui

informação relacionada