现在看起来很乱。我该如何实现以下目标:
图片标题位于图片下方中央,表格标题位于表格下方中央。两个标题的垂直高度相同。表格垂直居中,与图片高度一致。
\documentclass[12pt,oneside,ngerman,reqno,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm} % ams stuff should be before font loading
\usepackage{lmodern}
\usepackage[T1]{fontenc} % should be after font loading
\usepackage{fixltx2e,babel}
\usepackage[numbers]{natbib} % bibtex package
%\usepackage{typearea} % custom type area
% \areaset[0mm]{135mm}{210mm} % typearea configuration
% \topmargin5mm % typearea configuration
\usepackage{graphicx}
\usepackage{url}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{subfig}
\usepackage{pgfplots}
\begin{document}
\begin{minipage}{\textwidth}
\begin{minipage}[b]{0.40\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel=Züge$\text{[}\#\text{]}$,
ylabel=Zeit$\text{[}s\text{]}$,
axis y line=center,
grid=both,
axis x line=center,
ymax=2000,
symbolic x coords = {10, 20, 50, 100, 200,500,1000,2000}]
\addplot[color=red,mark=*,style=dashed] coordinates {
(10,25)
(20,12)
(50,33)
(100,1800)
(200,1800)
(500,1800)
(1000,509)
(2000,1514)
};
\end{axis}
\end{tikzpicture}
\captionof{figure}{A table beside a figure}
\end{minipage}
\hfill
\begin{minipage}[b]{0.40\textwidth}
\centering
\begin{tabularx}{\textwidth}{c|c|c}
Züge[\#] & Zeit[s] & Lücke[\%]\\ \hline \hline
10 & 25 & 0.00 \\
20 & 12 & 0.00 \\
50 & 333 & 0.00 \\
100 & 1800 & 1.92 \\
200 & 1800 & 1.08 \\
500 & 1800 & 21.37 \\
1000 & 509 & 0.00\\
2000 & 1514 & 0.00 \\ \hline
\end{tabularx}
\captionof{table}{A table beside a figure}
\end{minipage}
\end{minipage}
\end{document}
答案1
使用包的解决方案floatrow
。我使用几何包调整了边距,但您也可以调整表格或图形。此外,我加载了siunitx
适当的数字对齐方式,makecell
使行与行之间有更好的垂直间距,并在表格底部使用更粗的水平线(booktabs
不适用于垂直线):
\documentclass[12pt,oneside,ngerman,reqno,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm} % ams stuff should be before font loading
\usepackage{lmodern}
\usepackage[T1]{fontenc} % should be after font loading
\usepackage{fixltx2e,babel}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{floatrow}
\usepackage{hhline, array, makecell}
\setcellgapes{4pt}
\makegapedcells
\usepackage[showframe, margin = 25mm]{geometry}
\usepackage{siunitx}
\newcolumntype{I}{S[table-format=4.0]}
\begin{document}
\begin{figure}\CenterFloatBoxes
\begin{floatrow}
\ffigbox[\FBwidth]
{ \caption{A figure beside a table}\label{figuretab}}
{ \begin{tikzpicture}
\begin{axis}[
xlabel=Züge$\text{[}\#\text{]}$,
ylabel=Zeit$\text{[}s\text{]}$,
axis y line=center,
grid=both,
axis x line=center,
ymax=2000,
symbolic x coords = {10, 20, 50, 100, 200,500,1000,2000}]
\addplot[color=red,mark=*,style=dashed] coordinates {
(10,25)
(20,12)
(50,33)
(100,1800)
(200,1800)
(500,1800)
(1000,509)
(2000,1514)
};
\end{axis}
\end{tikzpicture}}%
\ffigbox[1.08\FBwidth][1.25\FBheight]{\captionof{table}{A table beside a figure}\label{tablefig}}
{\begin{tabular}{@{}I|I|S[table-format = 2.2]@{}}
{Züge\,[\#]} & {Zeit\,[s]} &{ Lücke\,[\%]} \\
\hhline{ >{\arrayrulewidth = 2pt}:=:=:=:}
10 & 25 & 0.00 \\
20 & 12 & 0.00 \\
50 & 333 & 0.00 \\
100 & 1800 & 1.92 \\
200 & 1800 & 1.08 \\
500 & 1800 & 21.37 \\
1000 & 509 & 0.00\\
2000 & 1514 & 0.00 \\
\Xhline{0.8pt}
\end{tabular}}%
\end{floatrow}
\end{figure}
\end{document}
答案2
这可能是您想要的吗?您需要一个\noindent
,并且图形需要稍微缩小以适合页边距。此外,我使用堆栈来对齐标题并拨入表格的垂直偏移以实现居中外观。
\documentclass[12pt,oneside,ngerman,reqno,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm} % ams stuff should be before font loading
\usepackage{lmodern}
\usepackage[T1]{fontenc} % should be after font loading
\usepackage{fixltx2e,babel}
\usepackage[numbers]{natbib} % bibtex package
%\usepackage{typearea} % custom type area
% \areaset[0mm]{135mm}{210mm} % typearea configuration
% \topmargin5mm % typearea configuration
\usepackage{graphicx}
\usepackage{url}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{subfig}
\usepackage{pgfplots}
\usepackage{stackengine,lipsum}
\newsavebox\tmpbox
\begin{document}
\lipsum[1]\par\bigskip
\noindent\begin{minipage}{\textwidth}
\begin{minipage}[b]{.4\textwidth}
\centering
\sbox{\tmpbox}{\begin{tikzpicture}
\begin{axis}[
xlabel=Züge$\text{[}\#\text{]}$,
ylabel=Zeit$\text{[}s\text{]}$,
axis y line=center,
grid=both,
axis x line=center,
ymax=2000,
symbolic x coords = {10, 20, 50, 100, 200,500,1000,2000}]
\addplot[color=red,mark=*,style=dashed] coordinates {
(10,25)
(20,12)
(50,33)
(100,1800)
(200,1800)
(500,1800)
(1000,509)
(2000,1514)
};
\end{axis}
\end{tikzpicture}}
\setbox0=\vbox{\captionof{figure}{A table beside a figure}}
\stackon{\box0}{\scalebox{.8}{\usebox{\tmpbox}}}
\end{minipage}
\hfill
\begin{minipage}[b]{0.40\textwidth}
\centering
\sbox{\tmpbox}{\begin{tabularx}{\textwidth}{c|c|c}
Züge[\#] & Zeit[s] & Lücke[\%]\\ \hline \hline
10 & 25 & 0.00 \\
20 & 12 & 0.00 \\
50 & 333 & 0.00 \\
100 & 1800 & 1.92 \\
200 & 1800 & 1.08 \\
500 & 1800 & 21.37 \\
1000 & 509 & 0.00\\
2000 & 1514 & 0.00 \\ \hline
\end{tabularx}}
\setbox0=\vbox{\captionof{table}{A table beside a figure}}
\stackon[17pt]{\box0}{\usebox{\tmpbox}}
\end{minipage}
\end{minipage}\par
\medskip
\lipsum[2]
\end{document}