将不同大小的图表和表格并排居中

将不同大小的图表和表格并排居中

我是乳胶的新手,我正在尝试弄清楚如何将这两个中心对齐在一起。

以下是我所拥有的:

在此处输入图片描述

这是我的目标: 在此处输入图片描述

我的代码如下。

\documentclass{article}
\usepackage{geometry}

\usepackage{natbib}
\usepackage{setspace}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
%\usepgfplotslibrary{external}
%\tikzexternalize

\usepackage{caption}
\usepackage[rawfloats=true]{floatrow}%

\begin{document}


\begin{figure}[!h]
\begin{floatrow}
\floatsetup{heightadjust=all, valign=c}
    \begin{tikzpicture}
        \begin{axis}[
            symbolic x coords={1,2,3,4,5,6,7,8,9},
            xtick=data, ylabel=\textit{P(d)}
          ]
        \addplot[ybar,fill=blue] coordinates {
            (1,   30.1)
            (2,  17.6)
            (3,   12.5)
            (4,   9.7)
            (5,  7.9)
            (6,   6.7)
            (7,   5.8)
            (8,  5.1)
            (9,   4.6)
        };
    \end{axis}
\end{tikzpicture}

\begin{tabular}[b]{cc}\hline
      \hline            
      1 & 30.1 \\
      2 & 17.6 \\
      3 & 12.5 \\
      4 & 9.7 \\
      5 & 7.9 \\
      6 & 6.7 \\
      7 & 5.8 \\
      8 & 5.1 \\
      9 & 4.6 \\
      \hline  
\end{tabular}

\end{floatrow}
\end{figure}

\end{document}

先感谢您!

答案1

通过使用tabularx并在图像中心定义基线:

在此处输入图片描述

(红线表示页面布局)

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{tabularx}               % <-- new
\usepackage{siunitx}                % <-- new

\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9} % <-- it is very old, try to upgrade to 1.16!
%\usepgfplotslibrary{external}      % not used
%\tikzexternalize                   % not used


%-------------------------------------- only for show page layout
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.25pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}[htb]
\centering
\begin{tabularx}{0.9\linewidth}{p{10cm} >{\centering\arraybackslash}X}
    \begin{tikzpicture}[baseline=(current bounding box.center)]
        \begin{axis}[
            symbolic x coords={1,2,3,4,5,6,7,8,9},
            xtick=data, ylabel=\textit{P(d)}
                    ]
        \addplot[ybar,fill=blue] coordinates {
            (1,   30.1)
            (2,  17.6)
            (3,   12.5)
            (4,   9.7)
            (5,  7.9)
            (6,   6.7)
            (7,   5.8)
            (8,  5.1)
            (9,   4.6)
        };
    \end{axis}
\end{tikzpicture}
    &
        \begin{tabular}{cS[table-format=2.1]}
      \hline
      1 & 30.1 \\
      2 & 17.6 \\
      3 & 12.5 \\
      4 & 9.7 \\
      5 & 7.9 \\
      6 & 6.7 \\
      7 & 5.8 \\
      8 & 5.1 \\
      9 & 4.6 \\
      \hline
    \end{tabular}   \\
\caption{My figure}
    &
    \captionof{table}{My table}
\end{tabularx}
    \end{figure}
\end{document}

相关内容