因此,我正在使用 制作图表pgfplots
,但遇到了一个问题:它们在页面上居中效果不佳。我宁愿坚持使用article
以便于打印,这样我就可以在同一文档中拥有多个图表(例如,如果我有同一种化合物的多个光谱,最好将它们全部放在一个地方)。
但是,当我编译它时,图形并没有完全到达右边距,这很烦人。如何缩放图形以自动使用整个页面,但不让轴标签超出页面或类似情况?
我有一个 MWE,其中使用了我的一小部分数据。我还对其进行了精简(我通常使用外部文件来存储数据)并删除了标签等以使其最小化):
\documentclass[letterpaper]{article}
\usepackage[margin=0.5 in,landscape]{geometry}
\pagestyle{empty}
%Graphics stuff here
\usepackage{pgfplots} %For graphing data
\pgfplotsset
{
compat = newest,
every tick/.append style = thin,
width= 0.95 \textwidth,
height= 0.95\textheight
}
\pgfkeys{/pgf/number format/set thousands separator = }
%Science stuff here
\usepackage[]{siunitx} %Adds si units and others by name- See the manual.
\sisetup{mode = text}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
x dir = reverse,
xlabel = Frequency (\si{\per\centi\metre}),
title = Demo,
xticklabel style = {rotate=270},
yticklabels = {},
]
\addplot[color = black, mark = none]
coordinates {
( 3.983730e+003, 9.824165e+001 )
( 3.984213e+003, 9.854189e+001 )
( 3.984695e+003, 9.890483e+001 )
( 3.985177e+003, 9.878275e+001 )
( 3.985659e+003, 9.859460e+001 )
( 3.986141e+003, 9.835152e+001 )
( 3.986623e+003, 9.794798e+001 )
( 3.987105e+003, 9.803477e+001 )
( 3.987587e+003, 9.864641e+001 )
( 3.988070e+003, 9.895673e+001 )
( 3.988552e+003, 9.910266e+001 )
( 3.989034e+003, 9.866454e+001 )
( 3.989516e+003, 9.837458e+001 )
( 3.989998e+003, 9.857204e+001 )
( 3.990480e+003, 9.883611e+001 )
( 3.990962e+003, 9.891921e+001 )
( 3.991444e+003, 9.846350e+001 )
( 3.991927e+003, 9.804715e+001 )
( 3.992409e+003, 9.815513e+001 )
( 3.992891e+003, 9.844558e+001 )
( 3.993373e+003, 9.842175e+001 )
( 3.993855e+003, 9.843822e+001 )
( 3.994337e+003, 9.828293e+001 )
( 3.994819e+003, 9.791080e+001 )
( 3.995301e+003, 9.774442e+001 )
( 3.995783e+003, 9.783126e+001 )
( 3.996266e+003, 9.788599e+001 )
( 3.996748e+003, 9.826096e+001 )
( 3.997230e+003, 9.857933e+001 )
( 3.997712e+003, 9.843895e+001 )
( 3.998194e+003, 9.839955e+001 )
( 3.998676e+003, 9.863584e+001 )
( 3.999158e+003, 9.872655e+001 )
( 3.999640e+003, 9.836100e+001 )
( 4.000123e+003, 9.836080e+001 )};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
也许将 放在tikz
居中的零宽度框中就是您想要的。已编辑以放置\centering
在\par
-ended 组中,感谢 cfr 的建议。
\documentclass[letterpaper]{article}
\usepackage[margin=0.5 in,landscape]{geometry}
\pagestyle{empty}
%Graphics stuff here
\usepackage{pgfplots} %For graphing data
\pgfplotsset
{
compat = newest,
every tick/.append style = thin,
width= .95 \textwidth,
height= .95\textheight
}
\pgfkeys{/pgf/number format/set thousands separator = }
%Science stuff here
\usepackage[]{siunitx} %Adds si units and others by name- See the manual.
\sisetup{mode = text}
\begin{document}
{\centering\makebox[0pt]{
\begin{tikzpicture}
\begin{axis}
[
x dir = reverse,
xlabel = Frequency (\si{\per\centi\metre}),
title = Demo,
xticklabel style = {rotate=270},
yticklabels = {},
]
\addplot[color = black, mark = none]
coordinates {
( 3.983730e+003, 9.824165e+001 )
( 3.984213e+003, 9.854189e+001 )
( 3.984695e+003, 9.890483e+001 )
( 3.985177e+003, 9.878275e+001 )
( 3.985659e+003, 9.859460e+001 )
( 3.986141e+003, 9.835152e+001 )
( 3.986623e+003, 9.794798e+001 )
( 3.987105e+003, 9.803477e+001 )
( 3.987587e+003, 9.864641e+001 )
( 3.988070e+003, 9.895673e+001 )
( 3.988552e+003, 9.910266e+001 )
( 3.989034e+003, 9.866454e+001 )
( 3.989516e+003, 9.837458e+001 )
( 3.989998e+003, 9.857204e+001 )
( 3.990480e+003, 9.883611e+001 )
( 3.990962e+003, 9.891921e+001 )
( 3.991444e+003, 9.846350e+001 )
( 3.991927e+003, 9.804715e+001 )
( 3.992409e+003, 9.815513e+001 )
( 3.992891e+003, 9.844558e+001 )
( 3.993373e+003, 9.842175e+001 )
( 3.993855e+003, 9.843822e+001 )
( 3.994337e+003, 9.828293e+001 )
( 3.994819e+003, 9.791080e+001 )
( 3.995301e+003, 9.774442e+001 )
( 3.995783e+003, 9.783126e+001 )
( 3.996266e+003, 9.788599e+001 )
( 3.996748e+003, 9.826096e+001 )
( 3.997230e+003, 9.857933e+001 )
( 3.997712e+003, 9.843895e+001 )
( 3.998194e+003, 9.839955e+001 )
( 3.998676e+003, 9.863584e+001 )
( 3.999158e+003, 9.872655e+001 )
( 3.999640e+003, 9.836100e+001 )
( 4.000123e+003, 9.836080e+001 )};
\end{axis}
\end{tikzpicture}
}\par}
\end{document}
可以通过改变使其稍微大一些
\pgfplotsset
{
compat = newest,
every tick/.append style = thin,
width= .95 \textwidth,
height= .95\textheight
}
和
\centering\makebox[0pt]{
更改为以下内容:
\pgfplotsset
{
compat = newest,
every tick/.append style = thin,
width= .99\textwidth,
height=.99\textheight
}
和
\centering\makebox[0pt]{\raisebox{-.99\textheight}{\smash{%
并在 之前添加 2 个额外的右括号\end{document}
。