我的定心命令不起作用!为什么?

我的定心命令不起作用!为什么?

我将使用以下命令绘制条形直方图:

\documentclass[a4paper]{report}‎
\usepackage{pgfplots}‎
\pgfplotsset{compat=newest}‎
\begin{document}‎
\begin{tikzpicture}‎
\centering‎
\begin{axis}[‎
 xbar,‎‎
 height=4.5cm,‎
 width=13cm,
 bar width=0.2cm,‎
 legend style={at={(0.5,-0.21)},‎
 enlarge x limits={upper,value=0.25},‎
 xmin=-2,xmax=110,‎
 anchor=north,legend columns=-1},‎
 ylabel={\ Data size}, ‎x‎label={\ Computation time(sec)},‎
 symbolic y coords={1024 by 1024‎,512 by 512,256 by 256},‎
  ytick=data,‎
  nodes near coords,‎
  nodes near coords align=horizontal,‎
  ]‎
  \addplot coordinates {(108.3,1024 by 1024) (14.22,512 by 512) (1.7,256 by 256)‎
  };‎
  \addplot coordinates {(3.5,1024 by 1024) (0.85,512 by 512) (0.21,256 by 256)‎
  };‎
  \legend{Conventional method,Butterfly-based method}‎
  \end{axis}‎
  \end{tikzpicture}‎
  \end{document}‎

但是我的直方图不在页面的中心,我的表格是这样的:

在此处输入图片描述

我怎样才能将其放置在页面左右两侧的中间位置?我怎样才能减少列之间的空间?

答案1

\centering之后\begin{tikzpicture}不执行任何操作:使用center环境,但也使用相对宽度,因为 13cm 对于文本宽度来说很可能太大。

\documentclass[a4paper]{report}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
 xbar,
 height=4.5cm,
 width=.8\textwidth, % <------- relative width
 bar width=0.2cm,
 legend style={at={(0.5,-0.21)},
 enlarge x limits={upper,value=0.25},
 xmin=-2,xmax=110,
 anchor=north,legend columns=-1},
 ylabel={\ Data size},
 xlabel={\ Computation time(sec)},
 symbolic y coords={1024 by 1024,512 by 512,256 by 256},
 ytick=data,
 nodes near coords,
 nodes near coords align=horizontal,
  ]
  \addplot coordinates {(108.3,1024 by 1024) (14.22,512 by 512) (1.7,256 by 256)
  };
  \addplot coordinates {(3.5,1024 by 1024) (0.85,512 by 512) (0.21,256 by 256)
  };
  \legend{Conventional method,Butterfly-based method}
  \end{axis}
\end{tikzpicture}
\end{center}
\end{document}

如果你有一个figure围绕情节的环境,那么你应该输入

\begin{figure}
\centering

\begin{tikzpicture}
...
\end{tikzpicture}

\caption{The caption}\label{thelabel}

\end{figure}

为了制作图片,我使用了该showframe包,因此显示了文本块的边界。

在此处输入图片描述

相关内容