![我的定心命令不起作用!为什么?](https://linux22.com/image/314554/%E6%88%91%E7%9A%84%E5%AE%9A%E5%BF%83%E5%91%BD%E4%BB%A4%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%EF%BC%81%E4%B8%BA%E4%BB%80%E4%B9%88%EF%BC%9F.png)
我将使用以下命令绘制条形直方图:
\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}, 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{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
包,因此显示了文本块的边界。