如何使双列文档中的单列pgfplots
/tikzpicture
条形图居中?
以下是示例文档。图表取自例子在 Overleaf。
\documentclass[twocolumn]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\begin{document}
% Some Text
\begin{tikzpicture}
\begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Year,
enlargelimits=0.05,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
ybar interval=.7,
]
\addplot
coordinates {(2012,408184) (2011,408348)
(2010,414870) (2009,412156) (2008,415 838)};
\addplot
coordinates {(2012,388950) (2011,393007)
(2010,398449) (2009,395972) (2008,398866)};
\legend{Men,Women}
\end{axis}
\end{tikzpicture}
% More Text
\end{document}
这是示例编译文档。显示了未对齐的图表。我确实希望图表位于单列中,但如您所见,图表未居中。(可能是因为左侧的 ylabel)。
答案1
将您的 tikzpicture 放在图形环境中,例如:
\begin{figure}[h]
\begin{tikzpicture}
...
\end{tikzpicture}
\end{figure}
完整代码:
\documentclass[twocolumn]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{lipsum}
\begin{document}
\lipsum[1] % Some text.
\begin{figure}[h]
\begin{tikzpicture}
\begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Year,
enlargelimits=0.05,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
ybar interval=.7,
]
\addplot
coordinates {(2012,408184) (2011,408348)
(2010,414870) (2009,412156) (2008,415 838)};
\addplot
coordinates {(2012,388950) (2011,393007)
(2010,398449) (2009,395972) (2008,398866)};
\legend{Men,Women}
\end{axis}
\end{tikzpicture}
\end{figure}
\lipsum[2]% Some text.
\end{document}