我正在尝试将由 tabular 环境生成的表格和由 TikZ 生成的图并排放置。我尝试使用 table 和 minipage 环境,因为它可以并排放置多个表格。但是这两个对象似乎垂直偏离,我做错了什么?
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage{pgfplots}
\begin{document}
\begin{table}
\begin{minipage}[b]{5 cm}
\centering
\begin{tabular}{|c|c|}
\hline
Temperature & IQ Score \\ \hline
14\celsius & 57\% \\ \hline
16\celsius & 65\% \\ \hline
18\celsius & 69\% \\ \hline
20\celsius & 71\% \\ \hline
22\celsius & 79\% \\ \hline
24\celsius & 88\% \\ \hline
26\celsius & 81\% \\ \hline
28\celsius & 76\% \\ \hline
30\celsius & 66\% \\ \hline
32\celsius & 62\% \\
\hline
\end{tabular}
\end{minipage}
\hspace{1cm}
\begin{minipage}[b]{10cm}
\centering
\begin{tikzpicture}
\begin{axis}[grid=major, grid style={dashed,gray!30}, xlabel=Temperature $\celsius$,ylabel=IQ Scores \%, legend style={at={(axis cs:25,28)},anchor=south}]
%\addplot[scatter, only marks, scatter/classes={y={black}}] table[x=x, y=y, col sep=comma] {NumbersAndFunctions-Temp-IQ-data.csv};
\addplot[color=red, domain=7:41, thick, samples=400, mark=none] {88*exp(-(\x-24)^2/253.0889)};
\legend{Raw, Gaussian};
\end{axis}
\end{tikzpicture}
\end{minipage}
\end{table}
\end{document}
谢谢
答案1
这些在顶部对齐:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=8cm}
\usepackage{siunitx}
\begin{document}
\begin{table}
\begin{minipage}[t]{5 cm}
\centering
\begin{tabular}[t]{|c|c|}
\hline
Temperature & IQ Score \\ \hline
\SI{14}{\celsius} & \SI{57}{\percent} \\ \hline %% change all \% like this
\SI{16}{\celsius} & 65\% \\ \hline
\SI{18}{\celsius} & 69\% \\ \hline
\SI{20}{\celsius} & 71\% \\ \hline
\SI{22}{\celsius} & 79\% \\ \hline
\SI{24}{\celsius} & 88\% \\ \hline
\SI{26}{\celsius} & 81\% \\ \hline
\SI{28}{\celsius} & 76\% \\ \hline
\SI{30}{\celsius} & 66\% \\ \hline
\SI{32}{\celsius} & 62\% \\
\hline
\end{tabular}
\end{minipage}
\hfill
\begin{tikzpicture}[baseline={(current bounding box.north)}]
\begin{axis}[grid=major, grid style={dashed,gray!30}, xlabel=Temperature $\celsius$,ylabel=IQ Scores\si{\percent}, legend style={at={(axis cs:25,28)},anchor=south}]
%\addplot[scatter, only marks, scatter/classes={y={black}}] table[x=x, y=y, col sep=comma] {NumbersAndFunctions-Temp-IQ-data.csv};
\addplot[color=red, domain=7:41, thick, samples=400, mark=none] {88*exp(-(\x-24)²/253.0889)};
\addlegendentry{Raw,Gaussian};
\end{axis}
\end{tikzpicture}
\end{table}
\end{document}
由于没有[t]
进minipage
和[baseline={(current bounding box.center)}]
进,tikzpicture
它们在中心对齐。
由于和中都没有[b
] ,因此它们在底部对齐。tabular
minipage
[baseline={(current bounding box.south)}]
tikzpicture