这是我第一次在这个网站上提问(尽管得到了很多答案)。我axis
在tabular
环境中对 pgfplots 的水平对齐存在问题。
我的目标,独立于以下具体示例,是获得一个 3x2 方轴矩阵,无论是否考虑 ylabels/yticklabels,该矩阵都精确填充文本宽度。
在以下 MWE 中,两个tikzpicture
s 由包含它们的相应文件加载。和红色框caption
的长度证明了对齐效果不佳。我想知道为什么。此外,我认为和也无法正常工作。从这个意义上讲,我想知道如何在考虑和不考虑标签和刻度标签的情况下紧密填充figure
trim axis left
trim axis right
\textwidth
\documentclass[a4paper,11pt]{article}
\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{bm}
\usepackage[super]{nth}
\usepackage{calc}
\usepackage{tikz}
%\usepackage{pbox}
\usetikzlibrary{decorations}
\usetikzlibrary{calc}
\usetikzlibrary{patterns}
\usetikzlibrary{shapes.arrows}
\usepackage{tikzscale}
\usepackage{pgfplots}
\usepackage{tabularx}
\pgfplotsset{compat=1.12}
\usepackage[font=small, format=hang, labelfont={sf,bf}, tableposition=top, figureposition=bottom]{caption}
\newcommand{\mat}{\mathbf}
\renewcommand{\vec}{\bm}
\begin{document}
\begin{figure}[!t]
\centering
\begin{tabular}{lr}
%\tikzsetnextfilename{pippo1}
\includegraphics{immagini/tikz/wpvsw/lele_w.tikz}
&
%\tikzsetnextfilename{pipo2}
\includegraphics{immagini/tikz/wpvsw/lele_distorsion.tikz}
\\
\end{tabular}%
\caption{\textsl{Left}: Plot of the real part of the modified wavenumber, $w'_\text{r}$, vs. wavenumber $w$ for first derivative approximations: (a) \nth{2} order explicit; (b) \nth{4} order explicit; (d) \nth{4} order tridiagonal (Padé); (e) \nth{6} order tridiagonal; (f) \nth{8} order tridiagonal; (h) \nth{10} order pentadiagonal.\\ \textsl{Right}: $w$-$w'$ plane stretched orthogonally to the bisector by a factor 500; each grey line results from the overlapping --- to eye precision --- of one horizontal and one vertical grid line on the \textsl{left}, due to the heavy distortion.}
\label{fig:pippo}
\end{figure}
\end{document}
文件 lele_w.tikz 应该包含
\begin{tikzpicture}[baseline,trim axis left]
\begin{axis}[grid=major,axis equal image=true,xmin=0,xmax=pi,xtick={0,.7854,...,3.1416},xticklabels={{},$\frac{\pi}{4}$,$\frac{\pi}{2}$,$\frac{3\pi}{4}$,{}},x label style={at={(ticklabel* cs:1)},anchor=north east},xlabel={$w$},ymin=0,ymax=pi,ytick={0,.7854,...,3.1416},yticklabels={{},$\frac{\pi}{4}$,$\frac{\pi}{2}$,$\frac{3\pi}{4}$,{}},y label style={at={(ticklabel* cs:1)},anchor=north east,rotate=-90},ylabel={$\Re(w')$}]
% exact
\addplot[mark=none] {x};
\end{axis}
\draw[red]
(current axis.below south west)
rectangle (current axis.above north east);
\draw[red]
(current axis.left of south west)
rectangle (current axis.right of north east);
\end{tikzpicture}
而 lele_distorsion.tikz 应该包含
\begin{tikzpicture}[baseline,trim axis right]
\begin{axis}[ylabel={$\Re(w')$},yticklabel pos=right,%at={(main axis.right of south east)},
%xshift=7cm,%anchor=south west,
axis equal image=true,xmin=0,xmax=pi,ymin=0,ymax=pi,ticks=none]
% exact
\addplot[mark=none] {x};
\end{axis}
\draw[red]
(current axis.below south west)
rectangle (current axis.above north east);
\draw[red]
(current axis.left of south west)
rectangle (current axis.right of north east);
\end{tikzpicture}
我按照@Harish Kumar 所说的做了,但对我来说并不完全有效。我向代码中添加了一个具有一组 3x2 轴环境的不同图形
\documentclass[a4paper,11pt]{article}
\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{bm}
\usepackage[super]{nth}
\usepackage{calc}
\usepackage{tikz}
%\usepackage{pbox}
\usetikzlibrary{decorations}
\usetikzlibrary{calc}
\usetikzlibrary{patterns}
\usetikzlibrary{shapes.arrows}
\usepackage{tikzscale}
\usepackage{pgfplots}
\usepackage{tabularx}
\pgfplotsset{compat=1.12}
\usepackage[font=small, format=hang, labelfont={sf,bf}, tableposition=top, figureposition=bottom]{caption}
\begin{document}
\begin{figure}
\centering
\begin{tabular}{lr}
%\tikzsetnextfilename{re1}
\includegraphics{immagini/tikz/wpvsw/re1.tikz}
&
%\tikzsetnextfilename{im1}
\includegraphics{immagini/tikz/wpvsw/im1.tikz}
\\
%\tikzsetnextfilename{re2}
\includegraphics{immagini/tikz/wpvsw/re2.tikz}
&
%\tikzsetnextfilename{im2}
\includegraphics{immagini/tikz/wpvsw/im2.tikz}
\\
%\tikzsetnextfilename{re3}
\includegraphics{immagini/tikz/wpvsw/re3.tikz}
&
%\tikzsetnextfilename{im3}
\includegraphics{immagini/tikz/wpvsw/im3.tikz}
\\
\end{tabular}%
\caption{\textsl{Left}: Plot of the real part of the modified wavenumber, $w'_\text{r}$, vs. wavenumber $w$ for first derivative approximations: (a) \nth{2} order explicit; (b) \nth{4} order explicit.}
\end{figure}
\end{document}
左上角的文件是:
\begin{tikzpicture}[baseline]
\tikzset{every mark/.append style={scale=.75,fill=white}}
\pgfplotsset{every tick label/.append style={
/pgf/number format/precision=1,
/pgf/number format/fixed,
/pgf/number format/fixed zerofill
}}
\pgfplotsset{every axis plot/.append style={line width=.25pt}}
\begin{axis}[width=.5\textwidth,height=.5\textwidth,
ylabel={$\text{Re}\left(k'\right)$},
xmin=0,xmax=pi,ymin=0,ymax=pi,axis equal image=true,
xtick={.5,1,...,3},
xticklabels={},
ytick={.5,1,...,3},
grid=major,trim axis left]
\addplot[mark=none] {x};
\end{axis}
\draw[red]
(current axis.below south west)
rectangle (current axis.above north east);
\draw[red]
(current axis.left of south west)
rectangle (current axis.right of north east);
\end{tikzpicture}
右上角的文件是:
\begin{tikzpicture}[baseline]
\tikzset{every mark/.append style={scale=.75,fill=white}}
\pgfplotsset{every tick label/.append style={
/pgf/number format/precision=1,
/pgf/number format/fixed,
/pgf/number format/fixed zerofill
}}
\pgfplotsset{every axis plot/.append style={line width=.25pt}}
\begin{axis}[width=.5\textwidth,height=.5\textwidth,
ylabel={$\text{Im}\left(k'\right)$},
xmin=0,xmax=pi,ymin=-2e-2,ymax=1.6e-1,
xtick={.5,1,...,3},
xticklabels={},
ytick={0,2e-2,4e-2,6e-2,8e-2,10e-2,12e-2,14e-2,16e-2},
scaled y ticks={base 10:2},tick scale binop=\times,
yticklabel pos=right,
grid=major,trim axis right]
\end{axis}
\draw[red]
(current axis.below south west)
rectangle (current axis.above north east);
\draw[red]
(current axis.left of south west)
rectangle (current axis.right of north east);
\end{tikzpicture}
下面 2 个 (1x2) 图有标签和刻度标签
axis
' 选项用于width=.5\textwidth,height=.5\textwidth
使绘图全部为正方形,即使右侧的绘图在 x 和 y 方向上具有不同的比例,如下图所示
答案1
对于给定的 TikZ 图片,我无法重现您的问题,但检查您的图表表明,您喜欢第一行中的图像与第二行中的图像在xlabel
和中有所不同xticklabels
。后者显然突出了图表的右侧和顶部边框,使图像略大。因此,我建议您xmax
从xmax=pi
到稍微增加一点,例如xmax=1.05*pi
,ymax
尺寸与xmax
(图中左侧图像)相同。请参阅下面的代码。这样我得到:
我生成了上面的图,我将你的 TikZ 图像直接放在图中。包括它们的 pdf 文件不应该改变它们的外观。
\documentclass[a4paper,11pt]{article}
\usepackage{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{bm}
\usepackage[super]{nth}
\usepackage{calc}
\usepackage{tikz}
%\usepackage{pbox}
\usetikzlibrary{calc,decorations,patterns,shapes.arrows}
\usepackage{tikzscale}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12,
width=0.5\textwidth-2*\tabcolsep, % <--- new,
height=0.5\textwidth-2*\tabcolsep,% common for all tikz pictures
every axis plot/.append style={line width=1pt}
}
\usepackage[font=small,
format=hang,
labelfont={sf,bf},
tableposition=top,
figureposition=bottom]{caption}
\newcommand{\mat}{\mathbf}
\renewcommand{\vec}{\bm}
\begin{document}
\begin{figure}[t]
\rule{\textwidth}{1pt}\\[1ex]% only for show, that the images fit to width of text
\centering
\begin{tabular}{@{}l r@{}}
%\tikzsetnextfilename{pippo1}
%\includegraphics[width=0.48\textwidth]{example-image-a}
\begin{tikzpicture}[baseline]
\begin{axis}[
/pgf/number format/precision=1,
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
ylabel={$\text{Re}\left(k'\right)$},
xmin=0,xmax=pi,%<------- corrected
ymin=0,ymax=pi,%<------- corrected
axis equal image=true,
xtick={.5,1,...,3},
xticklabels={},
ytick={.5,1,...,3},
grid=major,trim axis left]
\addplot[mark=none] {x};
\end{axis}
\end{tikzpicture}
&
%\tikzsetnextfilename{pipo2}
% \includegraphics[width=0.48\textwidth]{example-image-b}
\begin{tikzpicture}[baseline]
\begin{axis}[
ylabel={$\text{Im}\left(k'\right)$},
xmin=0,xmax=pi,ymin=-2e-2,ymax=1.6e-1,
xtick={.5,1,...,3},
xticklabels={},
ytick={0,2e-2,4e-2,6e-2,8e-2,10e-2,12e-2,14e-2,16e-2},
scaled y ticks={base 10:2},tick scale binop=\times,
yticklabel pos=right,
grid=major,trim axis right]
\end{axis}
\end{tikzpicture}
\\
%------------------------------------------
%\tikzsetnextfilename{pippo1}
%\includegraphics[width=0.48\textwidth]{example-image-a}
\begin{tikzpicture}[baseline]
\begin{axis}[
ylabel={$\text{Re}\left(k'\right)$},
xmin=0,xmax=pi,
ymin=0,ymax=pi,
axis equal image=true,
xtick={.5,1,...,3},
xticklabels={0.5,1.0,1.5,2.0,2.5,3.0},
ytick={.5,1,...,3},
grid=major,trim axis left,
xlabel={$k$}]
\addplot[mark=none] {x};
\end{axis}
\end{tikzpicture}
&
%\tikzsetnextfilename{pipo2}
% \includegraphics[width=0.48\textwidth]{example-image-b}
\begin{tikzpicture}[baseline]
\begin{axis}[
ylabel={$\text{Im}\left(k'\right)$},
xmin=0,xmax=pi,ymin=-2e-2,ymax=1.6e-1,
xtick={.5,1,...,3},
xticklabels={0.5,1.0,1.5,2.0,2.5,3.0},
ytick={0,2e-2,4e-2,6e-2,8e-2,10e-2,12e-2,14e-2,16e-2},
scaled y ticks={base 10:2},tick scale binop=\times,
yticklabel pos=right,
grid=major,trim axis right,
xlabel={$k$}]
]
\end{axis}
\end{tikzpicture}
\end{tabular}%
\caption{%
\textsl{Left}: Plot of the real part of the modified wavenumber, $w'_\text{r}$, vs. wavenumber $w$ for first derivative approximations: (a) \nth{2} order explicit; (b) \nth{4} order explicit; (d) \nth{4} order tridiagonal (Padé); (e) \nth{6} order tridiagonal; (f) \nth{8} order tridiagonal; (h) \nth{10} order pentadiagonal.\\
%
\textsl{Right}: $w$-$w'$ plane stretched orthogonally to the bisector by a factor 500; each grey line results from the overlapping --- to eye precision --- of one horizontal and one vertical grid line on the \textsl{left}, due to the heavy distortion.}
\label{fig:pippo}
\end{figure}
\end{document}
编辑:
我更改了pdfplotsset
,它现在包含所有 pgf 图的所有公共数据。在那里我将图像的宽度定义为0.5\\textwidth-2*\tabcolsep
,以适应表格单元格中的空间。在那里我@{}
消除了表格中的左右空间。
现在我也省略了图像周围的红线,并将 x 轴的最大值返回给pi
。我希望