我无法让图和 pgfplotstabletypeset 对齐,使它们彼此紧挨着。这可能吗?请帮帮我。
目前的情况如下:
这是我的代码:
\begin{filecontents}{performance.data}
Konsumenten Sekunden
1 31.944
2 16.064
3 16.099
4 16.541
5 6.611
6 6.248
7 6.345
8 6.375
9 6.26
10 3.748
\end{filecontents}
\begin{flushright}
\begin{tikzpicture}
\begin{axis}
\addplot[color=black, mark=x] table[x=Konsumenten, y=Sekunden] {performance.data};
\end{axis}
\end{tikzpicture}
\end{flushright}
\begin{flushleft}
\pgfplotstabletypeset[
col sep=&,row sep=\\,
string type,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule}
]{
Konsumenten & Sekunden\\
1 & 31.944 \\
2 & 16.064 \\
3 & 16.099 \\
4 & 16.541 \\
5 & 6.611 \\
6 & 6.248 \\
7 & 6.345 \\
8 & 6.375 \\
9 & 6.26 \\
10 & 3.748 \\
}
\end{flushleft}
答案1
标准minipage
想法在这里起作用
为了将来,请务必发布完整的 MWE - 以下是其中一个例子:
% arara: pdflatex
% !arara: indent: {overwrite: on, trace: yes}
\begin{filecontents}{performance.data}
Konsumenten Sekunden
1 31.944
2 16.064
3 16.099
4 16.541
5 6.611
6 6.248
7 6.345
8 6.375
9 6.26
10 3.748
\end{filecontents}
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{colortbl}
\begin{document}
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}
\begin{axis}[width=\textwidth]
\addplot[color=black, mark=x] table[x=Konsumenten, y=Sekunden] {performance.data};
\end{axis}
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\pgfplotstabletypeset[
col sep=&,row sep=\\,
string type,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule}
]{
Konsumenten & Sekunden\\
1 & 31.944 \\
2 & 16.064 \\
3 & 16.099 \\
4 & 16.541 \\
5 & 6.611 \\
6 & 6.248 \\
7 & 6.345 \\
8 & 6.375 \\
9 & 6.26 \\
10 & 3.748 \\
}
\end{minipage}
\end{document}
如果你想要每个对象的标题,那么你可以将上面的代码放入环境minipage
中figure
,并使用caption
包的captionof
命令,如下所示。
% arara: pdflatex
% !arara: indent: {overwrite: on, trace: yes}
\begin{filecontents}{performance.data}
Konsumenten Sekunden
1 31.944
2 16.064
3 16.099
4 16.541
5 6.611
6 6.248
7 6.345
8 6.375
9 6.26
10 3.748
\end{filecontents}
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{caption}
\begin{document}
\begin{figure}[!htb]
\begin{minipage}{.5\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[width=\textwidth]
\addplot[color=black, mark=x] table[x=Konsumenten, y=Sekunden] {performance.data};
\end{axis}
\end{tikzpicture}
\caption{Figure caption here}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\captionof{table}{Table caption here}
\pgfplotstabletypeset[
col sep=&,row sep=\\,
string type,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule}
]{
Konsumenten & Sekunden\\
1 & 31.944 \\
2 & 16.064 \\
3 & 16.099 \\
4 & 16.541 \\
5 & 6.611 \\
6 & 6.248 \\
7 & 6.345 \\
8 & 6.375 \\
9 & 6.26 \\
10 & 3.748 \\
}
\end{minipage}
\end{figure}
\end{document}
答案2
或者,您可以设置 TikZ 图片的基线,或者您可以使用subcaption
包来获取单独的标题标签等。
\documentclass{article}
\usepackage{pgfplotstable,booktabs,colortbl}
\pgfplotsset{compat=1.8}
\pgfplotstableread{
Konsumenten Sekunden
1 31.944
2 16.064
3 16.099
4 16.541
5 6.611
6 6.248
7 6.345
8 6.375
9 6.26
10 3.748
}\mytable
\begin{document}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\begin{axis}[width=0.5\textwidth]
\addplot[color=black, mark=x] table[x=Konsumenten, y=Sekunden] {\mytable};
\end{axis}
\end{tikzpicture}
%
\hfill
%
\pgfplotstabletypeset[
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule}
]\mytable
\end{document}